Skip to content

Inconsistent JVM-target compatibility detected #209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
agoransson opened this issue Feb 23, 2025 · 1 comment
Open

Inconsistent JVM-target compatibility detected #209

agoransson opened this issue Feb 23, 2025 · 1 comment

Comments

@agoransson
Copy link

agoransson commented Feb 23, 2025

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 agoransson changed the title Inconsistent JVM-target compatibility detected for tasks 'compileDebugJavaWithJavac' (17) and 'compileDebugKotlin' (21). Inconsistent JVM-target compatibility detected Feb 23, 2025
@CATALYST1109
Copy link

CATALYST1109 commented Mar 27, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants