hyperledger-web3j / web3j

Lightweight Java and Android library for integration with Ethereum clients
https://www.web3labs.com/web3j-sdk
Other
5.11k stars 1.68k forks source link

Invalid build configuration. Attempt to create a global synthetic for 'Record desugaring' without a global-synthetics consumer. #1963

Open JR-05 opened 1 year ago

JR-05 commented 1 year ago

Issuetitle

Execution failed for task ':app:mergeExtDexDevDebug'.

Environment

IDEA: AndroidStudio Web3j 4.10.2 Java version: zuluDK17 Operating System Win10 Gradle version: 7.6

Error


JR-05 commented 1 year ago

I also need to add a special configuration, that is, if minifyEnabled = true, everything will be normal.

koala0x commented 1 year ago

I also encountered this problem

honey201 commented 8 months ago

I also encountered this problem. Did anyone able to fix this?

abir4u commented 2 months ago

As mentioned above, I tried making minifyEnabled = true, but that did not solve the problem for me.

I found out that in my case, the issue triggers if I add this in build.gradle

dependencies {
    implementation("org.mongodb:mongodb-driver-kotlin-coroutine:5.2.0")
}

I followed these steps from MongoDB documentation.

Still trying to find a fix for it.

Updated my comment 👆 @rohandakua @mongodb

rohandakua commented 2 months ago

packaging { resources { excludes += "/META-INF/DISCLAIMER" } } packagingOptions { resources { excludes += setOf( "META-INF/LICENSE.md", "META-INF/LICENSE.txt", "META-INF/NOTICE", "META-INF/NOTICE.txt", "META-INF/LICENSE-notice.md" ) } } add this in our build.gradle of our app inside android section and also make sure the java version is 17 in app.build.gradle

abir4u commented 2 months ago

packagingOptions { resources { excludes += setOf( "META-INF/LICENSE.md", "META-INF/LICENSE.txt", "META-INF/NOTICE", "META-INF/NOTICE.txt", "META-INF/LICENSE-notice.md" ) } }

@rohandakua This didn't fix the issue for me unfortunately.

rohandakua commented 2 months ago

packagingOptions { resources { excludes += setOf( "META-INF/LICENSE.md", "META-INF/LICENSE.txt", "META-INF/NOTICE", "META-INF/NOTICE.txt", "META-INF/LICENSE-notice.md" ) } }

@rohandakua This didn't fix the issue for me unfortunately.

Can you use 4.12.1 version of web3j implementation("org.web3j:core:4.12.1")

abir4u commented 2 months ago

implementation("org.web3j:core:4.12.1")

That didn't work. In fact, it got worse. Before, org.mongodb:mongodb-driver-kotlin-coroutine dependency was causing the issue. But when I added the dependency org.web3j:core:4.12.1, I get the same failure even if I comment out coroutine.

abir4u commented 2 months ago

Finally solved the issues. 🎉

Issue 1:

Invalid build configuration. Attempt to create a global synthetic for 'Record desugaring' without a global-synthetics consumer.

This issue was happening because my Kotlin and Java versions were not aligned.The JVM target mentioned in the build.gradle was 1.8 and I was using JDK 17.

I changed the following in android block of build.gradle

compileOptions {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }
    kotlinOptions {
        jvmTarget = "17"
    }

Issue 2:

2 files found with path 'META-INF/native-image/native-image.properties'

I added this in build.gradle to fix it:

excludes += "META-INF/native-image/**"

@rohandakua - Thanks for the idea 🥳 👆

This helped exclude all files and folders inside the META-INF/native-image directory from my final APK or AAB.

rohandakua commented 2 months ago

congrats sir 🎉