Skip to content
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

[Bug]: Capacitor 7 is using JDK 21 for building android #7839

Closed
1 of 3 tasks
mleister97 opened this issue Jan 22, 2025 · 5 comments
Closed
1 of 3 tasks

[Bug]: Capacitor 7 is using JDK 21 for building android #7839

mleister97 opened this issue Jan 22, 2025 · 5 comments
Labels

Comments

@mleister97
Copy link

mleister97 commented Jan 22, 2025

Capacitor Version

Latest Dependencies:

@capacitor/cli: 7.0.1
@capacitor/core: 7.0.1
@capacitor/android: 7.0.1
@capacitor/ios: 7.0.1

Installed Dependencies:

@capacitor/android: 7.0.1
@capacitor/cli: 7.0.1
@capacitor/ios: 7.0.1
@capacitor/core: 7.0.1

Platforms Affected

  • iOS
  • Android
  • Web

Current Behavior

I just had a discussion with the maintainer of a Capacitor community package (see here capacitor-community/safe-area#43) who believes that Android does not support JDK 21 and only supports up to JDK 17. Because of this, I am unable to use this plugin. After a quick search, I came across https://developer.android.com/build/jdks which confirms that JDK 17 is used throughout.

Why does the latest version of Capacitor require JDK 21? Is it officially supported?

Expected Behavior

I am not sure, but imo Capacitor should use

android {
  compileOptions {
      sourceCompatibility JavaVersion.VERSION_17
      targetCompatibility JavaVersion.VERSION_17
  }
}

instead of 21

Answer of the capacitor-community plugin member:

@tafelnl

I don't know why it says that. I think there's a lot of misinformation and confusion around the JDK versioning among the Android community. As far as I understand you could try and get JDK 21 to work. If it works for you, good for you. But nowhere does Google claim that Android supports JDK 21 for building. So I think it's a mistake on Capacitor's part

@mleister97 mleister97 changed the title [Bug]: Capacitor 7 is using JDK 21 [Bug]: Capacitor 7 is using JDK 21 for building android Jan 22, 2025
@tafelnl
Copy link

tafelnl commented Jan 22, 2025

For reference also:

AndroidIDEOfficial/AndroidIDE#1800 (comment)
AndroidIDEOfficial/AndroidIDE#1657

It seems to be a widespread misconception. If you do a quick google for Android JDK 21 errors you get tons of results (not necessarily Capacitor related). All of which can be resolved by downgrading to JDK 17

@tafelnl
Copy link

tafelnl commented Jan 22, 2025

In the changelog of Android 15 they make an explicit mention about JDK 17: https://developer.android.com/about/versions/15/features#core-libraries

OpenJDK 17 updates
Android 15 continues the work of refreshing Android's core libraries to align with the features in the latest OpenJDK LTS releases.

Further confirming that JDK 21 support is just a coincidence at times

@jcesarmobile
Copy link
Member

Android Studio Ladybug was shipped with JDK 21 and it was causing issues on projects configured to use JDK 17, so we updated Capacitor to use JDK 21 and made the usage of Ladybug a requirement for Capacitor 7.

If it wasn't compatible I don't think they would be releasing Android Studio with an unsupported JDK version.

We also updated gradle to 8.11, which should be compatible with JAVA up to 23.

@jcesarmobile jcesarmobile closed this as not planned Won't fix, can't repro, duplicate, stale Jan 22, 2025
@tafelnl
Copy link

tafelnl commented Jan 22, 2025

Gradle x Android compatibility goes up to Android Gradle Plugin v8.7 (https://docs.gradle.org/current/userguide/compatibility.html#android)

Gradle is tested with Android Gradle Plugin 7.3 through 8.7. Alpha and beta versions may or may not work.

According to the release notes the minimum (and default) version of Gradle for Android Gradle Plugin v8.7 is 8.9 (https://developer.android.com/build/releases/past-releases/agp-8-7-0-release-notes#compatibility)

The minimum and default JDK version for Android Gradle Plugin v8.7 is set to JDK 17 https://developer.android.com/build/releases/past-releases/agp-8-7-0-release-notes#compatibility

Gradle 8.9 itself seems to supports up to Java 22. (https://docs.gradle.org/current/userguide/compatibility.html#java_runtime)

I cannot find anywhere that the Android Gradle Plugin is compatible with JDK 21. Only either explicit or vague mentions that it supports JDK 17: https://developer.android.com/build/jdks and https://developer.android.com/about/versions/15/features#core-libraries

I doubt that the Android team actually either intends everyone to compile their app using JDK 21 or for everyone to make their plugins/sdks support JDK 21.

I'm not working for the Android team however, so it would probably be best to ask them for advise.

Anyhow, the Gradle ecosystem is quite confusing and the documentation lacks pretty hard at this point

@tafelnl
Copy link

tafelnl commented Jan 22, 2025

Scott Stanchfield claims to have written the docs about the JDK versioning. He answers the following on SO: https://stackoverflow.com/a/77109376/8634342

The main place Google keeps the info for which Java levels are supported is Which Java APIs can I use in my Java or Kotlin source code?

Toolchain JDK - default for source and target levels, as well as JDK used to run unit tests. I strongly recommend using this instead of sourceCompatibility, targetCompatibility and jvmTarget. Set by adding

kotlin {
  jvmToolchain(17)
}

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

No branches or pull requests

3 participants