Jenkins build failed due to missing android SDK
The problem is that you are exporting the ANDROID_HOME
environment variable in an "Execute shell" step. Once the shell step has completed, that environment is gone — the variables will not be carried over to subsequent build steps.
If you were executing everything, including Gradle, in a single build step, it would work, e.g.
export ANDROID_HOME=/foo/bar/sdk
./gradlew clean assembleProductionRelease
But since you're using the Gradle plugin as a separate build step, the environment variables are no longer available.
Exporting the environment variable globally via the Jenkins config as you have done in your own answer is one way to solve this, though you can also use the EnvInject plugin to inject environment variables during a build. Variables set up using this plugin will be available to all build steps.
For a build machine, the best practice would be to minimise the amount of manual setup required, like installing the Android SDK and hardcoding environment variables into the server config.
I can recommend adding the Android SDK Manager plugin to your Gradle build — it will automatically install the Android SDK plus any build dependencies for you.
Fixed it.
- Go to Jenkins > Manage Jenkins > Configure System
- Check "Environment variables"
- add name: ANDROID_HOME, value -> your android sdk dir
- click "add"
- SCROLL DOWN CLICK SAVE
I fixed it using:
- Copy your Android folder \Users{yourUser}\Library\Android\
- Paste in the folder \Users\Shared\Jenkins\Library
- Go to Jenkins -> Manage Jenkins -> Configure System
- Check "Environment variables"
- add name: ANDROID_HOME, value -> \Users\Shared\Jenkins\Library\Android\sdk
- Add
- Save