React原生:任务":app:checkDebugDuplicateClasses"的执行失败

r8uurelv  于 2023-01-31  发布在  React
关注(0)|答案(4)|浏览(256)

我在运行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)

我尝试了:
1.* * 再次按照官方react原生文档页面上的安装步骤操作:https://reactnative.dev/docs/environment-setup**

brew install node
 brew install watchman
 brew tap homebrew/cask-versions
 brew install --cask zulu11

1.* * 卸载并安装Android Studio**
1.在android/build. gradle中设置kotlinVersion = "1.8.0"

buildToolsVersion = "32.0.0"
 minSdkVersion = 21
 compileSdkVersion = 33
 targetSdkVersion = 33
 // here
 kotlinVersion = "1.8.0"

看起来如果我去掉"react-native-inappbrowser-reborn": "^3.7.0"库,错误就消失了,应用程序也成功启动了。但是如果我的项目中需要react-native-inappbrowser-reborn呢?
提前感谢各位朋友!

db2dz4w8

db2dz4w81#

这是由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
}

您可以参考以下内容:Kotlin文件

sycxhyv7

sycxhyv72#

将其添加到android/app/build.gradle

configurations.all {
resolutionStrategy {
    eachDependency {
        if ((requested.group == "org.jetbrains.kotlin") && (requested.name.startsWith("kotlin-stdlib"))) {
            useVersion("1.6.10")
        }
    }
}

}

pcrecxhr

pcrecxhr3#

对我来说,是react-native-iapreact-native-onesignal包的组合导致了这个问题。
升级react-native-onesignal不起作用,所以我尽可能升级react-native-iap而不破坏更改,对我来说,这就是v7.5.6
在将iap升级到7.5.6之后,我还必须将以下代码添加到../android/app/build.gradle文件中以便编译:

defaultConfig {
    ...
    missingDimensionStrategy 'store', 'play'
}

编辑:我认为发生的事情是你的一个包有一个松散的依赖关系,这导致了一个意外的更新。所以每个情况可能是不同的。

kyxcudwk

kyxcudwk4#

android/app/build.gradle文件中,将kotlin-stdlib设置为使用相同的版本
例如:

configurations.all {
    resolutionStrategy {
        eachDependency {
            if ((requested.group == "org.jetbrains.kotlin") && (requested.name.startsWith("kotlin-stdlib"))) {
                useVersion("1.7.20")
            }
        }
    }
}

相关问题