Skip to content

Android Studio overrides original global JAVA_HOME env value #343

@iamironz

Description

@iamironz

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions