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.

  1. Go to Jenkins > Manage Jenkins > Configure System
  2. Check "Environment variables"
  3. add name: ANDROID_HOME, value -> your android sdk dir
  4. click "add"
  5. SCROLL DOWN CLICK SAVE

I fixed it using:

  1. Copy your Android folder \Users{yourUser}\Library\Android\
  2. Paste in the folder \Users\Shared\Jenkins\Library
  3. Go to Jenkins -> Manage Jenkins -> Configure System
  4. Check "Environment variables"
  5. add name: ANDROID_HOME, value -> \Users\Shared\Jenkins\Library\Android\sdk
  6. Add
  7. Save