I am trying to build an apk via jenkins for my android application. I followed this tutorial to do this.The issue I have is my Android sdk is installed in a separate hard disk (Not the one where jenkins is installed).
So the path I set for the sdk in the environment variable is not identified by jenkins & the build fails. But I can build an apk normally using Android studio with the same sdk path.
P.S Android studio is installed in the same hard where jenkins is installed. I referred to this solution but still no luck. Also I cannot move the sdk to the disk where I have installed jenkins because of a disk space issue. Please can any one help me on this ?
Please refer to the console log in Jenkins
16:52:08 Started by user Darrel Rayen
16:52:08 Building in workspace /var/lib/jenkins/workspace/android-
recruiter-app
16:52:08 > git rev-parse --is-inside-work-tree # timeout=10
16:52:08 Fetching changes from the remote Git repository
16:52:08 > git config remote.origin.url
https://DarrelR#bitbucket.org/harver/android-recruiter-app.git #
timeout=10
16:52:08 Fetching upstream changes from
https://DarrelR#bitbucket.org/harver/android-recruiter-app.git
16:52:08 > git --version # timeout=10
16:52:08 using GIT_ASKPASS to set credentials
16:52:08 > git fetch --tags --progress
https://DarrelR#bitbucket.org/harver/android-recruiter-app.git
+refs/heads/*:refs/remotes/origin/*
16:52:12 > git rev-parse refs/remotes/origin/master^{commit} #
timeout=10
16:52:12 > git rev-parse refs/remotes/origin/origin/master^{commit} #
timeout=10
16:52:12 Checking out Revision
1609ea0ced1febf6a6cbb8bbd9488637c2c70e1a (refs/remotes/origin/master)
16:52:12 > git config core.sparsecheckout # timeout=10
16:52:12 > git checkout -f 1609ea0ced1febf6a6cbb8bbd9488637c2c70e1a
16:52:12 Commit message: "Merged in AMOB-264-end-to-end-testing-for-
the-cand (pull request #57)"
16:52:12 > git rev-list --no-walk
1609ea0ced1febf6a6cbb8bbd9488637c2c70e1a # timeout=10
16:52:12 [Gradle] - Launching build.
16:52:12 [android-recruiter-app] $ /var/lib/jenkins/workspace/android-
recruiter-app/gradlew clean assembleDebug test connectedAndroidTest
16:52:12 Starting a Gradle Daemon (subsequent builds will be faster)
16:52:16
16:52:16 FAILURE: Build failed with an exception.
16:52:16
16:52:16 * What went wrong:
16:52:16 A problem occurred configuring project ':app'.
16:52:16 > The SDK directory '/media/darrel/NewDisk' does not exist.
16:52:16
16:52:16 * Try:
16:52:16 Run with --stacktrace option to get the stack trace. Run with
--info or --debug option to get more log output. Run with --scan to
get full insights.
16:52:16
16:52:16 * Get more help at https://help.gradle.org
16:52:16
16:52:16 BUILD FAILED in 4s
16:52:16 Build step 'Invoke Gradle script' changed build result to
FAILURE
16:52:16 Build step 'Invoke Gradle script' marked build as failure
16:52:17 Finished: FAILURE
I found a solution for my problem from this. I had to update the access permission for the user to access the mounted drive using the below steps
1.Unmount the mounted device (/dev/sdb is the hard disk detected name)
umount /dev/sdb
chmod -R 0777 /mnt/
2.Finally mount the hard
mount /dev/sdb /mnt
3.Then I gave the sdk path as /mnt/Android/Sdk
Related
I am attempting to deploy a React Native Android application using CircleCI.
Here is the job
android_deploy_staging:
docker:
- image: cimg/android:2021.12.2-node
environment:
JAVA_OPTS: '-Xms512m -Xmx2g'
GRADLE_OPTS: '-Xmx3g -Dorg.gradle.daemon=false -Dorg.gradle.jvmargs="-Xmx2g -XX:+HeapDumpOnOutOfMemoryError"'
steps:
- checkout
- *fetchDeployKeys
- run: git config --global url."https://qadrebot:$GITHUB_TOKEN#github.com".insteadOf "https://github.com"
- run: *set_node_version
- restore_cache: *restore_npm_cache
- run: *install_npm_dependencies
- save_cache: *save_npm_cache
- restore_cache:
key: 4-gems-{{ checksum "android/Gemfile.lock" }}
- run: cd android; bundle check || bundle install --path vendor/bundle --clean
- save_cache:
key: 4-gems-{{ checksum "android/Gemfile.lock" }}
paths:
- vendor/bundle
- run:
name: Install Fastlane
command: sudo gem install fastlane
- run:
name: bundle install
command: cd android && bundle install
- run:
environment:
ANDROID_SDK_ROOT: '/home/circleci/android-sdk'
name: Prepare environment and compile beta
no_output_timeout: 30m
command: |
echo Executing fastlane
yarn deploy_staging:android
However I get an error about the SDK location not being found.
[12:36:31]: -------------------
[12:36:31]: --- Step: clean ---
[12:36:31]: -------------------
[12:36:31]: $ /home/circleci/project/android/gradlew clean -p .
[12:36:31]: ▸ Downloading https://services.gradle.org/distributions/gradle-6.4-all.zip
[12:36:32]: ▸ .............10%..............20%..............30%..............40%..............50%..............60%..............70%..............80%..............90%.............100%
[12:36:34]: ▸ Welcome to Gradle 6.4!
[12:36:34]: ▸ Here are the highlights of this release:
[12:36:34]: ▸ - Support for building, testing and running Java Modules
[12:36:34]: ▸ - Precompiled script plugins for Groovy DSL
[12:36:34]: ▸ - Single dependency lock file per project
[12:36:34]: ▸ For more details see https://docs.gradle.org/6.4/release-notes.html
[12:36:35]: ▸ Starting a Gradle Daemon (subsequent builds will be faster)
[12:36:49]: ▸ > Configure project :app
[12:36:49]: ▸ Reading env from: ./app/services/config/.env.staging
[12:36:49]: ▸ WARNING: DSL element 'DexOptions.incremental' is obsolete.
[12:36:49]: ▸ It will be removed in version 5.0 of the Android Gradle plugin.
[12:36:49]: ▸ WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
[12:36:49]: ▸ It will be removed in version 5.0 of the Android Gradle plugin.
[12:36:49]: ▸ For more information, see http://d.android.com/r/tools/update-dependency-configurations.html.
[12:36:51]: ▸ FAILURE: Build failed with an exception.
[12:36:51]: ▸ * What went wrong:
[12:36:51]: ▸ A problem occurred configuring project ':app'.
[12:36:51]: ▸ > Could not create task ':app:lintDebug'.
[12:36:51]: ▸ > SDK location not found. Define location with an ANDROID_SDK_ROOT environment variable or by setting the sdk.dir path in your project's local properties file at '/home/circleci/project/android/local.properties'.
[12:36:51]: ▸ * Try:
[12:36:51]: ▸ Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
[12:36:51]: ▸ * Get more help at https://help.gradle.org
[12:36:51]: ▸ BUILD FAILED in 20s
On the CircleCi website it states
This image contains the Android SDK and CLI tools.
But it looks like maybe the Android SDK isn't installed?
Has anyone come across this before?
You can check cimg-android docker template code.
# Install Android SDK Tools
ENV ANDROID_HOME "/home/circleci/android-sdk"
ENV ANDROID_SDK_ROOT $ANDROID_HOME
You don't need to set $ANDROID_SDK_ROOT yourself.
Instead, the sdk path can be refered with $ANDROID_SDK_ROOT
- run:
name: 'Build Android App'
command: |
export ANDROID_SDK_ROOT='/home/circleci/android-sdk'
export JAVA_HOME='/usr/lib/jvm/java-8-openjdk-amd64'
npm run build:android
I am trying to build an android app using a yaml pipeline. The gradle build task is complaining that it can't find the android sdk root. I've tried both the local.properties file and the environmental variable ANDROID_SDK_ROOT, and neither work. This is my build pipeline:
# Android
# Build your Android project with Gradle.
# Add steps that test, sign, and distribute the APK, save build artifacts, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/android
trigger:
- master
- dev
pool:
name: 'Default'
steps:
- task: UseDotNet#2
inputs:
version: '2.2.x'
packageType: runtime
- task: GitVersion#5
displayName: GitVersion
inputs:
useConfigFile: true
configFilePath: GitVersion.yml
# trying to set the env variable doesn't work.
# - task: PowerShell#2
# inputs:
# targetType: 'inline'
# script: |
# # Write your PowerShell commands here.
# [Environment]::SetEnvironmentVariable("ANDROID_SDK_ROOT", "C:\Users\Administrator\AppData\Local\Android\Sdk", "User")
- task: file-creator#6
inputs:
filepath: '$(System.DefaultWorkingDirectory)/local.properties'
filecontent: 'sdk.dir=C:/Users/Administrator/AppData/Local/Android/Sdk'
fileoverwrite: true
# trying to execute gradlew manually does not work
# - task: CmdLine#2
# inputs:
# script: |
# gradlew.bat assembleDebug
# workingDirectory: '$(System.DefaultWorkingDirectory)'
- task: Gradle#2
inputs:
workingDirectory: '$(System.DefaultWorkingDirectory)'
gradleWrapperFile: 'gradlew'
gradleOptions: '-Xmx3072m'
publishJUnitResults: false
testResultsFiles: '**/TEST-*.xml'
tasks: 'assembleDebug'
This is the output:
Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/build/gradle
==============================================================================
SYSTEMVSSCONNECTION exists true
C:\Windows\system32\cmd.exe /D /S /C "C:\VSTS\_work\8\s\gradlew.bat -p C:\VSTS\_work\8\s assembleDebug"
Starting a Gradle Daemon, 1 incompatible and 4 stopped Daemons could not be reused, use --status for details
> Configure project :app
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> SDK location not found. Define location with an ANDROID_SDK_ROOT environment variable or by setting the sdk.dir path in your project's local properties file at 'C:\VSTS\_work\8\s\local.properties'.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 16s
Error: The process 'C:\VSTS\_work\8\s\gradlew.bat' failed with exit code 1
at ExecState._setResult (C:\VSTS\_work\_tasks\Gradle_8d8eebd8-2b94-4c97-85af-839254cc6da4\2.176.0\node_modules\azure-pipelines-task-lib\toolrunner.js:816:25)
at ExecState.CheckComplete (C:\VSTS\_work\_tasks\Gradle_8d8eebd8-2b94-4c97-85af-839254cc6da4\2.176.0\node_modules\azure-pipelines-task-lib\toolrunner.js:799:18)
at ChildProcess.<anonymous> (C:\VSTS\_work\_tasks\Gradle_8d8eebd8-2b94-4c97-85af-839254cc6da4\2.176.0\node_modules\azure-pipelines-task-lib\toolrunner.js:721:19)
at emitTwo (events.js:106:13)
at ChildProcess.emit (events.js:191:7)
at maybeClose (internal/child_process.js:920:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:230:5)
##[error]Error: The process 'C:\VSTS\_work\8\s\gradlew.bat' failed with exit code 1
Finishing: Gradle
If I rdp into the build agent and run gradlew manually with the generated local.properties file present from the command line the build DOES succeed though, so I'm not sure what the issue with running it in a pipeline is.
You can set environmental variables in azure pipeline by defining it in the Variables section. You can add below to your yaml pipeline.
variables:
ANDROID_SDK_ROOT: 'C:\Users\Administrator\AppData\Local\Android\Sdk'
You can also set the environmental variable ANDROID_SDK_ROOT using the task.setvariable logging command in the scripts. For below example.
steps:
- powershell: echo "##vso[task.setvariable variable=ANDROID_SDK_ROOT]C:\Users\Administrator\AppData\Local\Android\Sdk"
I figured out the issue. I installed the android sdk on the administrator account, but devops created a separate windows user for builds. Installing the android sdk for that user fixed my build.
Options mentioned in similar questions didn't help for me. That's why I'm creating question.
When trying to build project on CircleCi I get the following error:
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> 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. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 17s
Exited with code 1
I've tried to take configuration file from here: https://circleci.com/docs/2.0/language-android/
I've also tried to use default configuration file, when building a project.
I've set ANDROID Home variable, I've checked local.properties file. Everything is correct.
Can anybody help?
My config.yml file:
version: 2
jobs:
build:
working_directory: ~/code
docker:
- image: circleci/android:api-25-alpha
environment:
JVM_OPTS: -Xmx3200m
steps:
- checkout
- restore_cache:
key: jars-{{ checksum "build.gradle" }}-{{ checksum "app/build.gradle" }}
- run:
name: Chmod permissions #if permission for Gradlew Dependencies fail, use this.
command: sudo chmod +x ./gradlew
- run:
name: Download Dependencies
command: ./gradlew androidDependencies
- save_cache:
paths:
- ~/.gradle
key: jars-{{ checksum "build.gradle" }}-{{ checksum "app/build.gradle" }}
- run:
name: Run Tests
command: ./gradlew lint test
- store_artifacts:
path: app/build/reports
destination: reports
- store_test_results:
path: app/build/test-results
go to app directory -> go to android directory -> create a file named local.properties
then add :
sdk.dir = /home/user-name/Android/Sdk
NOTE: replace sdk address with your's
I have use jenkins with docker
after pull and install the following plugin
Git Plugin
Gradle Plugin
Android Lint Plugin
Google Play Android Publisher Plugin
THEN setup JDK, Repository (GitLab)
AND create project and run, it's show the following error.
RUN COMMAND
docker run -p 8080:8080 -v /Users/abc/Library/Android/sdk:/var/android_home -p 50000:50000 -v jenkins_home:/var/jenkins_home jenkins/jenkins:lts
JENKINS CONSOLE OUTPUT
Building in workspace /var/jenkins_home/workspace/ABC Project
> git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git config remote.origin.url http://office.viinsoft.com/issoft/mappening-android.git # timeout=10
Fetching upstream changes from http://office.viinsoft.com/issoft/mappening-android.git
> git --version # timeout=10
using GIT_ASKPASS to set credentials
> git fetch --tags --progress http://office.viinsoft.com/issoft/mappening-android.git +refs/heads/*:refs/remotes/origin/*
> git rev-parse refs/remotes/origin/master^{commit} # timeout=10
> git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision 7a760b63852e92c57e5b4dea5bdf6680b01d8894 (refs/remotes/origin/master)
> git config core.sparsecheckout # timeout=10
> git checkout -f 7a760b63852e92c57e5b4dea5bdf6680b01d8894
Commit message: "Test Jenkins#2"
> git rev-list --no-walk 7a760b63852e92c57e5b4dea5bdf6680b01d8894 # timeout=10
[Gradle] - Launching build.
[Mappening Project] $ "/var/jenkins_home/workspace/Mappening Project/gradlew" assembleDebug
Starting a Gradle Daemon (subsequent builds will be faster)
Configuration 'testCompile' in project ':app' is deprecated. Use 'testImplementation' instead.
Configuration 'androidTestCompile' in project ':app' is deprecated. Use 'androidTestImplementation' instead.
:app:preBuild UP-TO-DATE
:app:preDevDebugBuild UP-TO-DATE
:app:compileDevDebugAidl UP-TO-DATE
:app:compileDevDebugRenderscript UP-TO-DATE
:app:checkDevDebugManifest UP-TO-DATE
:app:generateDevDebugBuildConfig UP-TO-DATE
:app:generateDevDebugResValues UP-TO-DATE
:app:generateDevDebugResources UP-TO-DATE
:app:mergeDevDebugResourcesAAPT err(Facade for 849578689): /var/android_home/build-tools/26.0.2/aapt2: 6: /var/android_home/build-tools/26.0.2/aapt2: Syntax error: Unterminated quoted string
AAPT err(Facade for 1702555035): /var/android_home/build-tools/26.0.2/aapt2: 6: /var/android_home/build-tools/26.0.2/aapt2: Syntax error: Unterminated quoted string
Slave 1702555035 failed to start
java.lang.RuntimeException: AAPT slave failed to start. Please make sure the current build tools (located at /var/android_home/build-tools/26.0.2/aapt2) are not corrupted.
at com.android.builder.png.AaptProcess.waitForReadyOrFail(AaptProcess.java:211)
at com.android.builder.internal.aapt.AaptQueueThreadContext.creation(AaptQueueThreadContext.java:56)
at com.android.builder.tasks.WorkQueue.run(WorkQueue.java:213)
at java.lang.Thread.run(Thread.java:748)
AAPT err(Facade for 1365735589): /var/android_home/build-tools/26.0.2/aapt2: 6: /var/android_home/build-tools/26.0.2/aapt2: Syntax error: Unterminated quoted string
Slave 1365735589 failed to start
java.lang.RuntimeException: AAPT slave failed to start. Please make sure the current build tools (located at /var/android_home/build-tools/26.0.2/aapt2) are not corrupted.
at com.android.builder.png.AaptProcess.waitForReadyOrFail(AaptProcess.java:211)
at com.android.builder.internal.aapt.AaptQueueThreadContext.creation(AaptQueueThreadContext.java:56)
at com.android.builder.tasks.WorkQueue.run(WorkQueue.java:213)
at java.lang.Thread.run(Thread.java:748)
AAPT err(Facade for 212997924): /var/android_home/build-tools/26.0.2/aapt2: 6: /var/android_home/build-tools/26.0.2/aapt2: Syntax error: Unterminated quoted string
Slave 212997924 failed to start
java.lang.RuntimeException: AAPT slave failed to start. Please make sure the current build tools (located at /var/android_home/build-tools/26.0.2/aapt2) are not corrupted.
at com.android.builder.png.AaptProcess.waitForReadyOrFail(AaptProcess.java:211)
at com.android.builder.internal.aapt.AaptQueueThreadContext.creation(AaptQueueThreadContext.java:56)
at com.android.builder.tasks.WorkQueue.run(WorkQueue.java:213)
at java.lang.Thread.run(Thread.java:748)
Slave 849578689 failed to start
java.lang.RuntimeException: AAPT slave failed to start. Please make sure the current build tools (located at /var/android_home/build-tools/26.0.2/aapt2) are not corrupted.
at com.android.builder.png.AaptProcess.waitForReadyOrFail(AaptProcess.java:211)
at com.android.builder.internal.aapt.AaptQueueThreadContext.creation(AaptQueueThreadContext.java:56)
at com.android.builder.tasks.WorkQueue.run(WorkQueue.java:213)
at java.lang.Thread.run(Thread.java:748)
Error: java.util.concurrent.ExecutionException: java.lang.RuntimeException: No server to serve request. Check logs for details.
:app:mergeDevDebugResources FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:mergeDevDebugResources'.
> Error: java.util.concurrent.ExecutionException: java.lang.RuntimeException: No server to serve request. Check logs for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
BUILD FAILED in 13s
7 actionable tasks: 1 executed, 6 up-to-date
Build step 'Invoke Gradle script' changed build result to FAILURE
Build step 'Invoke Gradle script' marked build as failure
Finished: FAILURE
TRAIL AND STILL ERROR
I was google around it seem that, a solution need to use older build-tool which I don't want Android studio 2.1.2 gradle aapt Syntax error: Unterminated quoted string
and someone said I have missing library to execute 64 bit code, so I run the following command on my mac OSX and check, but it seem okay Android Studio 3.0 - No server to serve request
otool -L build-tools/26.0.2/aapt2
build-tools/26.0.2/aapt2:
#rpath/libc++.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1213.0.0)
finally, I give permission to my local path sudo chmod 755 -R /Users/sattha.p/Library/Android/sdk but nothing change even restart docker.
When I try to do Build Android-studio project in jenkins I get this error:
Could not create service of type FileCollectionSnapshotterRegistry using TaskExecutionServices.createFileCollectionSnapshotterRegistry().
Could not create service of type CachingFileHasher using TaskExecutionServices.createFileSnapshotter().
I didn't found a answer any place, please help me :)
Started by user admin
Building in workspace /var/lib/jenkins/workspace/AndroidProject
> git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git config remote.origin.url https://github.com/ShiraOzeri/Try_MyTest # timeout=10
Fetching upstream changes from https://github.com/ShiraOzeri/Try_MyTest
> git --version # timeout=10
> git fetch --tags --progress https://github.com/ShiraOzeri/Try_MyTest +refs/heads/*:refs/remotes/origin/*
> git rev-parse refs/remotes/origin/master^{commit} # timeout=10
> git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision 78a492d135b437ee188d71ba44a060540fc56a95 (refs/remotes/origin/master)
> git config core.sparsecheckout # timeout=10
> git checkout -f 78a492d135b437ee188d71ba44a060540fc56a95
> git rev-list 78a492d135b437ee188d71ba44a060540fc56a95 # timeout=10
[Gradle] - Launching build.
[AndroidProject] $ /var/lib/jenkins/workspace/AndroidProject/gradlew build
Starting a Gradle Daemon (subsequent builds will be faster)
Incremental java compilation is an incubating feature.
FAILURE: Build failed with an exception.
* What went wrong:
Could not create service of type FileCollectionSnapshotterRegistry using TaskExecutionServices.createFileCollectionSnapshotterRegistry().
> Could not create service of type CachingFileHasher using TaskExecutionServices.createFileSnapshotter().
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 7.083 secs
FAILURE: Build failed with an exception.
* What went wrong:
java.nio.file.AccessDeniedException: /var/lib/jenkins/workspace/AndroidProject/build/android-profile/profile-2017-06-19-18-24-07-215.rawproto
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Build step 'Invoke Gradle script' changed build result to FAILURE
Build step 'Invoke Gradle script' marked build as failure
Finished: FAILURE
So. my solution:
first, you need to check if you have gradle
To test the Gradle installation, just run Gradle from the command-line:
gradle
second, this help me a lot,
try this:
chown -R jenkins:jenkins <Path to your jenkins>
example: chown -R jenkins:jenkins /var/lib/jenkins/
Thanks!!
You can see it clearly in the error "AccessDeniedException"
What went wrong:
java.nio.file.AccessDeniedException: /var/lib/jenkins/workspace/AndroidProject/build/android-profile/profile-2017-06-19-18-24-07-215.rawproto
You probably have a user/group permissions problem. Try to see if the Jenkins user have permissions to make changes in that folder (since Jenkins has different user).
I had the same problem. Seems like some process is holding the lock for it.
I tried removing the taskArtifacts from .gradle folder in the workspace but that didn't work.
Ultimately, just a restart of Android Studio did the trick!
Note: I didn't try the chown command as mentioned in the original question.