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

[8.0.0] Android environment variables: ANDROID_HOME vs ANDROID_SDK_ROOT - cosmetic display issue #670

Closed
janpio opened this issue Feb 14, 2019 · 31 comments · Fixed by #951
Closed

Comments

@janpio
Copy link
Member

janpio commented Feb 14, 2019

Hey @brodybits (as I remember you pushed a PR in this area), check out the output of running cordova build android on a brand new machine where I just installed Android Studio:

E:\Projects\throwaway\cordovaAndroid8Test  (helloworld@1.0.0)
λ cordova platform list
Installed platforms:
  android 8.0.0
Available platforms:
  browser ~5.0.1
  ios ~4.5.4
  osx ~4.0.1
  windows ~6.0.0

E:\Projects\throwaway\cordovaAndroid8Test  (helloworld@1.0.0)
λ cordova build android
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=undefined (recommended setting)
ANDROID_HOME=C:\Users\Jan\AppData\Local\Android\sdk (DEPRECATED)
Starting a Gradle Daemon (subsequent builds will be faster)

...

Strange that this set ANDROID_HOME, and not ANDROID_SDK_ROOT, isn't it?

@janpio janpio changed the title Android environment variables [8.0.0] Android environment variables Feb 14, 2019
@janpio janpio changed the title [8.0.0] Android environment variables [8.0.0] Android environment variables: ANDROID_HOME vs ANDROID_SDK_ROOT Feb 14, 2019
@brody4hire brody4hire added the bug label Feb 14, 2019
@brody4hire
Copy link

(as I remember you pushed a PR in this area), check

PR #656, which was raised to resolve #617

Strange [...]?

Yes.

The explanation is that check_reqs.js would internally set its own process ANDROID_HOME environmental variable according to where it found the right place, in the following inner function:

function maybeSetAndroidHome (value) {
if (!hasAndroidHome && fs.existsSync(value)) {
hasAndroidHome = true;
process.env['ANDROID_HOME'] = value;
}
}

I resolved #617 without changing how this part works in order to support non-deprecated Android SDK behavior without blocking the major release.

The correct solution would be for check_reqs.js to track the correct Android SDK root in an internal variable and then log the value of the internal variable in a user-friendly manner. I just added the bug label, cannot promise when I will get a chance to fix it.

@janpio
Copy link
Member Author

janpio commented Feb 14, 2019

Wouldn't this also mean that if something is actually broken with the env variables the error message to the user would be misleading when we mess with the variables? (Not sure if this can or does actually happen - just thinking out loud.)

@brody4hire
Copy link

Wouldn't this also mean that if something is actually broken with the env variables the error message to the user would be misleading when we mess with the variables?

I think so. I hope someone will get a chance to fix it.

@phiferd
Copy link

phiferd commented Apr 11, 2019

This causes problems for me. The symptom is:

> cordova build android

... (omitted for clarity)

* Where:
Script 'C:\Users\...\platforms\android\CordovaLib\cordova.gradle' line: 68

* What went wrong:
A problem occurred evaluating project ':app'.
> No installed build tools found. Install the Android build tools version 19.1.0 or higher.

In the generated cordova.gradle, the getAndroidSdkDir() function uses ANDROID_HOME rather than ANDROID_SDK_ROOT. The maybeSetAndroidHome function only overrides the android home value if it isn't already set. That means that in the gradle routine, it will continue to use the deprecated value even if the ANDROID_SDK_ROOT env variable is set.

It's very counter intuitive that a deprecated value would take precedence over the non-deprecated value.

At the very least, the error message should be improved, as it will lead people down the path of uninstalling and reinstalling the build tools, which isn't the issue at all. Maybe:

Could not find build tools in <DIRECTORY THAT WAS CHECKED>, ensure your ANDROID_SDK_ROOT env variable is set correctly and the ANDROID_HOME env variable is removed

@yordanosz
Copy link

https://www.oracle.com/technetwork/java/javase/downloads/java-archive-javase8-2177648.html
In case someone searching for jdk files

@basurahan
Copy link

Please fix the issue

@basurahan
Copy link

Hi my old project would build successfully.
But the one that i created just a few minutes ago did not build with the message

