Status Update
Comments
ar...@google.com <ar...@google.com>
je...@google.com <je...@google.com>
hu...@google.com <hu...@google.com> #2
As the error message says, please use source/targetCompatibility
instead, i.e.:
tasks.withType<JavaCompile>().configureEach {
sourceCompatibility = "11"
targetCompatibility = "11"
}
I'm resolving this bug, but will follow up if you have any questions.
ma...@gmail.com <ma...@gmail.com> #3
As the error message says, please use source/targetCompatibility instead, i.e.:
- Which error? Error says to use toolchains which I do use. The warning says setting a
--release
"could cause issues", but doesn't explain what issues and attaches a dead link, which makes me believe the warning is invalid/outdated. - The construct you shared uses API that is "not generally advised" by Gradle -
https://docs.gradle.org/current/userguide/building_java_projects.html#sec:java_cross_compilation - Setting a
--release
option is the recommended way fororg.jetbrains.kotlin.jvm
projects
The expected behaviour is to either remove the invalid/outdated warning or update the warning message, so it explains what it tries to achieve.
So, since the bug is still there, and this issue got prematurely closed - should I file a new issue? Or can you still reopen this one?
hu...@google.com <hu...@google.com> #5
I think the explanation for this behavior is as follows:
- The
--release
option forjavac
is essentially a replacement for the-source
,-target
, and--boot-class-path
options. So we can only use one or the other. Trying to use both will result in the following error fromjavac
:
error: option -source cannot be used together with --release
- For projects targeting JVM, either option is possible, and
--release
is preferred. However, for projects targeting Android, they need to be compiled againstandroid.jar
, so AGP needs to overwrite the JDK boot classpath withandroid.jar
using the--system
or--boot-class-path
options. And these options are not compatible with--release
:
error: option --system cannot be used together with --release
error: option --boot-class-path cannot be used together with --release
Therefore, in Android, we have to use the combination of -source
, -target
, and --system
/--boot-class-path
options instead of --release
.
For more info, please see
I'm planning to update the message to summarize the above info and also change it from warning to error.
hu...@google.com <hu...@google.com> #6
I'm planning to update the message to summarize the above info and also change it from warning to error.
This is now done in AGP 8.4.0-alpha02. The change is
Thank you for this report!
an...@google.com <an...@google.com> #7
Thank you for your patience while our engineering team worked to resolve this issue. A fix for this issue is now available in:
- Android Studio Jellyfish | 2023.3.1 Canary 1
- Android Gradle Plugin 8.4.0-alpha01
We encourage you to try the latest update.
If you notice further issues or have questions, please file a new bug report.
Thank you for taking the time to submit feedback — we really appreciate it!
Description
STEPS TO REPRODUCE:
1. Have a custom Gradle plugin
2. Add
```kotlin
tasks.withType<JavaCompile>().configureEach {
options.release.set(11)
}
```
3. Apply the plugin to all projects (including `org.jetbrains.kotlin.jvm` and `com.android.library`
4. Compile the project `./gradlew assemble`
5. Console gets polluted with:
```
WARNING: Using '--release' option could cause issues when using Android Gradle Plugin to compile sources with Java 9+. Instead, please set 'sourceCompatibility' and 'targetCompatibility' to the desired Java version, and set 'compileSdkVersion' to 30 or above. See
```
And the problem is I do want to set `--release`, as I want all task in the project use the same java version. Regardles if it's an Android or kotlin-only module.
I do have `sourceCompatibility` set.
I do have `compileSdk` set to >30, but I still see an error.
I expected to see a link explaining how to disable the warning, but it turns out the link is dead already.
I expected to see clear message explaining what kind of "issues" current config may cause.
If I remove the `--release` then my Kotlin modules will target wrong java version and the build fails with:
```
'compileJava' task (current target is 17) and 'compileKotlin' task (current target is 11) jvm target compatibility should be set to the same Java version.
Consider using JVM toolchain:
```
I don't expect to see a warning if I have everything set properly, or at least have a way to disable the invalid warning
Can you please share how to remove that warning?
ATTACH SCREENSHOTS/RECORDINGS OF THE ISSUE
ATTACH LOG FILES (Select Help > Show Log in Files, or Show Log in Finder on a Mac)
------------------
IMPORTANT: Please read
all required information.
------------------
Studio Build: None
Version of Gradle Plugin: 8.0.0
Version of Gradle:
```
------------------------------------------------------------
Gradle 8.1
------------------------------------------------------------
Build time: 2023-04-12 12:07:45 UTC
Revision: 40ba32cde9d6daf2b92c39376d2758909dd6b813
Kotlin: 1.8.10
Groovy: 3.0.15
Ant: Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM: 20 (Homebrew 20)
OS: Mac OS X 13.3.1 x86_64
```
Version of Java:
```
openjdk version "20" 2023-03-21
OpenJDK Runtime Environment Homebrew (build 20)
OpenJDK 64-Bit Server VM Homebrew (build 20, mixed mode, sharing)
```
OS: All