I am facing a small issue, where executing kmongo code in a simple kt file with a main() function, it works fine, but when I try to implement it in my SDK project by installing it and adding "implementation 'org.litote.kmongo:kmongo:4.8.0'" to the build.gradle file, I consistently receive the following error during build: "Invalid build configuration. Attempt to create a global synthetic for 'Record desugaring' without a global-synthetics consumer." This error is definitely due to Kmongo, because if I remove the implementation, my application launches without error.

I hope you can help me with this., Thank you all.

2

There are 2 best solutions below

1
Giorgio Pigierati On

I just installed kmongo:4.5.0 instead 4.8.0 and everything work fine

0
FOOKTHISOFFICIAL On

The problem actually is on Mongodb API behalf !

If you are using KMongo(Deprecated) with a gradle version of 7.2 or higher you are more likely to face this issue as you'd be encountering it even when using Mongodb Drivers which are supposed to be working official Apis. Some libraries in both KMongo and Mongodb need to use Component.transformClassesWith API and Transform API though they're either deprecated or entirely deleted in higher gradle version - see more here and here for Replacement APIs and for Support transformations based on whole program analysis -. You can also use third-party libraries that'll do it for you. This is the error and if you try to run it with stacktrace it gives you more on what's going on exactly but it's already clear :

> 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.

Anyway, probably we can not use KMongo and Mongodb unless we're using Replacement APIs provided by Google, as i've mentioned and you can take a closer look at those links above:

Several commonly used plugins have already migrated to use these new APIs, including the Firebase performance monitoring plugin (1.4.1 is compatible with AGP 8.0) and the Hilt Gradle plugin (2.40.1 is compatible with AGP 8.0). The AGP Upgrade Assistant will also help project developers upgrade commonly used plugins as needed.

Mongodb team should get a working over KMongo and release something other than current version 4.10.2 for Kotlin. but, really, i don't really know we should blame it on Google or Mongodb..!