react-native-community/netinfo:compileDebugJavaWithJavac FAILED

一,现象

执行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.com/react-native-netinfo/react-native-netinfo/issues/540

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

https://developer.android.com/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"
    }

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值