1、Caused by: java.lang.UnsatisfiedLinkError: No implementation found for int com.baidu.platform.comjni.tools.JNITools.initClass
解决方法:
sourceSets{
main{
jniLibs.srcDirs ‘libs’
}
}
2、Caused by: java.lang.IllegalStateException: you have not supplyed the global app context info from SDKInitializer.initialize(Context) function.
解决方法:
把自定义的MainApplication在Androidmenifest.xml中声明
3、百度地图errorcode: -10 uid: -1 appid -1 msg: Current network is not available.
解决方法:
Androidmenifest.xml中增加访问网络的权限
4、权限问题兼容
解决办法:
Androidmenifest.xml中增加compile ‘com.android.support:support-core-utils:25.3.1’
代码如下:
public void checkPermission(){
if ((ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED
| (ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION)) != PackageManager.PERMISSION_GRANTED
| (ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION)) != PackageManager.PERMISSION_GRANTED
| (ContextCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE)) != PackageManager.PERMISSION_GRANTED)){
ActivityCompat.requestPermissions(MainActivity.this,
new String[] {android.Manifest.permission.ACCESS_COARSE_LOCATION,
android.Manifest.permission.ACCESS_FINE_LOCATION,
android.Manifest.permission.ACCESS_FINE_LOCATION,
android.Manifest.permission.WRITE_EXTERNAL_STORAGE
},
REQUEST_CODE_ASK_PERMISSIONS);
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
Log.i("TeamGroups", "requestCode = " + requestCode);
Log.i("TeamGroups", permissions.toString());
doNext(requestCode, grantResults);
}
private void doNext(int requestCode, int[] grantResults) {
System.out.println("request code = " + requestCode);
if (requestCode == REQUEST_CODE_ASK_PERMISSIONS) {
for (int grantResult : grantResults) {
Log.i("TeamGroups", "" + grantResult);
}
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Toast.makeText(this, "已授权", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "未授权", Toast.LENGTH_SHORT).show();
}
}
}
onCreate()里调用:checkPermission()
5、java.lang.IllegalArgumentException: Could not locate ResponseBody converter
解决方法:
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Constants.API_BASE_URL)
.addConverterFactory(GsonConverterFactory.create())//这句
.build();
compile ‘com.squareup.retrofit2:converter-gson:2.0.2’
6、@Body parameters cannot be used with form or multi-part encoding
解决方法:
去掉@FormUrlEncoded
7、使用retrofit进行post传递
LoginActvity:
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(ContentURL.HOME_HOST)
.addConverterFactory(GsonConverterFactory.create())
.build();
ApiService service = retrofit.create(ApiService.class);
Call<LoginResponseBean> call = service.login(login);
call.enqueue(new Callback<LoginResponseBean>() {
@Override
public void onResponse(Call<LoginResponseBean> call, Response<LoginResponseBean> response) {
if(response.body().getToken() == null){
Toast.makeText(LoginActivity.this,R.string.any_error,Toast.LENGTH_SHORT).show();
}else {
Log.i("TeamGroups", response.body().getToken());
Log.i("TeamGroups", response.body().getResult());
PreferenceUtils.setPrefString(LoginActivity.this, "Token", response.body().getToken());
Intent intent = new Intent(LoginActivity.this,MainActivity.class);
startActivity(intent);
}
}
@Override
public void onFailure(Call<LoginResponseBean> call, Throwable t) {
t.printStackTrace();
}
});
ApiService:
public interface ApiService {
@POST(ContentURL.LOGIN_URL)
Call<LoginResponseBean> login(@Body LoginBean login);
}