此声明是实验性的,其用法必须用“@kotlin.ExperimentalStdlibApi”或“@OptIn(kotlin.ExperimentalStdlibApi::class)”标记

Hug*_*ugo 6 android android-gradle-plugin react-native

升级到 React Native 0.70.6 后,我在 android 上不断遇到这个问题,好几天都没有找到解决方案。

> Task :react-native-gradle-plugin:compileKotlin FAILED
e: /Users/hugohouyez/code/hugoh1995/Superprof/node_modules/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/BundleHermesCTask.kt: (137, 11): This declaration is experimental and its usage must be marked with '@kotlin.ExperimentalStdlibApi' or '@OptIn(kotlin.ExperimentalStdlibApi::class)'
Run Code Online (Sandbox Code Playgroud)

我已经在我的 package.json 中安装了 "react-native-gradle-plugin": "^0.71.10",尽管文档中没有提到它,因为如果没有它,它会说找不到依赖项。

构建.gradle

...
    dependencies {
        classpath("com.android.tools.build:gradle:7.3.0")
        classpath("com.facebook.react:react-native-gradle-plugin")
        classpath("de.undercouch:gradle-download-task:5.0.1")
        classpath("com.google.gms:google-services:4.3.10")
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
Run Code Online (Sandbox Code Playgroud)

gradle-wrapper.properties

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
Run Code Online (Sandbox Code Playgroud)

小智 7

更改 /android/gradle/wrapper/gradle-wrapper.properties 中的 distributionUrl 解决了我的问题。

distributionUrl=https://services.gradle.org/distributions/gradle-7.5.1-all.zip
Run Code Online (Sandbox Code Playgroud)