Electric-Coin-Company / kotlin-bip39

A concise implementation of BIP-0039 in Kotlin for Android. In order, it prioritizes being secure, concise and idiomatic.
MIT License
35 stars 8 forks source link

JVM_TARGET not being applied correctly #263

Open luca992 opened 6 months ago

luca992 commented 6 months ago

I think JVM_TARGET=8 is not being applied correctly. Using this library in a project being compiled with less than jdk 17 fails with:

Exception in thread "main" java.lang.UnsupportedClassVersionError: cash/z/ecc/android/bip39/Mnemonics$MnemonicCode 
has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime 
only recognizes class file versions up to 55.0
who-biz commented 5 months ago

Encountered this as well, when pulled in via Maven as a dependency of ZCash Wallet Android SDK.

Prevents compilation, with a less informative error message than above. Seems same issue, however.

Full error log:

ERROR:/home/xxxxxx/.gradle/caches/modules-2/files-2.1/cash.z.ecc.android/kotlin-bip39-jvm/1.0.6/87c564f7322b53c0ec2d8f6cc6b0de5d3cf2b737/bip39-lib-jvm.jar: D8: java.lang.IllegalArgumentException: Unsupported class file major version 61

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeExtDexDebug'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Failed to transform bip39-lib-jvm.jar (cash.z.ecc.android:kotlin-bip39-jvm:1.0.6) to match attributes {artifactType=android-dex, asm-transformed-variant=NONE, dexing-enable-desugaring=true, dexing-is-debuggable=true, dexing-min-sdk=27, org.gradle.category=library, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-runtime, org.jetbrains.kotlin.platform.type=jvm}.
      > Execution failed for DexingNoClasspathTransform: /home/xxxxxxx/.gradle/caches/modules-2/files-2.1/cash.z.ecc.android/kotlin-bip39-jvm/1.0.6/87c564f7322b53c0ec2d8f6cc6b0de5d3cf2b737/bip39-lib-jvm.jar.
         > Error while dexing.
who-biz commented 5 months ago

Just adding some further information:

It looks as though setting JVM_TARGET in gradle.properties is improper.

Seems there are compiler options in build.gradle.kts that were missed, detailed here: https://kotlinlang.org/docs/gradle-compiler-options.html#for-all-kotlin-compilation-tasks

More specifically, jvmTarget needs set, in Kotlin compiler options: image

More details here: https://stackoverflow.com/questions/41113268/how-to-set-up-kotlins-byte-code-version-in-gradle-project-to-java-8