apache / cordova-android

Apache Cordova Android
https://cordova.apache.org/
Apache License 2.0
3.59k stars 1.52k forks source link

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

Closed janpio closed 4 years ago

janpio commented 5 years ago

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?

brodybits commented 5 years ago

(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: https://github.com/apache/cordova-android/blob/b4de6f55c4d7ad87a72f852d2b98dc9baf351731/bin/templates/cordova/lib/check_reqs.js#L225-L230

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 commented 5 years ago

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.)

brodybits commented 5 years ago

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 commented 5 years ago

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 commented 4 years ago

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

basurahan commented 4 years ago

Please fix the issue

basurahan commented 4 years ago

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 commented 4 years ago

Definitely not in an unrelated, old issue.

uvconnects commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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

breautek commented 4 years ago

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 commented 4 years ago

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

gazsmith10 commented 4 years ago

Same issue

luccadumas commented 4 years ago

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

vignesh-d commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

In Windows is not generating the build of the app

cordova platform list Installed platforms: android 8.0.0 Available platforms: browser ^6.0.0 electron ^1.0.0 ios ^5.0.0 osx ^5.0.0 windows ^7.0.0

The error message

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

luccadumas commented 4 years ago

Man, stop marking my message as spam ... I can not build on Windows, is giving this error when I do "ionic cordova build android --release"

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

phiferd commented 4 years ago

@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 (https://github.com/apache/cordova-android/issues/670#issuecomment-481936559) 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 commented 4 years ago

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 commented 4 years ago

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

PMMRanger commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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}
brodybits commented 4 years ago

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/

75341704 commented 4 years ago

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 commented 4 years ago

@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 commented 4 years ago

@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 commented 4 years ago

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 commented 4 years ago

@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.