由于缺少android SDK,Jenkins构建失败

时间:2015-03-23 17:13:13

标签: android jenkins android-gradle

由于标题说我的jenkins构建因为没有找到android sdk dispite而失败,因此它位于环境路径中。

这是控制台日志

Started by user anonymous
Building in workspace /Users/lmnapp/.jenkins/jobs/Android_app_master/workspace
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url https://bitbucket.org/xxxxx-xxx/xxxx-android-app.git # timeout=10
Fetching upstream changes from https://bitbucket.org/xxxx-mob/xxxx-android-app.git
 > git --version # timeout=10
using .gitcredentials to set credentials
 > git config --local credential.helper store --file=/var/folders/gj/xxxxxxxx/T/xxxxx.credentials # timeout=10

+ export ANDROID_HOME=/Users/lmnapp/android-sdk-macosx
+ ANDROID_HOME=/Users/lmnapp/android-sdk-macosx
+ export ANDROID_SDK=/Users/lmnapp/android-sdk-macosx/platforms
+ ANDROID_SDK=/Users/lmnapp/android-sdk-macosx/platforms
+ export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/Users/lmnapp/android-sdk-macosx/tools:/Users/lmnapp/android-sdk-macosx/platform-tools:/Users/lmnapp/android-sdk-macosx
+ PATH=/usr/bin:/bin:/usr/sbin:/sbin:/Users/lmnapp/android-sdk-macosx/tools:/Users/lmnapp/android-sdk-macosx/platform-tools:/Users/lmnapp/android-sdk-macosx
+ export AVD_NAME=jenkinsGoogleApi18_1
+ AVD_NAME=jenkinsGoogleApi18_1
+ echo displayPath
displayPath
+ echo ....
....
+ echo ....
....
+ echo /usr/bin:/bin:/usr/sbin:/sbin:/Users/lmnapp/android-sdk-macosx/tools:/Users/lmnapp/android-sdk-macosx/platform-tools:/Users/lmnapp/android-sdk-macosx
/usr/bin:/bin:/usr/sbin:/sbin:/Users/lmnapp/android-sdk-macosx/tools:/Users/lmnapp/android-sdk-macosx/platform-tools:/Users/lmnapp/android-sdk-macosx
+ adb start-server
[Gradle] - Launching build.
[workspace] $ /Users/lmnapp/.jenkins/jobs/Android_app_master/workspace/gradlew assembleProductionRelease
Failed to notify ProjectEvaluationListener.afterEvaluate(), but primary configuration failure takes precedence.
java.lang.RuntimeException: SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.
    at com.android.build.gradle.internal.SdkHandler.getAndCheckSdkFolder(SdkHandler.java:103)
    at com.android.build.gradle.internal.SdkHandler.getSdkLoader(SdkHandler.java:113)
    at com.android.build.gradle.internal.SdkHandler.initTarget(SdkHandler.java:87)
    at com.android.build.gradle.BasePlugin.ensureTargetSetup(BasePlugin.groovy:467)
    at com.android.build.gradle.BasePlugin.access$0(BasePlugin.groovy)
    at com.android.build.gradle.BasePlugin$_createTasks_closure9.doCall(BasePlugin.groovy:372)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:324)
    at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:278)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1016)
    at groovy.lang.Closure.call(Closure.java:423)
    at org.gradle.listener.ClosureBackedMethodInvocationDispatch.dispatch(ClosureBackedMethodInvocationDispatch.java:40)
    at org.gradle.listener.ClosureBackedMethodInvocationDispatch.dispatch(ClosureBackedMethodInvocationDispatch.java:25)
    at org.gradle.listener.BroadcastDispatch.dispatch(BroadcastDispatch.java:83)
    at org.gradle.listener.BroadcastDispatch.dispatch(BroadcastDispatch.java:31)
    at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
    at com.sun.proxy.$Proxy12.afterEvaluate(Unknown Source)
    at org.gradle.configuration.project.LifecycleProjectEvaluator.notifyAfterEvaluate(LifecycleProjectEvaluator.java:79)
    at org.gradle.configuration.project.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:65)
    at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:504)
    at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:83)
    at org.gradle.execution.TaskPathProjectEvaluator.configureHierarchy(TaskPathProjectEvaluator.java:47)
    at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:35)
    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:129)
    at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:106)
    at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:86)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:80)
    at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33)
    at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:36)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
    at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:51)
    at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:171)
    at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:237)
    at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:210)
    at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:35)
    at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:24)
    at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:206)
    at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:169)
    at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
    at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
    at org.gradle.launcher.Main.doAction(Main.java:33)
    at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:54)
    at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:35)
    at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.gradle.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:30)
    at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:127)
    at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:55)

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/lmnapp/.jenkins/jobs/Android_app_master/workspace/project/build.gradle' line: 120

