13

I'm trying to set up my first Android project to build on Jenkins.

I'm running Jenkins 1.6.2 with version 1.24 of the Gradle plugin. Running on Windows 7 Professional SP1.

I've installed Android Studio and the Java7 JDK on my build machine, and a checked-out version of the software builds just fine, through Android Studio or when running gradlew.bat from the command line. But I can't get the Invoke Gradle script build task to work, within my Jenkins job.

There is a pair of radio buttons, on the configure project page:

  • Invoke Gradle
  • Use Gradle Wrapper

If I select "Invoke Gradle", I'm asked to select a "Gradle Version", which is something I setup in Configure System.

I created a gradle installation with GRADLE_HOME set to "D:\Program Files\Android Studio\gradle\gradle-2.2.1". That gives me a warning that "D:\Program Files\Android Studio\gradle\gradle-2.2.1 is not a directory on the Jenkins master...."

And when I run a build, I get an error "Can't retrieve the Gradle executable".

Which is probably related to the gradle plugin complaining about the directory. But the directory is correct. I've tried it with '/' instead of '\', and it made no difference.

Since that didn't work, I tried the alternative, "Use Gradle Wrapper". There's a checkbox: "From Root Build Script Dir". Whether I check it, or not, I get "java.lang.IllegalArgumentException: android.compileSdkVersion is missing!"

I've set both JAVA_HOME and ANDROID_HOME, so that's not the issue.

Any ideas?

As a followup, I delete the gradle task, and added an Execute Windows batch command task:

SET ANDROID_HOME=d:\Program Files\Android\sdk SET JAVA_HOME=d:\Program Files\Java\jdk1.7.0_79 .\gradlew.bat clean 

When I run that, I still get that error.

But when I run those commands from a command line on the build machine, they work just fine.

What could be different, when running gradlew.bat from Jenkins, than when running it from the command line? The Jenkins service is configured to use the same user as I'm logged in as, when I'm running from the command line. I've tried explicitly setting each and every environment variable I have set in the command line, in the Jenkins task, and I'm still seeing the error.

Any ideas?

10
  • I will recommend not to use wrapper. The warning will probably be the issue. Did you already tried to install gradle automatically by Jenkins? (gradle version in the job-config may just be 'default'.) Commented May 5, 2015 at 6:54
  • I'm trying to use the gradle that was installed as a part of Android Studio. And as I said, the gradle version I specified in the job-config is the one I created pointing at the gradle installed as a part of Android Studio. Commented May 5, 2015 at 14:18
  • I've tried auto-installing Gradle, and in the Gradle Installations config, the version dropdown is empty Commented May 5, 2015 at 15:46
  • Do you have a compileSdkVersion set in your build.gradle? That is what the Gradle wrapper is complaining about. Commented May 6, 2015 at 18:14
  • Yes. And when I run gradle from the command-line, it can find it. But when I run it from Jenkins, it can't. Commented May 6, 2015 at 19:04

4 Answers 4

4
+50

Your local.properties file must contain: sdk.dir="path to your android sdk"

Sign up to request clarification or add additional context in comments.

1 Comment

My local.properties file is the same, when run from the command-line as when run from Jenkins.
2

I'm also using jenkins for building my apps and had a similar problem. I fixed it by executing the gradle wrapper via jenkins without using the jenkins gradle plugin.

cd $WORKSPACE ./gradlew assembleRelease 

And if you want lint add a second shell exec with

cd $WORKSPACE ./gradlew lint 

Note that these commands are for a linux system but they will work just fine on windows (had a windows build server some time ago and did the same thing)

Comments

1

I met this problem too, but I don't know whether my solution suit for you.

My situation is below, in my project build.gradle file:

apply plugin: 'com.android.library' apply from: 'maven_push.gradle' dependencies { ...... } android { compileSdkVersion 19 buildToolsVersion "21.1.0" ...... } 

When i run: gradle clean build, error message show:

* Where: Script 'C:\xxxxxx\Project\maven_push.gradle' line: 32 * What went wrong: A problem occurred evaluating script. > android.compileSdkVersion is missing! 

My solution is change the position of this script apply from: 'maven_push.gradle' to the bottom in build.gradle file, and BUILD SUCCESSFUL!:

apply plugin: 'com.android.library' dependencies { ...... } android { compileSdkVersion 19 buildToolsVersion "21.1.0" ...... } apply from: 'maven_push.gradle' 

I think you should pay attention to the "Where" message in the error command line.

Comments

1

I can't be sure it's gonna solve your issue, but maybe you can consider using the sdk-manager-plugin which downloads and installs the android sdk directly from gradle.

If it works, it probably won't tell you why your current configuration is not working, but at least you won't be stuck anymore.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.