admin管理员组

文章数量:1626405

一,现象

执行yarn安装依赖后,运行react-native项目,就报错:

react-native-community/netinfo:compileDebugJavaWithJavac FAILED

具体的报错代码是这块:

  // Get the current receive link speed in Mbps
   try {
     if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) {
      int rxLinkSpeed =
      wifiInfo.getRxLinkSpeedMbps();
      details.putInt("rxLinkSpeed", rxLinkSpeed);
       }
     } catch (Exception e) {
     // Ignore errors
    }

请教了安卓大佬,说是这个安卓版本不对,需要安卓10以上才有Q这个属性和getRxLinkSpeedMbps这个方法。

二,相关资料

github上的解决方案:https://github/react-native-netinfo/react-native-netinfo/issues/540

You must use compileSdkVersion and minSdkVersion 29 for this to work:

https://developer.android/reference/android/telephony/TelephonyManager#NETWORK_TYPE_NR

That's below the current play store minimum requirement (of 30) so this should not be a burden? As in: you literally cannot publish an app on the app store without having targetSdkVersion 29 so your app should be there already. Can you confirm that you are not on those versions, and that it works if you bump to those versions?

This was not an intentional breaking change though - it was an inadvertent one. We can certainly require compileSdkVersion 29 (or 31) easily, but requiring targetSdkVersion 30 is perhaps more difficult (for non play store apps?).

I didn't realize this would be breaking and it should be called out in the release notes - sorry for the trouble and let me know if it resolves with the APIs set to 29+

和安卓大佬说的差不多,需要指定新的安卓版本。

三,具体修改

打开andriod/build.gradle文件,找到这几个版本控制的配置:

buildscript {
    ext {
        buildToolsVersion = "28.0.3"
        minSdkVersion = 16
        compileSdkVersion = 28
        targetSdkVersion = 28
        supportLibVersion = "28.0.0"
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:3.5.2")

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

改成

 ext {
        buildToolsVersion = "30.0.3"
        minSdkVersion = 16
        compileSdkVersion = 30
        targetSdkVersion = 30
        supportLibVersion = "30.0.0"
    }

再重新运行项目,就可以了。

本文标签: CommunityNativeReactfailedcompileDebugJavaWithJavac