FelipeFraga
FelipeFraga

Reputation: 91

Android SDK Download as Part of Gradle Build

I am trying build an Android app with Jenkins and I have little control over Jenkins' slave machines.

In order to build the app I need the Android SDK installed on the slave, otherwise I get as expected:

"SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable."

That being the case, can gradle be configured to download the SDK as part of the build process and use it as a normal dependency?

Does this even make sense?

Upvotes: 6

Views: 2368

Answers (2)

Harikumar Alangode
Harikumar Alangode

Reputation: 561

Yes it is possible. Check out this gradle plugin which automates SDK download

Add the plugin to your root level gradle

classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.12.+'

Apply the plugin in your build.gradle before the regular 'android' plugin:

apply plugin: 'android-sdk-manager'
apply plugin: 'com.android.application'

Note: this plugin is no longer under active development.

Upvotes: 1

cstarner
cstarner

Reputation: 387

The Gradle Android plugin supports automatic downloading of missing dependencies at build time; the trick is that accepted license agreements pertaining to the Android SDK must be bundled with the project to be built.

You basically just copy over the accepted license agreements from one spot where they have been accepted through Android Studio (your dev workstation probably), and ensure that they are copied as in to the Android SDK Home Directory on the Jenkins slave.

The files can be found in a license/ folder in the Android SDK folder, although the official documentation refers to the directory as licenses/.

Upvotes: 3

Related Questions