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

Android Studio overrides original global JAVA_HOME env value #343

Open
iamironz opened this issue Apr 18, 2024 · 3 comments
Open

Android Studio overrides original global JAVA_HOME env value #343

iamironz opened this issue Apr 18, 2024 · 3 comments

Comments

@iamironz
Copy link

Hey!
Thank you for this plugin, very much appreciate the effort you put into development.

I have the following setup for my project:

The plugin version is 0.9.2.

Settings used:

doctor {
    downloadSpeedWarningThreshold = .5f
    GCWarningThreshold = 0.10f
    GCFailThreshold = 0.9f
    daggerThreshold = 5000
    failOnEmptyDirectories = true
    allowBuildingAllAndroidAppsSimultaneously = true
    warnWhenJetifierEnabled = true
    negativeAvoidanceThreshold = 500
    warnWhenNotUsingParallelGC = true
    disallowCleanTaskDependencies = true
    warnIfKotlinCompileDaemonFallback = true
    appleRosettaTranslationCheckMode = com.osacky.doctor.AppleRosettaTranslationCheckMode.ERROR
    javaHome {
        ensureJavaHomeMatches = true
        ensureJavaHomeIsSet = true
        failOnError = false
    }
}

However, a while ago, Google introduced something bizarre: they started overriding the global JAVA_HOME to their bundled JDK, and moved out the originally defined value to the GRADLE_LOCAL_JAVA_HOME.

As per newer versions of Android Studio we have:

Screenshot 2024-04-18 at 11 23 03 AM

Where GRADLE_LOCAL_JAVA_HOME is my actual JAVA_HOME.
As you can see, they forcibly swapped it, which is extremely weird IMO.

If I switch to GRADLE_LOCAL_JAVA_HOME in AS I will obviously get following the message after the configuration is complete:

=============================== Gradle Doctor Prescriptions ============================================
| JAVA_HOME is not set.                                                                                |
| Please set JAVA_HOME so that switching between Android Studio and the terminal does not trigger a fu |
| ll rebuild.                                                                                          |
| To set JAVA_HOME: (using bash)                                                                       |
| echo "export JAVA_HOME=$(/usr/libexec/java_home)" >> ~/.bash_profile                                 |
| or `~/.zshrc` if using zsh.                                                                          |
|                                                                                                      |
========================================================================================================
| Gradle is not using JAVA_HOME.                                                                       |
| JAVA_HOME is null                                                                                    |
| Gradle is using /opt/homebrew/Cellar/openjdk@17/17.0.10/libexec/openjdk.jdk/Contents/Home            |
| This can slow down your build significantly when switching from Android Studio to the terminal.      |
| To fix: Project Structure -> JDK Location.                                                           |
| Set this to your JAVA_HOME.                                                                          |
|                                                                                                      |
========================================================================================================

And this is expected, the doctor plugin works just fine here.
But now within the AS, there's no option to use my real JAVA_HOME and doctor plugin option with its checking at the same time anymore.

Probably you have some suggestions/thoughts about this?

Thank you!

@iamironz iamironz changed the title Override original global JAVA_HOME env value by Android Studio Android Studio overrides original global JAVA_HOME env value Apr 18, 2024
@dsvoronin
Copy link
Contributor

Just to add more context.
I had some questions regarding this new GRADLE_LOCAL_JAVA_HOME and how to properly use it: https://issuetracker.google.com/issues/214428183#comment9 , see Googler's answer

@trietbui85
Copy link

Hi @dsvoronin Does it mean the fix won't be included in the Gradle Doctor plugin?

@runningcode
Copy link
Owner

@iamironz Thanks for starting this conversation and the detailed explanation.

@dsvoronin thanks for the link to the google issue tracker

@trietbui85 what fix are you expecting in Gradle Doctor this issue doesn’t describe anything wrong with Gradle Doctor.

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

4 participants