重复类 com.facebook.jni - 无法构建应用程序

问题描述 投票:0回答:2

当我将

compileSdkVersion
从 29 更改为 31 后,因为我不得不这样做,它不会构建我的应用程序,现在我收到了此错误。

`失败:构建失败并出现异常。

  • 出了什么问题: 任务“:app:checkDebugDuplicateClasses”执行失败。

执行 com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable 时发生故障 在模块 jetified-fbjni-0.3.0-runtime (com.facebook.fbjni:fbjni:0.3.0) 和 jetified-fbjni-java-only-0.2 (com.facebook.fbjni) 中发现重复的类 com.facebook.jni.CppException :fbjni-java-only:0.2.2) 在模块 jetified-fbjni-0.3.0-runtime (com.facebook.fbjni:fbjni:0.3.0) 和 jetified-fbjni-java-only-0.2 (com.facebook.fbjni) 中发现重复的类 com.facebook.jni.CppSystemErrorException :fbjni-java-only:0.2.2) 在模块 jetified-fbjni-0.3.0-runtime (com.facebook.fbjni:fbjni:0.3.0) 和 jetified-fbjni-java-only-0.2 (com.facebook.fbjni) 中发现重复的类 com.facebook.jni.DestructorThread :fbjni-java-only:0.2.2) 在模块 jetified-fbjni-0.3.0-runtime (com.facebook.fbjni:fbjni:0.3.0) 和 jetified-fbjni-java-only-0.2 (com.facebook. fbjni:fbjni-java-only:0.2.2) 在模块 jetified-fbjni-0.3.0-runtime (com.facebook.fbjni:fbjni:0.3.0) 和 jetified-fbjni-java-only-0.2 (com.facebook) 中发现重复的类 com.facebook.jni.DestructorThread$Destructor .fbjni:fbjni-java-only:0.2.2) 在模块 jetified-fbjni-0.3.0-runtime (com.facebook.fbjni:fbjni:0.3.0) 和 jetified-fbjni-java-only-0.2 (com.facebook) 中发现重复的类 com.facebook.jni.DestructorThread$DestructorList .fbjni:fbjni-java-only:0.2.2) 在模块 jetified-fbjni-0.3.0-runtime (com.facebook.fbjni:fbjni:0.3.0) 和 jetified-fbjni-java-only-0.2 (com.facebook) 中发现重复的类 com.facebook.jni.DestructorThread$DestructorStack .fbjni:fbjni-java-only:0.2.2) 在模块 jetified-fbjni-0.3.0-runtime (com.facebook.fbjni:fbjni:0.3.0) 和 jetified-fbjni-java-only-0.2 (com.facebook) 中发现重复的类 com.facebook.jni.DestructorThread$Terminus .fbjni:fbjni-java-only:0.2.2) 在模块 jetified-fbjni-0.3.0-runtime (com.facebook.fbjni:fbjni:0.3.0) 和 jetified-fbjni-java-only-0.2 (com.facebook.fbjni) 中发现重复的类 com.facebook.jni.HybridClassBase :fbjni-java-only:0.2.2) 在模块 jetified-fbjni-0.3.0-runtime (com.facebook.fbjni:fbjni:0.3.0) 和 jetified-fbjni-java-only-0.2 (com.facebook.fbjni) 中发现重复的类 com.facebook.jni.HybridData :fbjni-java-only:0.2.2) 在模块 jetified-fbjni-0.3.0-runtime (com.facebook.fbjni:fbjni:0.3.0) 和 jetified-fbjni-java-only-0.2 (com.facebook) 中发现重复的类 com.facebook.jni.HybridData$Destructor .fbjni:fbjni-java-only:0.2.2) 在模块 jetified-fbjni-0.3.0-runtime (com.facebook.fbjni:fbjni:0.3.0) 和 jetified-fbjni-java-only-0.2 (com.facebook.fbjni) 中发现重复的类 com.facebook.jni.IteratorHelper :fbjni-java-only:0.2.2) 在模块 jetified-fbjni-0.3.0-runtime (com.facebook.fbjni:fbjni:0.3.0) 和 jetified-fbjni-java-only-0.2 (com.facebook.fbjni) 中发现重复的类 com.facebook.jni.MapIteratorHelper :fbjni-java-only:0.2.2) 在模块 jetified-fbjni-0.3.0-runtime (com.facebook.fbjni:fbjni:0.3.0) 和 jetified-fbjni-java-only-0.2 (com.facebook.fbjni) 中发现重复的类 com.facebook.jni.NativeRunnable :fbjni-java-only:0.2.2) 在模块 jetified-fbjni-0.3.0-runtime (com.facebook.fbjni:fbjni:0.3.0) 和 jetified-fbjni-java-only-0.2 (com.facebook.fbjni) 中发现重复的类 com.facebook.jni.ThreadScopeSupport :fbjni-java-only:0.2.2) 在模块 jetified-fbjni-0.3.0-runtime (com.facebook.fbjni:fbjni:0.3.0) 和 jetified-fbjni-java-only-0.2 (com.facebook.fbjni) 中发现重复的类 com.facebook.jni.UnknownCppException :fbjni-java-only:0.2.2) 在模块 jetified-fbjni-0.3.0-runtime (com.facebook.fbjni:fbjni:0.3.0) 和 jetified-fbjni-java-only-0.2 (com.facebook) 中发现重复的类 com.facebook.jni.annotations.DoNotStrip .fbjni:fbjni-java-only:0.2.2)```

