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

Incorrect parsing of JAVA_VERSION in build.gradle, wrong java version for compileOptions #1264

Closed
ultraon opened this issue Feb 17, 2025 · 2 comments

Comments

@ultraon
Copy link

ultraon commented Feb 17, 2025

Hello guys. I found that it might be incorrect parsing of the JAVA_VERSION in the build.gradle, see

def pattern = Pattern.compile("JAVA_VERSION=\"(\\d+)\"")

Java version is often is kind of JAVA_VERSION="17.0.3" in the release file. So, the regex can't detect the string "17.0.0" or "17.0.3", it tries to find exactly the number without any splitter (e.g. "." - dot).

But even though, if it parses the version correctly, there is another issue. After detecting that the java version is "21", it can't build the android project, because of these lines

compileOptions {
def version = getJavaVersion()
sourceCompatibility = version
targetCompatibility = version
}

whenever the version of Java is greater than "17", because Android doesn't support the higher version (I tried java version "21").

I got this case on old version of photo-manager library, when I installed the latest Android Studio "2024.2.2" that embeds Java 21. It happens because when we run flutter run command, it overrides JAVA_HOME env variable with a java version embedded in the latest Android Studio installed on the local machine, and if the Android Studio isn't detected, than it fallbacks to JAVA_HOME system env.

As a result of this issue:

Execution failed for task ':photo_manager: compileDebugJavaWithJavac' .
> error: invalid source release: 21

I think that the library shouldn't explicitly set compileOptions.

What do you think?

@fluttercandies-dev
Copy link

AI Summary: The build.gradle file incorrectly parses JAVA_VERSION due to regex issues and sets compileOptions to an unsupported Java version, causing build failures. The user suggests removing the explicit compileOptions setting.

@ultraon
Copy link
Author

ultraon commented Feb 17, 2025

Added comment related to the issue #1198 (comment)

@AlexV525 AlexV525 pinned this issue Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants