React Native:任务“:app:checkDebugDuplicateClasses”执行失败

spa*_*tak 7 react-native

我在运行时出现下一个错误npx react-native run-android。它不知从何而来——没有做出任何改变。

Execution failed for task ':app:checkDebugDuplicateClasses'.
A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable

Duplicate class kotlin.collections.jdk8.CollectionsJDK8Kt found in modules jetified-kotlin-stdlib-1.8.0 (org.jetbrains.kotlin:kotlin-stdlib:1.8.0) and jetified-kotlin-stdlib-jdk8-1.7.20 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.20)

Duplicate class kotlin.internal.jdk7.JDK7PlatformImplementations found in modules jetified-kotlin-stdlib-1.8.0 (org.jetbrains.kotlin:kotlin-stdlib:1.8.0) and jetified-kotlin-stdlib-jdk7-1.7.20 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.20)
     
Duplicate class kotlin.internal.jdk7.JDK7PlatformImplementations$ReflectSdkVersion found in modules jetified-kotlin-stdlib-1.8.0 (org.jetbrains.kotlin:kotlin-stdlib:1.8.0) and jetified-kotlin-stdlib-jdk7-1.7.20 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.20)
     
Duplicate class kotlin.internal.jdk8.JDK8PlatformImplementations found in modules jetified-kotlin-stdlib-1.8.0 (org.jetbrains.kotlin:kotlin-stdlib:1.8.0) and jetified-kotlin-stdlib-jdk8-1.7.20 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.20)
     
Duplicate class kotlin.internal.jdk8.JDK8PlatformImplementations$ReflectSdkVersion found in modules jetified-kotlin-stdlib-1.8.0 (org.jetbrains.kotlin:kotlin-stdlib:1.8.0) and jetified-kotlin-stdlib-jdk8-1.7.20 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.20)
Run Code Online (Sandbox Code Playgroud)

我尝试过的:

  1. 再次按照官方 React Native 文档页面上的安装步骤进行操作:https ://reactnative.dev/docs/environment-setup

     brew install node
     brew install watchman
     brew tap homebrew/cask-versions
     brew install --cask zulu11
    
    Run Code Online (Sandbox Code Playgroud)
  2. 卸载并安装Android Studio

  3. kotlinVersion = "1.8.0"android/build.gradle中设置:

     buildToolsVersion = "32.0.0"
     minSdkVersion = 21
     compileSdkVersion = 33
     targetSdkVersion = 33
     // here
     kotlinVersion = "1.8.0"
    
    Run Code Online (Sandbox Code Playgroud)

看起来如果我摆脱"react-native-inappbrowser-reborn": "^3.7.0"库,错误就会消失,并且应用程序会成功启动。但如果react-native-inappbrowser-reborn我的项目需要怎么办?

先谢谢各位小伙伴了!

use*_*583 16

这是由 Kotlin 插件更新引起的。您可以使用下面的配置轻松修复它:

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    //noinspection GradleDynamicVersion
    implementation "com.facebook.react:react-native:+"  // From node_modules
    implementation 'com.android.support:multidex:2.0.1'
    implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"

    // Add this line here
    implementation platform('org.jetbrains.kotlin:kotlin-bom:1.8.0')

    //...omit some code
}
Run Code Online (Sandbox Code Playgroud)

你可以参考这个:Kotlin文档

  • // android/app/build.gradle (2认同)