I'm trying to set up my first Android project to build on Jenkins.
我正在尝试建立我的第一个Android项目来构建Jenkins。
I'm running Jenkins 1.6.2 with version 1.24 of the Gradle plugin. Running on Windows 7 Professional SP1.
我正在使用Gradle插件的1.24版本运行Jenkins 1.6.2。在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.
我已经在我的构建机器上安装了Android Studio和Java7 JDK,并且通过Android Studio或从命令行运行gradlew.bat时,该软件的检出版本构建得很好。但我无法在Jenkins工作中使Invoke Gradle脚本构建任务正常工作。
There is a pair of radio buttons, on the configure project page:
配置项目页面上有一对单选按钮:
- Invoke Gradle
- Use Gradle Wrapper
使用Gradle Wrapper
If I select "Invoke Gradle", I'm asked to select a "Gradle Version", which is something I setup in Configure System.
如果我选择“Invoke Gradle”,我会被要求选择“Gradle Version”,这是我在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...."
我创建了一个gradle安装,GRADLE_HOME设置为“D:\ Program Files \ Android Studio \ gradle \ gradle-2.2.1”。这给了我一个警告:“D:\ Program Files \ Android Studio \ gradle \ gradle-2.2.1不是Jenkins主人的目录....”
And when I run a build, I get an error "Can't retrieve the Gradle executable".
当我运行构建时,我收到错误“无法检索Gradle可执行文件”。
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.
这可能与抱怨该目录的gradle插件有关。但目录是正确的。我用'/'代替'\'尝试了它,它没有任何区别。
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!"
由于那不起作用,我尝试了另一种选择,“使用Gradle Wrapper”。有一个复选框:“From Root Build Script Dir”。无论我是否检查它,我得到“java.lang.IllegalArgumentException:android.compileSdkVersion is missing!”
I've set both JAVA_HOME and ANDROID_HOME, so that's not the issue.
我已经设置了JAVA_HOME和ANDROID_HOME,所以这不是问题。
Any ideas?
As a followup, I delete the gradle task, and added an Execute Windows batch command task:
作为后续,我删除了gradle任务,并添加了一个Execute Windows批处理命令任务:
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.
从Jenkins运行gradlew.bat时,与从命令行运行它时有什么不同?当我从命令行运行时,Jenkins服务被配置为使用与我登录时相同的用户。我已经尝试显式设置我在命令行中设置的每个环境变量,在Jenkins任务中,我仍然看到错误。
Any ideas?
4 个解决方案
#1
Your local.properties file must contain: sdk.dir="path to your android sdk"
您的local.properties文件必须包含:sdk.dir =“android sdk的路径”
#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.
我也使用jenkins来构建我的应用程序并遇到了类似的问题。我通过jenkins执行gradle包装器而不使用jenkins gradle插件来修复它。
cd $WORKSPACE
./gradlew assembleRelease
And if you want lint add a second shell exec with
如果你想要lint添加第二个shell exec
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)
请注意,这些命令适用于Linux系统,但它们可以在Windows上正常工作(前一段时间有一个Windows构建服务器并执行相同的操作)
#3
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:
我的情况如下,在我的项目build.gradle文件中:
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:
当我运行:gradle clean build,错误消息显示:
* 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!:
我的解决方案是将此脚本的位置应用于:'maven_push.gradle'到build.gradle文件的底部,并且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.
我认为你应该注意错误命令行中的“Where”消息。
#4
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.
我不能确定它会解决你的问题,但也许你可以考虑使用直接从gradle下载和安装android sdk的sdk-manager-plugin。
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.
如果它有效,它可能不会告诉你为什么你当前的配置不起作用,但至少你不会再被卡住了。
#1
Your local.properties file must contain: sdk.dir="path to your android sdk"
您的local.properties文件必须包含:sdk.dir =“android sdk的路径”
#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.
我也使用jenkins来构建我的应用程序并遇到了类似的问题。我通过jenkins执行gradle包装器而不使用jenkins gradle插件来修复它。
cd $WORKSPACE
./gradlew assembleRelease
And if you want lint add a second shell exec with
如果你想要lint添加第二个shell exec
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)
请注意,这些命令适用于Linux系统,但它们可以在Windows上正常工作(前一段时间有一个Windows构建服务器并执行相同的操作)
#3
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:
我的情况如下,在我的项目build.gradle文件中:
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:
当我运行:gradle clean build,错误消息显示:
* 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!:
我的解决方案是将此脚本的位置应用于:'maven_push.gradle'到build.gradle文件的底部,并且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.
我认为你应该注意错误命令行中的“Where”消息。
#4
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.
我不能确定它会解决你的问题,但也许你可以考虑使用直接从gradle下载和安装android sdk的sdk-manager-plugin。
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.
如果它有效,它可能不会告诉你为什么你当前的配置不起作用,但至少你不会再被卡住了。