* What went wrong:
A problem occurred evaluating project ':project'.
> SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

正如你所看到的,路径显然已经正确设置了android_home。

我正试图通过jenkins的gradle建立这个。

这是我已经配置了这项工作的预先执行的shell命令

export ANDROID_HOME=/Users/lmnapp/android-sdk-macosx
export ANDROID_SDK=/Users/lmnapp/android-sdk-macosx/platforms
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$ANDROID_HOME
export AVD_NAME=jenkinsGoogleApi18_1

echo displayPath
echo ....
echo ....

echo $PATH

7 个答案:

答案 0 :(得分:59)

修正了它。

  1. 转到Jenkins>管理Jenkins>配置系统
  2. 检查“环境变量”
  3. 添加名称:ANDROID_HOME,值 - >你的android sdk dir
  4. 点击“添加”
  5. 滚动下来点击保存

答案 1 :(得分:6)

问题是您正在“执行shell”步骤中导出ANDROID_HOME环境变量。一旦shell步骤完成,该环境就消失了 - 变量将不会转移到后续构建步骤。

如果您在一个构建步骤中执行包括Gradle在内的所有内容,它将起作用,例如

export ANDROID_HOME=/foo/bar/sdk
./gradlew clean assembleProductionRelease

但是,由于您使用Gradle插件作为单独的构建步骤,因此环境变量不再可用。

在您自己的答案中通过Jenkins配置全局导出环境变量是解决此问题的一种方法,但您也可以在构建期间使用EnvInject plugin注入环境变量。使用此插件设置的变量将可用于所有构建步骤。


对于构建计算机,最佳做法是尽量减少所需的手动设置,例如将Android SDK和硬编码环境变量安装到服务器配置中。

我建议您将Android SDK Manager plugin添加到Gradle版本中 - 它会自动为您安装Android SDK以及任何构建依赖项。

答案 2 :(得分:1)

我使用以下方法修复了它:

  1. 复制您的Android文件夹\ Users {yourUser} \ Library \ Android \
  2. 粘贴到\ Users \ Shared \ Jenkins \ Library文件夹中
  3. 转到Jenkins->管理Jenkins->配置系统
  4. 检查“环境变量”
  5. 添加名称:ANDROID_HOME,值-> \ Users \ Shared \ Jenkins \ Library \ Android \ sdk
  6. 添加
  7. 保存

答案 3 :(得分:0)

您可以使用EnvInject插件在构建配置中添加ANDROID_HOME环境变量。

  1. 如果尚未安装EnvInject插件(通常是在Jenkins配置之后完成的),请安装它。

  2. 转到Jenkins->您的构建->配置。

  3. 向下滚动到构建环境。

  4. 找到“将环境变量注入到构建过程中”并进行检查。

  5. 在“属性内容”输入字段中输入“ ANDROID_HOME = / you / Android / Sdk /位置”。

  6. 别忘了保存它。

答案 4 :(得分:0)

我通过向您的android sdk目录添加权限来解决此问题

chmod 777 / Users / USER_NAME / Library / Android

答案 5 :(得分:0)

@Jonathan最正确,只需添加一个提示,您的SDK路径应放在Jenkins允许的位置。
将sdk放在/ root / sdk下时我被卡住了,在这种情况下,即使我设置了ANDROID_HOME,它仍然无法正常工作
在将SDK移至/ usr / local / sdk后,它可以正常工作

答案 6 :(得分:-1)

我想你在local.properties文件中检查了包含本地机器SDK文件路径的版本控制(在设置项目或打开项目时自动完成)。将local.properties文件更改为默认的SDK路径(以便它将根据本地计算机自动处理更改):

sdk.dir=/Applications/android_sdk

检查更改为版本控制,然后将local.properties放入.gitignore文件(see here for help)。