我发现这个错误 -> https://github.com/facebook/react-native/issues/34328 与我的类似,但我不知道如何修复它。

这是我的反应本机信息

System:
    OS: macOS 12.3.1
    CPU: (8) arm64 Apple M1
    Memory: 173.81 MB / 8.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 18.0.0 - /opt/homebrew/bin/node
    Yarn: Not Found
    npm: 8.6.0 - /opt/homebrew/bin/npm
    Watchman: 2022.03.21.00 - /opt/homebrew/bin/watchman
  Managers:
    CocoaPods: 1.11.3 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 21.4, iOS 15.4, macOS 12.3, tvOS 15.4, watchOS 8.5
    Android SDK: Not Found
  IDEs:
    Android Studio: 2021.1 AI-211.7628.21.2111.8309675
    Xcode: 13.3.1/13E500a - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.15 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 17.0.1 => 17.0.1
    react-native: 0.64.2 => 0.64.2
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

我已经尝试过我发布的链接的结果,但无法使其工作。

这是我的 android/build.gradle 文件:

buildscript {
    ext {
        buildToolsVersion = "29.0.3"
        minSdkVersion = 24
        compileSdkVersion = 31
        targetSdkVersion = 31
        kotlin_version = '1.5.0'
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath('com.android.tools.build:gradle:4.2.1')
        classpath 'com.google.gms:google-services:4.3.8'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.7.1'
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenLocal()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url("$rootDir/../node_modules/react-native/android")
        }
        maven {
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
        }

        google()
        jcenter()
        maven { url 'https://www.jitpack.io' }


    }
}

这里是来自 android/app/build.gradle 的依赖项

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
//noinspection GradleDynamicVersion

implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
implementation 'com.google.android.gms:play-services-analytics:17.0.0'
implementation platform('com.google.firebase:firebase-bom:28.2.0')
implementation 'com.google.firebase:firebase-analytics'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.8.5'
implementation 'com.fasterxml.jackson.core:jackson-core:2.8.5'
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.8.5'

api 'com.facebook.fbjni:fbjni-java-only:0.2.2'
implementation 'org.pytorch:pytorch_android:1.9.0'
implementation 'com.facebook.react:react-native:+'

// For displaying GIFs
implementation 'com.facebook.fresco:fresco:2.0.0'
implementation 'com.facebook.fresco:animated-gif:2.0.0'

debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
  exclude group:'com.facebook.fbjni'
}

debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
    exclude group:'com.facebook.flipper'
    exclude group:'com.squareup.okhttp3', module:'okhttp'
}

debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
    exclude group:'com.facebook.flipper'
}

if (enableHermes) {
    def hermesPath = "../../node_modules/hermes-engine/android/";
    debugImplementation files(hermesPath + "hermes-debug.aar")
    releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
    implementation jscFlavor
}

}

android react-native
2个回答
1
投票

这是 11 月 4 日以来与 RN 相关的问题。通过新的更新,他们打破了旧 RN 版本的 Android 构建。更多信息和修复 -> https://github.com/facebook/react-native/issues/35210


0
投票

您可以将

android/app/build.gradle
修改为

configurations {
    all*.exclude module: 'fbjni-java-only'
}

喜欢https://github.com/facebookincubator/fbjni/issues/50#issuecomment-790581813

implementation ("MY_LIBRARY") {
    exclude group:'com.facebook.fbjni', module: 'fbjni-java-only'
}

喜欢https://github.com/facebook/react-native/issues/34328#issuecomment-1208244060

或修改例如

react-native-pytorch-core/android/build.gradle

    implementation ("org.pytorch:pytorch_android_lite:${pytorchLiteVersion}") {
        exclude group:'com.facebook.fbjni', module: 'fbjni-java-only'
    }

https://github.com/flyskywhy/playtorch/commit/e131854

© www.soinside.com 2019 - 2024. All rights reserved.