简体   繁体   中英

Building Android Studio project on Jenkins? android.compileSdkVersion is missing

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?

您的local.properties文件必须包含:sdk.dir =“android sdk的路径”

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)

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM