某个Android版本某一天突然build失败了,很突然,相当突然,又没过改代码(这回是真的!!!)。
有了之前查问题的经验,先去查issue list, 果然:https://github.com/facebook/react-native/issues/25293,里面提到了解决办法,迁移到AndroidX,但是咱还没准备好。继续,终于有一个without:根本原因是gms的某个升级导致的,所以咱可以把这个升级踢出代码。简书上有个同事的分析:https://www.jianshu.com/p/3730043c1fb8
OK,react-native run android 没问题了。可是,可是,可是高兴的太早了release版本还是出现报错了。
尝试了一下升级"react-native-device-info": "^2.1.2",
npm install react-native-device-info@2.1.2
这个时候编译出现了找不到符号。因为引入了28的东东,咋办:
暴力修改:node_modules/react-native-device-info/android/src/main/java/com/learnium/RNDeviceInfo/RNDeviceModule.java
390 @ReactMethod
391 public void isLocationEnabled(Promise p) {
392 boolean locationEnabled = false;
393
394 /*if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
395 LocationManager mLocationManager = (LocationManager) reactContext.getApplicationContext().getSystemService(Context.LOCATION_SERVICE);
396 locationEnabled = mLocationManager.isLocationEnabled();
397 } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {*/
398 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
399 int locationMode = Settings.Secure.getInt(reactContext.getContentResolver(), Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_OFF);
400 locationEnabled = locationMode != Settings.Secure.LOCATION_MODE_OFF;
401 } else {
402 String locationProviders = Settings.Secure.getString(reactContext.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
403 locationEnabled = !TextUtils.isEmpty(locationProviders);
404 }
405
406 p.resolve(locationEnabled);
407 }
在android/build.gradle添加:
subprojects {
afterEvaluate {
project ->
if (project.hasProperty("android")) {
android {
compileSdkVersion = 27
buildToolsVersion = "27.0.3"
}
}
}
}
PASS!!!