我正在尝试在我的 RN 项目中使用 React Navigation,但是当我安装react-native-screens(这是它工作所需的包)时,我无法再次构建该项目。
我得到的错误如下:
Task :react-native-screens:compileDebugKotlin FAILED
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
我尝试了一些我看到其他人做的事情,但到目前为止没有任何效果。
你能帮我吗?谢谢
我在 android/build.gradle 中将 kotlin 版本更改为 kotlinVersion = "1.5.31"
如果您在使用
@react-navigation/[email protected]
将 react-native @0.69.0
库添加到项目后遇到此问题,只需升级 [email protected]
此特定版本
如果您在 2022 年 11 月 4 日之后发现此问题,它可能与问题 35210 有关:
这是他们发布 React Native 0.71.0-rc0 版本后出现的问题。因此,几乎所有使用 0.66.x 之前版本的 React Native 用户都会受到影响。使用 0.67 到 0.70 版本的 React Native 用户可能会受到影响,具体取决于他们使用的 npm 包。要解决此问题,您可以按照本期中的说明进行操作:https://github.com/facebook/react-native/issues/35210
请将react-native更新到此票证中提到的相应补丁版本 https://github.com/facebook/react-native/issues/35210
我通过将这段代码放入 android/buld.gradle 文件中解决了这个问题
def REACT_NATIVE_VERSION = new File(['node', '--print',"JSON.parse(require('fs').readFileSync(require.resolve('react-native/package.json'), 'utf-8')).version"].execute(null, rootDir).text.trim())
// 我已将其放置在所有项目上方{
allprojects {
configurations.all {
resolutionStrategy {
// Remove this override in 0.66, as a proper fix is included in react-native itself.
force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION
}
}
...
}
如果您在 2022 年 11 月遇到此问题,也许此解决方案可以帮助您解决它。
在
android/build.gradle
:
allprojects {
configurations.all {
resolutionStrategy {
force "com.facebook.react:react-native:0.67.+"
force "com.facebook.react:hermes-engine:0.67.+"
}
}
...
更改为您项目中使用的 React Native 版本。
(示例:
force "com.facebook.react:react-native:0.68.+"
我将节点版本从 19 减少到 16.16.0。 转到下面的链接。 https://nodejs.org/en/blog/release/v16.16.0
因为我使用的是 macOS-64 位。我下载了:- macOS 64 位安装程序:https://nodejs.org/dist/v16.16.0/node-v16.16.0.pkg