6

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?

genpfault
  • 51,148
  • 11
  • 85
  • 139
  • Refer this : https://github.com/codepath/android_guides/wiki/Building-Gradle-Projects-with-Jenkins-CI#install-the-android-sdk – Archis Thakkar Dec 18 '17 at 09:49
  • Checking the provided link it still points to a step to install the Android SDK on the Jenkins slave. My point, is that I am not able to easily do that. – FelipeFraga Dec 19 '17 at 13:10

2 Answers2

3

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

cstarner
  • 377
  • 3
  • 14
  • 1
    I’m sorry, but I think you misunderstood me. The whole point is that I am not easily able to change the Jenkins Slave, so there is no Android SDK home in it. – FelipeFraga Dec 19 '17 at 13:08
  • 1
    I apologize, I did misread the question You should be able to set the Android SDK Home via environmental variable. You could make it in a subdirectory of the build directory, set the ANDROID_SDK_HOME environmental variable to point to that subdirectory, and move the licenses folder there. – cstarner Dec 19 '17 at 16:07
1

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.

MatPag
  • 41,742
  • 14
  • 105
  • 114