Android SDK not found. Make sure that it is installed. If it is not at the default location, set the ANDROID_HOME environment variable.

Tho my ANDROID_HOME is set and my old project is building successfully i dont know how to get around with it can you help me?

@janpio
Copy link
Member Author

janpio commented May 25, 2019

Definitely not in an unrelated, old issue.

@uvconnects
Copy link

I have the same proble building with cordova, came out of no where
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=undefined (recommended setting)
ANDROID_HOME=C:\Android\android-sdk (DEPRECATED)
Subproject Path: CordovaLib
Subproject Path: app

@vignesh-d
Copy link

I have the same problem building with cordova, came out of no where
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=undefined (recommended setting)
ANDROID_HOME=C:\Android\android-sdk (DEPRECATED)
Subproject Path: CordovaLib
Subproject Path: app

Capture

@gabrielle88
Copy link

I have the same problem..had anyone found a solution?

@breautek
Copy link
Contributor

Can someone clarify the actual problem? Is it that ANDROID_SDK_ROOT is not read?

In my environments I have both ANDROID_SDK_ROOT and ANDROID_HOME set and that works just fine.

@uvconnects
Copy link

I read this is just a display issue. They were working on it.

@gazsmith10

This comment has been minimized.

@luccadumas

This comment has been minimized.

@vignesh-d
Copy link

I hope I found a solution. And Its working for me.
The problem is with the Gradle.
I have just uninstalled ionic cordova and android studio and reset the PC.

And declared environment variables.
1
2
3
4

Gradle now
For Windows:

