Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins build failed due to missing android SDK

As the title says my jenkins build fails due to not finding the android sdk dispite it being located in the environments path.

Here is the console logs

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 

As u can see, the path clearly has android_home set correctly.

I am trying to build this via gradle in jenkins.

This is teh pre executed shell commands i have configured this job to do

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 
like image 708
Jonathan Avatar asked Mar 23 '15 17:03

Jonathan


2 Answers

Fixed it.

  1. Go to Jenkins > Manage Jenkins > Configure System
  2. Check "Environment variables"
  3. add name: ANDROID_HOME, value -> your android sdk dir
  4. click "add"
  5. SCROLL DOWN CLICK SAVE
like image 118
Jonathan Avatar answered Oct 04 '22 06:10

Jonathan


The problem is that you are exporting the ANDROID_HOME environment variable in an "Execute shell" step. Once the shell step has completed, that environment is gone — the variables will not be carried over to subsequent build steps.

If you were executing everything, including Gradle, in a single build step, it would work, e.g.

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

But since you're using the Gradle plugin as a separate build step, the environment variables are no longer available.

Exporting the environment variable globally via the Jenkins config as you have done in your own answer is one way to solve this, though you can also use the EnvInject plugin to inject environment variables during a build. Variables set up using this plugin will be available to all build steps.


For a build machine, the best practice would be to minimise the amount of manual setup required, like installing the Android SDK and hardcoding environment variables into the server config.

I can recommend adding the Android SDK Manager plugin to your Gradle build — it will automatically install the Android SDK plus any build dependencies for you.

like image 28
Christopher Orr Avatar answered Oct 04 '22 04:10

Christopher Orr