MongoDB "Task :app:mergeExtDexDebug FAILED"

3

当我尝试在build.gradle的依赖块中添加mongodb-driver实现时,出现了以下构建错误。我尝试降级并启用enableDexEnable来解决这个问题,但问题仍然存在。我搜索了几乎整个互联网,但没有找到解决方案。

> Task :app:mergeExtDexDebug
AGPBI: {"kind":"error","text":"Invalid build configuration. Attempt to create a global synthetic for 'Record desugaring' without a global-synthetics consumer.","sources":[{}],"tool":"D8"}
Invalid build configuration. Attempt to create a global synthetic for 'Record desugaring' without a global-synthetics consumer.


> Task :app:mergeExtDexDebug FAILED
Execution failed for task ':app:mergeExtDexDebug'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Failed to transform bson-record-codec-4.8.1.jar (org.mongodb:bson-record-codec:4.8.1) to match attributes {artifactType=android-dex, asm-transformed-variant=NONE, dexing-enable-desugaring=true, dexing-enable-jacoco-instrumentation=false, dexing-is-debuggable=true, dexing-min-sdk=24, org.gradle.category=library, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-runtime}.
      > Execution failed for DexingNoClasspathTransform: C:\Users\user\.gradle\caches\modules-2\files-2.1\org.mongodb\bson-record-codec\4.8.1\339c92291f24acf896334ba9a2a5bf52fd462115\bson-record-codec-4.8.1.jar.
         > Error while dexing.

* Try:
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

build.gradle页面;

plugins {
    id 'com.android.application'
}

android {
    namespace 'com.example.appname'
    compileSdk 33

    defaultConfig {
        applicationId "com.example.appname"
        minSdk 21
        multiDexEnabled true
        targetSdk 33
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"


    }
    buildTypes {
        release {

            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_11
        targetCompatibility JavaVersion.VERSION_11
    }
    buildToolsVersion '33.0.1'
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.6.0'
    implementation 'com.google.android.material:material:1.7.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'org.mongodb:mongodb-driver-sync:4.8.2' //<-mongodb here
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}
1个回答

1

遇到了相同的问题,将MongoDB驱动程序版本降级为4.5.1后问题消失了。

implementation 'org.mongodb:mongodb-driver-sync:4.5.1'

可能与Java版本和MongoDB驱动程序使用较新的Java功能有关(例如,Java 16中的记录功能)。我没有调查过,因为在我的情况下降级可以正常工作。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接