-Download last version of Gradle (https://gradle.org/releases)

-Create a folder and unzip files (I use C:\Program Files (x86)\gradle)

-Copy the path with the bin directory included (C:\Program Files (x86)\gradle\bin)

-Set the path C:\Program Files (x86)\gradle\bin (in my exemple) to "Path Environment Variables"

Variable name "Path" and variable value "C:\Program Files (x86)\gradle\bin" for both: User Variable table and System Variables table

You may need to reopen the "Prompt commad line"

To test, type gradle in prompt.

This procedure works fine.

@janpio
Copy link
Member Author

janpio commented Sep 4, 2019

You are all posting in an issue that states that there is no problem, and that this is just a cosmetic problem without actual negative effects. So if you say "same issue", you are saying that you also see a cosmetic problem that doesn't require to be fixed.

If you have an actual problem of something not working, do not post here but create a new issue where you include all the relevant information.

@luccadumas

This comment has been minimized.

@luccadumas

This comment has been minimized.

@phiferd
Copy link

phiferd commented Sep 4, 2019

@luccadumas -- have you tried setting the ANDROID_SDK_ROOT env variable and removing the ANDROID_HOME variable?

@janpio , I'm not sure it's really "just cosmetic" -- builds that used to work now fail. Also, I'm not sure if the root cause is the same in all of the cases listed above.

For me, iirc, the issue was that I had a working build one day, and the next day I didn't, even though I didn't change my code. I suspect I did a clean install and new minor versions of packages were updated.

Please see my earlier comment (#670 (comment)) with a more detailed description of what I found. As I see it, it looks like the deprecation of an old ENV variable was implemented in an odd way and it is causing unnecessary churn (this thread, for example). However, I only spent enough time in the gradle code to understand why it wasn't working, so I could be wrong.

@janpio
Copy link
Member Author

janpio commented Sep 4, 2019

Also, I'm not sure if the root cause is the same in all of the cases listed above.

No it is not - but I created this issue, and is it specifically about the cosmetic problem. As I posted above, if something is actually broken for you, open a new issue and include all the information it asks for.

@jeraldpunx
Copy link

I have the same problem, anybody found the solution already?

@PMMRanger
Copy link

Same problem here (unbuntu 19.04). It is certainly not "cosmetic" as I cannot run or build when using "cordova run android". I do think it a little sad that no one seems interested in fixing a cosmetic error that is causing untold lost hours chasing ghosts. However, no ghost here. Real issue and dead in the water.

@mallajay
Copy link

Environment Variable For Windows
ANDROID_HOME
C:\Users${user}\AppData\Local\Android\sdk (deprecated)

ANDROID_SDK_ROOT
C:\Users${user}\AppData\Local\Android\sdk

JAVA_HOME
C:\Program Files\java${jdkVersion}

PATH
C:\Users${user}\AppData\Local\Android\sdk\platform-tools

PATH
C:\Users${user}\AppData\Local\Android\sdk\tools\bin

PATH
C:\Users${user}\AppData\Local\Android\sdk\emulator

PATH
C:\Users${user}\AppData\Local\Android\sdk\build-tools${version}

PATH
C:\Program Files\java${jdkVersion}\bin

@mallajay
Copy link

Environment Variable For LINUX/MAC

export ANDROID_SDK_ROOT=$HOME/Library/Android/sdk

export ANDROID_HOME=$HOME/Library/Android/sdk (deprecated)

# avdmanager, sdkmanager
export PATH=$PATH:$ANDROID_SDK_ROOT/tools/bin

# adb, logcat
export PATH=$PATH:$ANDROID_SDK_ROOT/platform-tools

# emulator
export PATH=$PATH:$ANDROID_SDK_ROOT/emulator

# apksigner, zipalign
export PATH=$PATH:$ANDROID_SDK_ROOT/build-tools/${version}


@brody4hire brody4hire changed the title [8.0.0] Android environment variables: ANDROID_HOME vs ANDROID_SDK_ROOT [8.0.0] Android environment variables: ANDROID_HOME vs ANDROID_SDK_ROOT display issue Sep 20, 2019
@brody4hire
Copy link

brody4hire commented Sep 20, 2019

I just updated the title to make it 100% clear that this issue is about a display issue. In case of anything beyond a display issue we would like to kindly ask that someone raise a new issue so that we can keep our issues clearly focused, trackable, and actionable. Please do feel free to reference this issue from a new issue as I think this would be relevant, GitHub will show the references here.

We have already marked this issue as a bug, so it is on our todo list.

P.S. I further updated the title to indicate that we see this as a cosmetic display issue. We would like to kindly ask that people raise a new issue if they see this kind of behavior as anything other than a cosmetic display issue. And we would kindly ask people to simply use GitHub Reactions as described in [1] if they think we should fix this issue.

I did change some hidden comments from "spam" to "resolved" as I personally did not see any attempt to actually spam us.

[1] https://github.blog/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/

@brody4hire brody4hire changed the title [8.0.0] Android environment variables: ANDROID_HOME vs ANDROID_SDK_ROOT display issue [8.0.0] Android environment variables: ANDROID_HOME vs ANDROID_SDK_ROOT - cosmetic display issue Sep 20, 2019
@75341704
Copy link

75341704 commented Sep 30, 2019

hello any idea about this problem?

I work under the macOS:

cordova build cordova
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=undefined (recommended setting)
ANDROID_HOME=/Users/developer/Library/Android/sdk (DEPRECATED)
Requirements check failed for JDK 8 ('1.8.*')! Detected version: 11.0.1
Check your ANDROID_SDK_ROOT / JAVA_HOME / PATH environment variables.

The .bash_profile is as follows,
export ANDROID_SDK_ROOT=$HOME/Library/Android/sdk
export ANDROID_HOME=$HOME/Library/Android/sdk
export JAVA_8_HOME="$(/usr/libexec/java_home -v 1.8)"
export JAVA_11_HOME="$(/usr/libexec/java_home -v 11)"
alias jdk8='export JAVA_HOME=$JAVA_8_HOME'
alias jdk11='export JAVA_HOME=$JAVA_11_HOME'
export JAVA_HOME=$JAVA_8_HOME
export GRADLE_HOME=/Users/developer/code/gradle-5.6.2
export PATH=${PATH}:${SWIG_HOME}/bin:${MY_BIN}:$ANDROID_SDK_ROOT/tools:$GRADLE_HOME/bin:$ANDROID_HOME/platform-tools

And no matter how the environment is , the problem is stil right here.

@breautek
Copy link
Contributor

@75341704 This issue is a cosmetic issue, not a functional issue, as stated several times before. If something is functionally not working for you, please raise a new issue and fill out the form completely.

@janpio is it possible to lock this thread so only contributors can comment? If so, perhaps it is time to so...

@75341704
Copy link

@75341704 This issue is a cosmetic issue, not a functional issue, as stated several times before. If something is functionally not working for you, please raise a new issue and fill out the form completely.

@janpio is it possible to lock this thread so only contributors can comment? If so, perhaps it is time to so...

mv /Library/Java/JavaVirtualMachines/jdk-11.0 ~/otherfolder
and it works.

The environment detection may have some problem.

@Kunj-Choksi
Copy link

Kunj-Choksi commented Oct 16, 2019

I am facing a weird issue.
I wrote the ANDROID_HOME variable in bash_profile.
Then I hit cmd ‘source bash_profile’.
Now echoing my env variables works fine. Until I close the terminal.
It just got vanished if I close the terminal.
To recover, I need to run cmd ‘source bash_profile’.

macOS Cataline

@breautek
Copy link
Contributor

@Kunj-Choksi

Your comment is unrelated to the ticket at hand. To quickly answer your question though, I believe macs use ~/.profile instead of ~/.bash_profile.

I am locking this thread due to the number of unrelated comments. As stated before, this issue describes a cosmetic issue. If you do have a functional issue, then you should raise a new ticket and fill out the form appropriately.

@apache apache locked as off-topic and limited conversation to collaborators Oct 16, 2019
breautek added a commit to breautek/cordova-android that referenced this issue Apr 12, 2020
This commit does the following:
- Makes ANDROID_SDK_ROOT the primary variable to look for the Android SDK location.
- Makes ANDROID_HOME the fallback variable, if ANDROID_SDK_ROOT is not present/valid.

Gradle updates:
Note that the following gradle updates were required, otherwise the android gradle plugin did not honour the ANDROID_SDK_ROOT variable.

- Updates the framework's android studio's gradle plugin from version 3.3.0 to 3.5.3.
	Not only this is required for android's gradle to obey ANDROID_SDK_ROOT, it is now in sync with the Android test project/
- Updates the Androidx test project to use gralde plugin from version 3.3.0 to 3.5.3, to match Android Test & framework.
	- Consequentially, this required to also upgrade AndroidX test project to use Gradle 6.1, which also matches both the Android test project & framework

These changes above fixes apache#949

Additionally, since we update the environment variables dynamically, the environment variable printout produced misleading information.
The environment variable printout will now print out the variable as defined by the user (before the tooling messes with them). An additional log
is printed that tells the user exactly what Cordova is going to use for the Android SDK path. This should fix apache#670
breautek added a commit to breautek/cordova-android that referenced this issue Apr 13, 2020
This commit does the following:
- Makes ANDROID_SDK_ROOT the primary variable to look for the Android SDK location.
- Makes ANDROID_HOME the fallback variable, if ANDROID_SDK_ROOT is not present/valid.

Gradle updates:
Note that the following gradle updates were required, otherwise the android gradle plugin did not honour the ANDROID_SDK_ROOT variable.

- Updates the framework's android studio's gradle plugin from version 3.3.0 to 3.5.3.
	Not only this is required for android's gradle to obey ANDROID_SDK_ROOT, it is now in sync with the Android test project/
- Updates the Androidx test project to use gralde plugin from version 3.3.0 to 3.5.3, to match Android Test & framework.
	- Consequentially, this required to also upgrade AndroidX test project to use Gradle 6.1, which also matches both the Android test project & framework

These changes above fixes apache#949

Additionally, since we update the environment variables dynamically, the environment variable printout produced misleading information.
The environment variable printout will now print out the variable as defined by the user (before the tooling messes with them). An additional log
is printed that tells the user exactly what Cordova is going to use for the Android SDK path. This should fix apache#670
breautek added a commit to breautek/cordova-android that referenced this issue Apr 15, 2020
This commit does the following:
- Makes ANDROID_SDK_ROOT the primary variable to look for the Android SDK location.
- Makes ANDROID_HOME the fallback variable, if ANDROID_SDK_ROOT is not present/valid.

Gradle updates:
Note that the following gradle updates were required, otherwise the android gradle plugin did not honour the ANDROID_SDK_ROOT variable.

- Updates the framework's android studio's gradle plugin from version 3.3.0 to 3.5.3.
	Not only this is required for android's gradle to obey ANDROID_SDK_ROOT, it is now in sync with the Android test project/
- Updates the Androidx test project to use gralde plugin from version 3.3.0 to 3.5.3, to match Android Test & framework.
	- Consequentially, this required to also upgrade AndroidX test project to use Gradle 6.1, which also matches both the Android test project & framework

These changes above fixes apache#949

Additionally, since we update the environment variables dynamically, the environment variable printout produced misleading information.
The environment variable printout will now print out the variable as defined by the user (before the tooling messes with them). An additional log
is printed that tells the user exactly what Cordova is going to use for the Android SDK path. This should fix apache#670
breautek added a commit to breautek/cordova-android that referenced this issue Apr 15, 2020
This commit does the following:
- Makes ANDROID_SDK_ROOT the primary variable to look for the Android SDK location.
- Makes ANDROID_HOME the fallback variable, if ANDROID_SDK_ROOT is not present/valid.

Gradle updates:
Note that the following gradle updates were required, otherwise the android gradle plugin did not honour the ANDROID_SDK_ROOT variable.

- Updates the framework's android studio's gradle plugin from version 3.3.0 to 3.5.3.
	Not only this is required for android's gradle to obey ANDROID_SDK_ROOT, it is now in sync with the Android test project/
- Updates the Androidx test project to use gralde plugin from version 3.3.0 to 3.5.3, to match Android Test & framework.
	- Consequentially, this required to also upgrade AndroidX test project to use Gradle 6.1, which also matches both the Android test project & framework

These changes above fixes apache#949

Additionally, since we update the environment variables dynamically, the environment variable printout produced misleading information.
The environment variable printout will now print out the variable as defined by the user (before the tooling messes with them). An additional log
is printed that tells the user exactly what Cordova is going to use for the Android SDK path. This should fix apache#670
breautek added a commit to breautek/cordova-android that referenced this issue Apr 16, 2020
This commit does the following:
- Makes ANDROID_SDK_ROOT the primary variable to look for the Android SDK location.
- Makes ANDROID_HOME the fallback variable, if ANDROID_SDK_ROOT is not present/valid.

Gradle updates:
Note that the following gradle updates were required, otherwise the android gradle plugin did not honour the ANDROID_SDK_ROOT variable.

- Updates the framework's android studio's gradle plugin from version 3.3.0 to 3.5.3.
	Not only this is required for android's gradle to obey ANDROID_SDK_ROOT, it is now in sync with the Android test project/
- Updates the Androidx test project to use gralde plugin from version 3.3.0 to 3.5.3, to match Android Test & framework.
	- Consequentially, this required to also upgrade AndroidX test project to use Gradle 6.1, which also matches both the Android test project & framework

These changes above fixes apache#949

Additionally, since we update the environment variables dynamically, the environment variable printout produced misleading information.
The environment variable printout will now print out the variable as defined by the user (before the tooling messes with them). An additional log
is printed that tells the user exactly what Cordova is going to use for the Android SDK path. This should fix apache#670
breautek added a commit that referenced this issue Apr 16, 2020
This commit does the following:
- Makes ANDROID_SDK_ROOT the primary variable to look for the Android SDK location.
- Makes ANDROID_HOME the fallback variable, if ANDROID_SDK_ROOT is not present/valid.

Gradle updates:
Note that the following gradle updates were required, otherwise the android gradle plugin did not honour the ANDROID_SDK_ROOT variable.

- Updates the framework's android studio's gradle plugin from version 3.3.0 to 3.5.3.
	Not only this is required for android's gradle to obey ANDROID_SDK_ROOT, it is now in sync with the Android test project/
- Updates the Androidx test project to use gralde plugin from version 3.3.0 to 3.5.3, to match Android Test & framework.
	- Consequentially, this required to also upgrade AndroidX test project to use Gradle 6.1, which also matches both the Android test project & framework

These changes above fixes #949

Additionally, since we update the environment variables dynamically, the environment variable printout produced misleading information.
The environment variable printout will now print out the variable as defined by the user (before the tooling messes with them). An additional log
is printed that tells the user exactly what Cordova is going to use for the Android SDK path. This should fix #670
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.