Skip to content

Fix JVM target mismatch on AGP 8+#60

Open
friederbluemle wants to merge 1 commit intopeterferguson:mainfrom
friederbluemle:fix-jvm-target
Open

Fix JVM target mismatch on AGP 8+#60
friederbluemle wants to merge 1 commit intopeterferguson:mainfrom
friederbluemle:fix-jvm-target

Conversation

@friederbluemle
Copy link
Copy Markdown

@friederbluemle friederbluemle commented Apr 9, 2026

Targeted (partial?) replacement for #59

The kotlinOptions block that sets jvmTarget to 17 was only applied inside an if (agpVersion < 8) guard, presumably assuming AGP 8+ would automatically propagate the Java compileOptions target to Kotlin. It does not - that only happens when using jvmToolchain().

On AGP 8+ with Kotlin 2.x (which defaults to JVM target 21), this caused a build failure:

$ ./gradlew :react-native-passkeys:compileDebugKotlin
[...]
> ❌ Inconsistent JVM Target Compatibility Between Java and Kotlin Tasks
  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

Replace the version-guarded compileOptions/kotlinOptions blocks with a single kotlin.jvmToolchain(17) call, which is the approach used by both React Native (ReactAndroid) and expo-modules-core. This sets both Java and Kotlin compilation targets in one place, eliminating the mismatch regardless of AGP version.

Summary by CodeRabbit

  • Chores
    • Modernized the Android build system configuration for improved stability, consistency, and predictability across all development and production environments. Consolidated Java version compatibility handling and removed unnecessary conditional build logic to streamline the build process. These infrastructure updates ensure more reliable builds, strengthen maintainability, and reduce build complexity while preserving all existing user functionality and features.

The kotlinOptions block that sets jvmTarget to 17 was only applied
inside an `if (agpVersion < 8)` guard, presumably assuming AGP 8+
would automatically propagate the Java compileOptions target to
Kotlin. It does not — that only happens when using jvmToolchain().

On AGP 8+ with Kotlin 2.x (which defaults to JVM target 21), this
caused a build failure:

  Inconsistent JVM-target compatibility detected for tasks
  'compileDebugJavaWithJavac' (17) and 'compileDebugKotlin' (21).

Replace the version-guarded compileOptions/kotlinOptions blocks with
a single `kotlin.jvmToolchain(17)` call, which is the approach used
by both React Native (ReactAndroid) and expo-modules-core. This sets
both Java and Kotlin compilation targets in one place, eliminating
the mismatch regardless of AGP version.
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 9, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 431f4473-d5b0-402b-a238-92e333df221f

📥 Commits

Reviewing files that changed from the base of the PR and between 12f498a and 21a272b.

📒 Files selected for processing (1)
  • android/build.gradle

📝 Walkthrough

Walkthrough

The android/build.gradle build configuration was refactored to replace conditional Java 17 compilation options with a unified Kotlin toolchain configuration. Removed version-specific logic that checked Android Gradle Plugin version; Java/Kotlin version targeting is now applied consistently via kotlin.jvmToolchain(17).

Changes

Cohort / File(s) Summary
Build Configuration
android/build.gradle
Replaced compileOptions Java 17 configuration and conditional kotlinOptions.jvmTarget logic with unconditional kotlin.jvmToolchain(17). Removed Android Gradle Plugin version check that previously gated Java 17 compatibility settings.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 Hoppity-hop! The build is clean,
No more conditions, just one serene,
Kotlin toolchain standing tall,
Java 17 for one and all! 🛠️

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: replacing version-guarded JVM target configuration with a unified kotlin.jvmToolchain(17) call to fix JVM target mismatches on AGP 8+.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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

Successfully merging this pull request may close these issues.

1 participant