react-native-mlkit icon indicating copy to clipboard operation
react-native-mlkit copied to clipboard

Inconsistent JVM-target compatibility detected

Open agoransson opened this issue 8 months ago • 1 comments
trafficstars

Reproduce:

  1. npx ignite-cli@latest new pizza-app (Select most settings default, no git repo, enable new architecture)
  2. cd pizza-app
  3. yarn android

This far is fine.

  1. yarn expo install @infinitered/react-native-mlkit-document-scanner
  2. yarn android

Here it will fail to build with the following error

yarn run v1.22.22
$ expo run:android
› Building app...
Configuration on demand is an incubating feature.

> Configure project :expo

Using expo modules
  - infinitered-react-native-mlkit-core (3.1.0)
  - infinitered-react-native-mlkit-document-scanner (3.1.0)
  - expo-application (6.0.2)
  - expo-asset (11.0.4)
  - expo-constants (17.0.7)
  - expo-file-system (18.0.11)
  - expo-font (13.0.4)
  - expo-keep-awake (14.0.3)
  - expo-linking (7.0.5)
  - expo-localization (16.0.1)
  - expo-modules-core (2.2.2)
  - expo-splash-screen (0.29.22)
  - expo-system-ui (4.0.8)


> Configure project :react-native-mmkv
[react-native-mmkv] Thank you for using react-native-mmkv ❤️
[react-native-mmkv] If you enjoy using react-native-mmkv, please consider sponsoring this project: https://github.com/sponsors/mrousavy

> Configure project :react-native-reanimated
Android gradle plugin: 8.6.0
Gradle: 8.10.2

> Task :expo-constants:createExpoConfig
Warning: Root-level "expo" object found. Ignoring extra keys in Expo config: "name", "displayName", "ignite"
Learn more: https://expo.fyi/root-expo-object

> Task :app:processDebugMainManifest
/Users/agoransson/Projects/temp/pizza-app/android/app/src/debug/AndroidManifest.xml:6:5-162 Warning:
        application@android:usesCleartextTraffic was tagged at AndroidManifest.xml:6 to replace other declarations but no other declaration present
/Users/agoransson/Projects/temp/pizza-app/android/app/src/debug/AndroidManifest.xml Warning:
        provider#expo.modules.filesystem.FileSystemFileProvider@android:authorities was tagged at AndroidManifest.xml:0 to replace other declarations but no other declaration present

> Task :infinitered-react-native-mlkit-document-scanner:compileDebugKotlin FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':infinitered-react-native-mlkit-document-scanner:compileDebugKotlin'.
> Inconsistent JVM-target compatibility detected for tasks 'compileDebugJavaWithJavac' (17) and 'compileDebugKotlin' (21).
  
  Consider using JVM Toolchain: https://kotl.in/gradle/jvm/toolchain
  Learn more about JVM-target validation: https://kotl.in/gradle/jvm/target-validation 

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 7s
326 actionable tasks: 87 executed, 230 from cache, 9 up-to-date
Error: /Users/agoransson/Projects/temp/pizza-app/android/gradlew app:assembleDebug -x lint -x test --configure-on-demand --build-cache -PreactNativeDevServerPort=8081 -PreactNativeArchitectures=arm64-v8a,armeabi-v7a exited with non-zero code: 1
Error: /Users/agoransson/Projects/temp/pizza-app/android/gradlew app:assembleDebug -x lint -x test --configure-on-demand --build-cache -PreactNativeDevServerPort=8081 -PreactNativeArchitectures=arm64-v8a,armeabi-v7a exited with non-zero code: 1
    at ChildProcess.completionListener (/Users/agoransson/Projects/temp/pizza-app/node_modules/@expo/spawn-async/src/spawnAsync.ts:67:13)
    at Object.onceWrapper (node:events:632:26)
    at ChildProcess.emit (node:events:517:28)
    at maybeClose (node:internal/child_process:1098:16)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:303:5)
    ...
    at spawnAsync (/Users/agoransson/Projects/temp/pizza-app/node_modules/@expo/spawn-async/src/spawnAsync.ts:28:21)
    at spawnGradleAsync (/Users/agoransson/Projects/temp/pizza-app/node_modules/@expo/cli/src/start/platforms/android/gradle.ts:134:28)
    at assembleAsync (/Users/agoransson/Projects/temp/pizza-app/node_modules/@expo/cli/src/start/platforms/android/gradle.ts:83:16)
    at runAndroidAsync (/Users/agoransson/Projects/temp/pizza-app/node_modules/@expo/cli/src/run/android/runAndroidAsync.ts:48:24)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

System:

agoransson@MacBook-Pro pizza-app % node -v
v18.20.4

Also tested with:

agoransson@MacBook-Pro pizza-app % node -v
v20.12.2

agoransson avatar Feb 23 '25 17:02 agoransson

I faced the same issue, and while I'm not sure whether my fix is the correct way or not, it worked.

There is this piece of code in build.gradle in the android folder:

if (agpVersion.tokenize('.')[0].toInteger() < 8) {
    compileOptions {
      sourceCompatibility JavaVersion.VERSION_17
      targetCompatibility JavaVersion.VERSION_17
    }

    kotlinOptions {
      jvmTarget = JavaVersion.VERSION_17.majorVersion
    }
  }

Either remove the if condition, or just paste the contents of the if block outside so it always runs. Specifying the compile options and kotlinOptions unconditionally worked for me.

CATALYST1109 avatar Mar 27 '25 08:03 CATALYST1109

Hey folks - once we merge and ship https://github.com/infinitered/react-native-mlkit/pull/233, I'll try to reproduce this one again and see if it's still an issue on latest. We changed up an Expo Modules Core dependency that might fix it on latest. I'll mark as needs reproduction for now and swing back around soon to check in.

coolsoftwaretyler avatar Nov 16 '25 20:11 coolsoftwaretyler

Hey folks, I think you may just be using an incompatible Java version. I was not able to reproduce this locally, but based on the error message, I presume you've got some Java runtime different from 17, which is the recommended set up in the React Native docs.

Can you try setting up your environment according to those specs and try again? If it still doesn't work, can you send the output of your java --version as well?

coolsoftwaretyler avatar Nov 17 '25 14:11 coolsoftwaretyler