SDK location not found. CircleCi - android

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

Related

Azure devops - SDK location not found. Define location with an ANDROID_SDK_ROOT environment

I get the below error while trying to run android application in a self hosted ubuntu agent. Am I getting this error because Android SDK is not present in the Ubuntu agent? If so, is there any workaround? I do not get this issue while the same app is run in a macos agent.
Any help is much appreciated
2022-07-28T23:36:24.0840286Z ##[section]Starting: Build Task
2022-07-28T23:36:24.0850273Z ==============================================================================
2022-07-28T23:36:24.0850626Z Task : Gradle
2022-07-28T23:36:24.0850911Z Description : Build using a Gradle wrapper script
2022-07-28T23:36:24.0851183Z Version : 3.205.0
2022-07-28T23:36:24.0851592Z Author : Microsoft Corporation
2022-07-28T23:36:24.0851981Z Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/build/gradle
2022-07-28T23:36:24.0852397Z ==============================================================================
2022-07-28T23:36:24.4320361Z ##[warning]Used 'chmod' method for gradlew file to make it executable.
2022-07-28T23:36:24.4933143Z [command]/azp/_work/1/s/gradlew assembleDebug
2022-07-28T23:36:25.2820472Z Starting a Gradle Daemon, 1 incompatible and 2 stopped Daemons could not be reused, use --status for details
2022-07-28T23:36:33.1825697Z
2022-07-28T23:36:33.1828123Z > Configure project :app
2022-07-28T23:36:33.1831681Z WARNING: DSL element 'android.dataBinding.enabled' is obsolete and has been replaced with 'android.buildFeatures.dataBinding'.
2022-07-28T23:36:33.1834823Z It will be removed in version 5.0 of the Android Gradle plugin.
2022-07-28T23:36:33.1836236Z VersionCode is set to 999
2022-07-28T23:36:33.1837886Z releaseVersion is set to 1.1.0
2022-07-28T23:36:33.2796793Z WARNING: DSL element 'android.dataBinding.enabled' is obsolete and has been replaced with 'android.buildFeatures.dataBinding'.
2022-07-28T23:36:33.2797944Z It will be removed in version 5.0 of the Android Gradle plugin.
2022-07-28T23:36:33.9796986Z
2022-07-28T23:36:33.9798819Z FAILURE: Build failed with an exception.
2022-07-28T23:36:33.9799385Z
2022-07-28T23:36:33.9799910Z * What went wrong:
2022-07-28T23:36:33.9801449Z A problem occurred configuring project ':app'.
2022-07-28T23:36:33.9802801Z > 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 '/azp/_work/1/s/local.properties'.
2022-07-28T23:36:33.9803386Z
2022-07-28T23:36:33.9803681Z * Try:
2022-07-28T23:36:33.9804986Z 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.
2022-07-28T23:36:33.9805350Z
2022-07-28T23:36:33.9805674Z * Get more help at https://help.gradle.org
2022-07-28T23:36:33.9806648Z
2022-07-28T23:36:33.9807103Z Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
2022-07-28T23:36:33.9807912Z Use '--warning-mode all' to show the individual deprecation warnings.
2022-07-28T23:36:33.9808507Z See https://docs.gradle.org/6.5/userguide/command_line_interface.html#sec:command_line_warnings
2022-07-28T23:36:33.9808801Z
2022-07-28T23:36:33.9809086Z BUILD FAILED in 9s
2022-07-28T23:36:34.4381110Z Error: The process '/azp/_work/1/s/gradlew' failed with exit code 1
2022-07-28T23:36:34.4386504Z at ExecState._setResult (/azp/_work/_tasks/Gradle_8d8eebd8-2b94-4c97-85af-839254cc6da4/3.205.0/node_modules/azure-pipelines-task-lib/toolrunner.js:944:25)
2022-07-28T23:36:34.4390433Z at ExecState.CheckComplete (/azp/_work/_tasks/Gradle_8d8eebd8-2b94-4c97-85af-839254cc6da4/3.205.0/node_modules/azure-pipelines-task-lib/toolrunner.js:927:18)
2022-07-28T23:36:34.4393277Z at ChildProcess.<anonymous> (/azp/_work/_tasks/Gradle_8d8eebd8-2b94-4c97-85af-839254cc6da4/3.205.0/node_modules/azure-pipelines-task-lib/toolrunner.js:840:19)
2022-07-28T23:36:34.4394910Z at ChildProcess.emit (events.js:198:13)
2022-07-28T23:36:34.4396280Z at maybeClose (internal/child_process.js:982:16)
2022-07-28T23:36:34.4397383Z at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
2022-07-28T23:36:34.4415403Z ##[error]Code analysis failed. Gradle exit code: -1. Error: Error: The process '/azp/_work/1/s/gradlew' failed with exit code 1
2022-07-28T23:36:34.4472252Z ##[section]Finishing: Build Task
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 '/azp/_work/1/s/local.properties'.
The cause of this error is that the Android SDK is not installed or the Android environment is not configured on your self-hosted agent.
You need to check if Android SDK has been installed on your self-hosted agent.
If no, you can use the following command to install Android SDK.
sudo apt update && sudo apt install android-sdk
The location of Android SDK on Linux can be any of the following:
/home/AccountName/Android/Sdk
/usr/lib/android-sdk
/Library/Android/sdk/
/Users/[USER]/Library/Android/sdk
Then you can set the Android environment via setting environment variable or setting sdk.dir path in /azp/_work/1/s/local.properties.
For example:
Set environment variable
1.Edit your ~/.zshrc or ~/.bashrc or ...
2. Add SDK path:
export ANDROID_HOME=$HOME/Android/Sdk
export ANDROID_SDK_ROOT=$HOME/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/platform-tools
3.Run command:
source $HOME/.bashrc
echo $ANDROID_SDK_ROOT

Bitbucket Pipelines - Task 'appDistributionUploadStaging' not found in root project 'build'

I am trying to setup CI on Bitbucket Pipelines: what I want to do is assemble and upload the APK on Firebase AppDistribution (using com.google.firebase.appdistribution gradle plugin)
image: androidsdk/android-31
pipelines:
default:
- step:
name: Deploy To Firebase App Distribution Staging
caches:
- gradle
script:
- export FIREBASE_TOKEN=$FB_TOKEN
- ./gradlew --stop
- ./gradlew assembleStaging
- ./gradlew appDistributionUploadStaging
artifacts:
- app/build/outputs/**
Unfortunately, the last step (- ./gradlew appDistributionUploadStaging) always fails for the sequent reason:
What went wrong: Task 'appDistributionUploadStaging' not found in root project 'build'.
p.s. Staging is the name of the buildType

Azure DevOps pipeline android build setting sdk location

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.

Ubuntu - Jenkins unable to access mounted hard disk

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

Circleci. SDK location not found

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

Categories

Resources