Setting ANDROID_HOME environment variable has no effect
Description of the problem / feature request:
Setting ANDROID_HOME environment variable has no effect. I get the error:
No such package '@androidsdk//': Either the path attribute of android_sdk_repository or the ANDROID_HOME environment variable must be set.
It does work when I set path to that path.
Feature requests: what underlying problem are you trying to solve with this feature?
Setting the Android SDK to a local directory.
Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
Make sure ANDROID_HOME is unset, but it might still work for you and not for me.. I've compiled 0.13.0 and ran it with the following prints: https://github.com/bazelbuild/bazel/commit/708728379f21ef46b6d06f901e243cb1fe6d3649 I looked around to see where the environment variable is coming from, but got a little lost. I could add more prints if you tell me where you want them.
What operating system are you running Bazel on?
Linux
What's the output of bazel info release?
release 0.13.0
(the version I compiled for the prints says development version, but the error happened on both).
Replace this line with your answer.
If bazel info release returns "development version" or "(@non-git)", tell us how you built Bazel.
Using the 0.13.0 source zip download from here: https://github.com/bazelbuild/bazel/releases/tag/0.13.0
What's the output of git remote get-url origin ; git rev-parse master ; git rev-parse HEAD ?
fatal: not a git repository (or any of the parent directories): .git
Have you found anything relevant by searching the web?
Nope
Any other information, logs, or outputs that you want to share?
Nope
What happens if you try $ ANDROID_HOME=/absolute/path/to/sdk bazel build :android_target?
oferd@ do you mind share your WORKSPACE? I have used this configuration for a while, and 0.13 seems to work fine in my project though.
@jin Your suggestion works!
@zhongleiwang This is my repo: https://github.com/google/startup-os
I tried from head (currently at db2373f5ab25a5ad5c54fd30f44f0fcadc3380f1)
I'd add, that for the same repo and build target, it's working on a mac.
How were you setting ANDROID_HOME?
Note that doing ANDROID_HOME="..." will make the variable available in your shell, but not available to bazel. Doing export ANDROID_HOME="..." will make it available also to bazel.
Adding export did the trick.
I see it is mentioned in the docs:
https://docs.bazel.build/versions/master/tutorial/android-app.html#install-android-studio
but I just looked at the error message and didn't think of export.
I guess adding a reminder it in the error message would do the trick.
Yeah, a hint in the error message might be helpful, but that's tricky because as far as I know it's a bash specific thing.
Well, the docs give the export example, so why not in the error as well?
Now I know why I got confused - it doesn't mention you need to export here:
https://docs.bazel.build/versions/master/be/android.html#android_sdk_repository
... and set the $ANDROID_HOME environment variable to the path of your Android SDK
I know it might be too late. Just hope it can help the others in future. I got this error when sync one project imported from Github. I am using Android Studio. This is the first time I build by using bazel. Following the hint of that error, I set up the environment variable ANDROID_HOME and validate it in both Linux terminal and the embedded terminal in Android Studio. The ANDROID_HOME did be set, but the error is still there. I finally resolved it by restarting the Android Studio in the command line. I suspect the plugin cannot pass ANDROID_HOME TO bazel since the environment variable was set after the IDE has been launched.