react-native-gradle-plugin kotlin.ExperimentalStdlibApi 声明是实验性的,必须标记其用法

Ant*_*ony 6 android gradle kotlin react-native kotlin-experimental

我一直在尝试构建 React Native 应用程序,我一直在到处搜索,但无法解决这个问题。任何帮助或建议都将非常感激。

我的 Android 版本出现此错误:

/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)

在react-native-gradle-plugin中,我找到了文件BundleHermesCTask.kt。在此文件中,它向我显示此函数的错误,我可以将此行放在函数 @OptIn(ExperimentalStdlibApi::class) 之上,程序将构建并工作,但更改节点模块不是解决方案,因为它将被覆盖。

 internal fun getBundleCommand(bundleFile: File, sourceMapFile: File): List<Any> =
  windowsAwareCommandLine(
      buildList {
        addAll(nodeExecutableAndArgs.get())
        add(cliFile.get().asFile.absolutePath)
        add(bundleCommand.get())
        add("--platform")
        add("android")
        add("--dev")
        add(devEnabled.get().toString())
        add("--reset-cache")
        add("--entry-file")
        add(entryFile.get().asFile.toString())
        add("--bundle-output")
        add(bundleFile.toString())
        add("--assets-dest")
        add(resourcesDir.get().asFile.toString())
        add("--sourcemap-output")
        add(sourceMapFile.toString())
        if (bundleConfig.isPresent) {
          add("--config")
          add(bundleConfig.get().asFile.absolutePath)
        }
        add("--minify")
        add(minifyEnabled.get().toString())
        addAll(extraPackagerArgs.get())
        add("--verbose")
      })
Run Code Online (Sandbox Code Playgroud)

我在网上搜索并尝试了所有方法,从检查我的java版本到检查所有依赖项是否加载相同版本以及更新反应本机和依赖项。我唯一能做的就是更改文件 BundleHermesCTask.kt,但我无法执行此操作,因为构建过程将移动应用程序并执行 npm 安装所有依赖项,并且更改会丢失。

我已经检查了 github 页面,也一直在尝试了解 kotlin 有关 kotlin 的更多信息,并阅读
https://kotlinlang.org/docs/opt-in-requirements上的文档

ste*_*ola 1

您使用的 Gradle 版本是什么?我通过升级到 Gradle 7.5.1 解决了这个问题

  • 这对我不起作用。它只在调试版本中工作,一旦我去做发布版本,它就不起作用了。(发布版本中的应用程序崩溃。致命异常:create_react_context)我必须使用 Gradle 到 7.3.3,然后降级react-native-gradle-plugin@0.70.3 (2认同)