我使用 RxPermission 库轻松处理运行时权限,
在我的应用程序中,我询问位置:
rxPermissions
.request(Manifest.permission.ACCESS_FINE_LOCATION)
.subscribe(granted -> {
if (granted) {
boolean gpsEnabled, networkEnabled;
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if (locationManager != null) {
gpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
networkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (gpsEnabled && locationListenerGPS != null) {
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0L, 0f, locationListenerGPS);
}
if (networkEnabled && locationListenerNetwork != null) {
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0L, 0f, locationListenerNetwork);
}
}
} else {
Log.d("Access not granted", "no location");
}
});
当我打开 debug-apk 时,它运行良好,但是当我尝试打开 release apk 时,它会因以下错误而崩溃:
在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 处运行(ZygoteInit.java:1230) 原因:java.lang.NoSuchFieldException:Ld/c/d/b/r 类中没有字段 producerIndex ; ('dcdbr' 的声明出现在 /data/app/com.magis.icbc-1/base.apk)的 java.lang.Class.getDeclaredField(Native Method) at dcdbsa(UnsafeAccess.java:112) Ld/c/d/b/r 类中没有字段 producerIndex;('dcdbr' 的声明出现在 /data/app/com.magis.icbc-1/base.apk)的 java.lang.Class.getDeclaredField(Native Method) at dcdbsa(UnsafeAccess.java:112) Ld/c/d/b/r 类中没有字段 producerIndex;('dcdbr' 的声明出现在 /data/app/com.magis.icbc-1/base.apk)的 java.lang.Class.getDeclaredField(Native Method) at dcdbsa(UnsafeAccess.java:112)
正好在这条线上 .subscribe(granted -> {