I have a problem with CircleCI that I can not get to work because my gradlew file is not in the root of my repository. As my depot is deprived here is a summary of his architectures:
root
-----> app_folder
------------> some folders
------------> some files
------------> gradlew
------> some files and folders
------> circle.yml
I tried to go into the app_folder folder using the cd command and change the path variable but nothing of it worked
circle.yml
#
# Build configuration for Circle CI
#
machine:
environment:
PATH: "~/$CIRCLE_PROJECT_REPONAME/app_folder:$PATH"
ANDROID_HOME: /usr/local/android-sdk-linux
GRADLE_OPTS: '-Dorg.gradle.jvmargs="-Xmx2048m -XX:+HeapDumpOnOutOfMemoryError"'
_JAVA_OPTIONS: "-Xms512m -Xmx1024m"
ADB_INSTALL_TIMEOUT: "10"
ANDROID_API_LEVEL: 25
ANDROID_BUILD_TOOLS_VERSION: 25.0.2
java:
version: oraclejdk7
dependencies:
cache_directories:
- ~/.gradle
- ~/.android
- /usr/local/android-sdk-linux/extras
pre:
- if [ ! -d "$ANDROID_HOME/tools" ]; then echo y | android update sdk --no-ui --all --filter "tools"; fi
- if [ ! -d "$ANDROID_HOME/platforms/android-$ANDROID_API_LEVEL" ]; then echo y | android update sdk --no-ui --all --filter "android-$ANDROID_API_LEVEL"; fi
- if [ ! -d "$ANDROID_HOME/build-tools/$ANDROID_BUILD_TOOLS_VERSION" ]; then echo y | android update sdk --no-ui --all --filter "build-tools-$ANDROID_BUILD_TOOLS_VERSION"; fi
- if [ ! -d "$ANDROID_HOME/add-ons/addon-google_apis-google-$ANDROID_API_LEVEL" ]; then echo y | android update sdk --no-ui --all --filter "addon-google_apis-google-$ANDROID_API_LEVEL"; fi
- echo y | android update sdk --no-ui --all --filter "extra-google-m2repository"
- echo y | android update sdk --no-ui --all --filter "extra-google-google_play_services"
- echo y | android update sdk --no-ui --all --filter "extra-android-m2repository"
test:
override:
# start the emulator
- emulator -avd circleci-android24 -no-audio -no-window:
background: true
parallel: true
# wait for it to have booted
- circle-android wait-for-boot
# unlock the emulator screen
- sleep 30
- adb shell input keyevent 82
# run tests against the emulator.
- echo $PATH
- cd app_folder && .\gradlew connectedAndroidTest -PdisablePreDex
- .\\app_folder\\gradlew connectedAndroidTest -PdisablePreDex
- .\app_folder\\gradlew connectedAndroidTest -PdisablePreDex
- .\gradlew connectedAndroidTest -PdisablePreDex ~/github_name/app_folder
# copy the build outputs to artifacts
- cp -r app_folder/app/build/outputs $CIRCLE_ARTIFACTS
# copy the test results to the test results directory.
- cp -r app_folder/app/build/outputs/androidTest-results/* $CIRCLE_TEST_REPORTS
You just need to add this on the top :
general:
build_dir: your_folder
There's two options here. The quickest is to specify a custom build directory. Using your example, this would be:
general:
build_dir: app_folder
This is because per CircleCI Docs:
CircleCI will run its inference as well as all build commands from
that directory.
The second option would be to not rely on CircleCI's Inference commands at all and instead run everything, like Gradle yourself. You're already overriding the test phase, so you'd need to override the dependencies phase as well and run gradle dependencies yourself.
For example:
dependencies:
override:
- gradle --project-dir app_folder dependencies
-Ricardo N Feliciano
Developer Evangelist, CircleCI
Related
I create an android project in git lab. I'm trying to use pipelines .
The build failed with message
Before building your project, you need to accept the license agreements and complete the installation of the missing components using the Android Studio SDK Manager.
How can I accept this licences automatically?
Adding --no-ui --all is not enough (I have already tried to add them!).
I tried all the soluctions presented [here](you need to accept the license agreements and complete) with no success.
Does someone actually managed to make git lab pipelines works for android?
Below my .gitlab-ci.yml file.
image: openjdk:8-jdk
variables:
ANDROID_COMPILE_SDK: "24"
ANDROID_BUILD_TOOLS: "25.0.3"
ANDROID_SDK_TOOLS: "25.0.3"
before_script:
- export ANDROID_HOME=$PWD/
- export PATH=$PATH:$PWD/
- apt-get --quiet update --yes
- apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1
- wget --quiet --output-document=android-sdk.zip https://dl.google.com/android/repository/tools_r${ANDROID_SDK_TOOLS}-linux.zip
- unzip android-sdk.zip
- echo y | tools/android --silent update sdk --no-ui --all --filter android-${ANDROID_COMPILE_SDK}
- echo y | tools/android --silent update sdk --no-ui --all --filter platform-tools
- echo y | tools/android --silent update sdk --no-ui --all --filter build-tools-${ANDROID_BUILD_TOOLS}
- echo y | tools/android --silent update sdk --no-ui --all --filter extra-android-m2repository
- echo y | tools/android --silent update sdk --no-ui --all --filter extra-google-google_play_services
- echo y | tools/android --silent update sdk --no-ui --all --filter extra-google-m2repository
- chmod +x ./gradlew
stages:
- build
build:
stage: build
script:
- ./gradlew assembleDebug --stacktrace
artifacts:
paths:
- app/build/outputs/
The sdkmanager cli can be used to update sdks/ accept licenses.
To accept all licenses you can run
echo y | tools/bin/sdkmanager --licenses
I finnally resolve the problem using sdkmanager but I had to download the sdk zip instead of the tools zip like the code in my original question.
This is the final code I copied from Nick Petrovsky post on gitlab issue tracker
image: openjdk:8-jdk
variables:
ANDROID_COMPILE_SDK: "24"
ANDROID_BUILD_TOOLS: "25.0.3"
# ANDROID_SDK_TOOLS: "25.0.3"
ANDROID_SDK_TOOLS_REV: "3859397" # "26.0.1"
before_script:
- mkdir $HOME/.android # For sdkmanager configs
- echo 'count=0' > $HOME/.android/repositories.cfg # Avoid warning
- wget --quiet --output-document=android-sdk.zip https://dl.google.com/android/repository/sdk-tools-linux-${ANDROID_SDK_TOOLS_REV}.zip
- mkdir $PWD/android-sdk-linux
- unzip -qq android-sdk.zip -d $PWD/android-sdk-linux
- export ANDROID_HOME=$PWD/android-sdk-linux
- export ANDROID_NDK_HOME=$ANDROID_HOME/ndk-bundle # Remove if you don't need NDK
- export PATH=$PATH:$ANDROID_HOME/platform-tools/:$ANDROID_NDK_HOME
- echo y | $ANDROID_HOME/tools/bin/sdkmanager --update
- echo y | $ANDROID_HOME/tools/bin/sdkmanager 'tools'
- echo y | $ANDROID_HOME/tools/bin/sdkmanager 'platform-tools'
- echo y | $ANDROID_HOME/tools/bin/sdkmanager 'build-tools;'$ANDROID_BUILD_TOOLS
- echo y | $ANDROID_HOME/tools/bin/sdkmanager 'platforms;android-'$ANDROID_COMPILE_SDK
- echo y | $ANDROID_HOME/tools/bin/sdkmanager 'extras;android;m2repository'
- echo y | $ANDROID_HOME/tools/bin/sdkmanager 'extras;google;google_play_services'
- echo y | $ANDROID_HOME/tools/bin/sdkmanager 'extras;google;m2repository'
- chmod +x ./gradlew
At the end I used this gitlab-ci-android docker image
It is faster and cause much less problems:
before_script:
- export GRADLE_USER_HOME=`pwd`/.gradle
- mkdir -p $GRADLE_USER_HOME
- chmod +x ./gradlew
cache:
paths:
- .gradle/wrapper
- .gradle/caches
build:
stage: build
script:
- ./gradlew assemble
test:
stage: test
script:
- ./gradlew check
I have created a CI image for Android, which can be found at https://gitlab.com/mvglasow/android-gitlab-ci.
It is based on what is described at https://about.gitlab.com/2018/10/24/setting-up-gitlab-ci-for-android-projects/, but it has all the Android tools in the image already so you don’t have to install them again for every CI run. Compared to the instructions, the image saves you about 30 seconds per pipeline.
I am having the following build failure on circleci for my android project :
What went wrong:
A problem occurred configuring project ':app'.
You have not accepted the license agreements of the following SDK components:
[Solver for ConstraintLayout 1.0.0-beta4, ConstraintLayout for Android 1.0.0-beta4].
Before building your project, you need to accept the license agreements and complete the installation of the missing components using the Android Studio SDK Manager.
Alternatively, to learn how to transfer the license agreements from one workstation to another, go to http://d.android.com/r/studio-ui/export-licenses.html
I am using the following circle.yml for build:
test:
override:
- (./gradlew assemble):
timeout: 360
dependencies:
pre:
# Android SDK Platform 24
- if [ ! -d "/usr/local/android-sdk-linux/platforms/android-25" ]; then echo y | android update sdk --no-ui --all --filter "android-25"; fi
# Android SDK Build-tools, revision 25.0.1
- if [ ! -d "/usr/local/android-sdk-linux/build-tools/25.0.1" ]; then echo y | android update sdk --no-ui --all --filter "build-tools-25.0.1"; fi
# Android Support Repository, revision 40 / Local Maven repository for Support Libraries
- if [ ! -d "/usr/local/android-sdk-linux/extras/android/m2repository/com/android/support/support-v4/25.0.1" ]; then echo y | android update sdk --no-ui --all --filter "extra-android-m2repository"; fi
# Google Support Repository, revision 40 / Local Maven repository for Support Libraries
- if [ ! -d "/usr/local/android-sdk-linux/extras/google/m2repository/com/google/firebase/firebase-core/10.0.1" ]; then echo y | android update sdk --no-ui --all --filter "extra-google-m2repository"; fi
- mkdir $ANDROID_HOME/licenses; ls -l $ANDROID_HOME/licenses
- cp --force licenses/* $ANDROID_HOME/licenses; ls -l $ANDROID_HOME/licenses
cache_directories:
- /usr/local/android-sdk-linux/platforms/android-25
- /usr/local/android-sdk-linux/build-tools/25.0.1
- /usr/local/android-sdk-linux/extras/android/m2repository
- /usr/local/android-sdk-linux/extras/google/m2repository
override:
# Adding true flag because of this issue with ConstraintLayout https://code.google.com/p/android/issues/detail?id=212128
- ANDROID_HOME=/usr/local/android-sdk-linux ./gradlew dependencies || true
machine:
java:
version: oraclejdk8
environment:
ANDROID_HOME: /usr/local/android-sdk-linux
What might be the cause of this problem ?
It seems that android is deprecated or being replaced with sdkmanager as a package manager. For example, in my case, sdkmanager has access(lists) to the ConstraintLayout and ConstraintLayout Solver packages, but android does not.
For more info on sdkmanager, visit the official docs
In my case, I also had to update the sdk tools using android in order to have sdkmanager installed. The install location is not in the tools folder, though, but tools/bin, so I also had to access sdkmanager directly, as it wasn't included in $PATH on my CI machine.
Applying all this to your case:
# Android SDK Platform 24
- if [ ! -d "/usr/local/android-sdk-linux/platforms/android-25" ]; then echo y | android update sdk --no-ui --all --filter "android-25"; fi
# Android SDK Build-tools, revision 25.0.1
- if [ ! -d "/usr/local/android-sdk-linux/build-tools/25.0.1" ]; then echo y | android update sdk --no-ui --all --filter "build-tools-25.0.1"; fi
# Android Support Repository, revision 40 / Local Maven repository for Support Libraries
- if [ ! -d "/usr/local/android-sdk-linux/extras/android/m2repository/com/android/support/support-v4/25.0.1" ]; then echo y | android update sdk --no-ui --all --filter "extra-android-m2repository"; fi
# Google Support Repository, revision 40 / Local Maven repository for Support Libraries
- if [ ! -d "/usr/local/android-sdk-linux/extras/google/m2repository/com/google/firebase/firebase-core/10.0.1" ]; then echo y | android update sdk --no-ui --all --filter "extra-google-m2repository"; fi
# Android Tools latest (has sdkmanager)
- if [ ! -d "/usr/local/android-sdk-linux/tools/bin/sdkmanager" ]; then echo y | android update sdk --no-ui --all --filter "tools"; fi
# ConstraintLayout
- if [ ! -d "/usr/local/android-sdk-linux/extras/m2repository/com/android/support/constraint/constraint-layout/1.0.0-beta4" ]; then echo y | /usr/local/android-sdk-linux/tools/bin/sdkmanager "extras;m2repository;com;android;support;constraint;constraint-layout;1.0.0-beta4"; fi
# ConstraintLayout Solver
- if [ ! -d "/usr/local/android-sdk-linux/extras/m2repository/com/android/support/constraint/constraint-layout-solver/1.0.0-beta4" ]; then echo y | /usr/local/android-sdk-linux/tools/bin/sdkmanager "extras;m2repository;com;android;support;constraint;constraint-layout-solver;1.0.0-beta4"; fi
I'm trying to use CircleCi with my Android project i've added the circle.yml file but every time the build fails with the following error
A problem occurred configuring project ':app'.
failed to find Build Tools revision 23.0.1
the following is my circle.yml file
#
# Build configuration for Circle CI
#
general:
artifacts:
- /home/ubuntu/ES-NRP-Android-V3/app/build/outputs/apk/
machine:
environment:
ANDROID_HOME: /usr/local/android-sdk-linux
dependencies:
pre:
- echo y | android update sdk --no-ui --all --filter "tools"
- echo y | android update sdk --no-ui --all --filter "build-tools-23.0.1"
override:
- echo y | android update sdk --no-ui --all --filter tools,platform-tools,build-tools-23.0.1,android-23,extra-google-m2repository,extra-google-google_play_services,extra-android-support
- ANDROID_HOME=/usr/local/android-sdk-linux ./gradlew dependencies
test:
override:
- (./gradlew assemble):
timeout: 360
i'm targeting SDK version 23 and build tools 23.0.2
I'm target to Sdk 25, and this is my working cicle.yml file:
general:
artifacts:
- /home/ubuntu/your-app-name/app/build/outputs/apk/
machine:
environment:
ANDROID_HOME: /usr/local/android-sdk-linux
dependencies:
pre:
- echo y | android update sdk --no-ui --all --filter tools,platform-tools,extra-google-m2repository,extra-google-google_play_services,extra-android-support,android-25
- echo y | android update sdk --no-ui --all --filter build-tools-25.0.0
- if [ ! -d "/usr/local/android-sdk-linux/platforms/android-25" ]; then echo y | android update sdk --no-ui --all --filter "android-25"; fi
- if [ ! -d "/usr/local/android-sdk-linux/build-tools/25.0.0" ]; then echo y | android update sdk --no-ui --all --filter "build-tools-25.0.0"; fi
- if [ ! -d "/usr/local/android-sdk-linux/extras/android/m2repository/com/android/support/design/25.0.0" ]; then echo y | android update sdk --no-ui --all --filter "extra-android-m2repository"; fi
cache_directories:
- /usr/local/android-sdk-linux/tools
- /usr/local/android-sdk-linux/build-tools/25.0.0
- /usr/local/android-sdk-linux/platforms/android-25
- /usr/local/android-sdk-linux/extras/android/m2repository
test:
override:
- ./gradlew assemble
- cp -r app/build/outputs $CIRCLE_ARTIFACTS
Test this CircleCi.yml file I made for Android projects forandroid version : 24
https://gist.github.com/mirhoseini/579cdf1b78a73738813ae5de71ceceb4
I hope it helps :)
I am now using the CircleCI for my project. Also I am implementing the new constraintLayout in my project. Now I am stuck with the CircleCI building. It shows me this when gradle -dependencies run:
File /home/ubuntu/.android/repositories.cfg could not be loaded.
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> You have not accepted the license agreements of the following SDK components:
[com.android.support.constraint:constraint-layout:1.0.0-alpha3, com.android.support.constraint:constraint-layout-solver:1.0.0-alpha3].
Before building your project, you need to accept the license agreements and complete the installation of the missing components using the Android Studio SDK Manager.
Alternatively, to learn how to transfer the license agreements from one workstation to another, go to http://d.android.com/r/studio-ui/export-licenses.html
Here is my configuration in .yml file:
#Install android build tools, platforms
#Supported versions here https://circleci.com/docs/android
machine:
java:
version: openjdk8
environment:
ANDROID_HOME: /usr/local/android-sdk-linux
dependencies:
pre:
- echo y | android list sdk
- echo y | android update sdk --no-ui --all --filter "tools"
- echo y | android update sdk --no-ui --all --filter "platform-tools"
- echo y | android update sdk --no-ui --all --filter "build-tools-24.0.0"
- echo y | android update sdk --no-ui --all --filter "android-24"
- echo y | android update sdk --no-ui --all --filter "extra-google-m2repository"
- echo y | android update sdk --no-ui --all --filter "extra-google-google_play_services"
- echo y | android update sdk --no-ui --all --filter "extra-android-support"
- echo y | android update sdk --no-ui --all --filter "extra-android-m2repository"
- (./gradlew -version):
timeout: 360
override:
#- ANDROID_HOME=/usr/local/android-sdk-linux ./gradlew dependencies
- export TERM="dumb"; if [ -e ./gradlew ]; then ./gradlew clean dependencies -stacktrace;else gradle clean dependencies -stacktrace;fi
#Pull any submodules
checkout:
post:
- git submodule init
- git submodule update
#-PdisablePreDex is a must else gradle just dies due to memory limit
#Replace
test:
override:
- (./gradlew assemble -PdisablePreDex):
timeout: 360
- cp -r ${HOME}/${CIRCLE_PROJECT_REPONAME}/app/build/outputs/apk/ $CIRCLE_ARTIFACTS
- emulator -avd circleci-android22 -no-audio -no-window:
background: true
parallel: true
# wait for it to have booted
- circle-android wait-for-boot
# run tests against the emulator.
- ./gradlew connectedAndroidTest
#Deploy when tests pass
deployment:
#production:
# branch: master
# commands:
# - (./gradlew clean assembleRelease crashlyticsUploadDistributionRelease -PdisablePreFex):
# timeout: 720
staging:
branch: staging
commands:
- (./gradlew clean assembleStaging crashlyticsUploadDistributionStaging -PdisablePreFex):
timeout: 720
I checked in the build log when
echo y | android update sdk --no-ui --all --filter "extra-android-m2repository"
command run and here is the result:
November 20, 2015
Do you accept the license 'android-sdk-license-c81a61d9' [y/n]:
Installing Archives:
Preparing to install archives
Downloading Android Support Repository, revision 33
Installing Android Support Repository, revision 33
Installed Android Support Repository, revision 33
Done. 1 package installed.
And my classpath is:
classpath 'com.android.tools.build:gradle:2.2.0-alpha4'
I am not sure what I've done incorrectly or is there anything I need to add more. Please suggest.
Thanks.
Alex Fu's answer explains nicely where the problem lies and how to deal with it but there is a simpler solution. Since the license files are really just simple files with a bunch of hex characters in them you can create them simply without any copying. An example would be putting the following code into the pre: section:
- ANDROID_HOME=/usr/local/android-sdk-linux
- mkdir "$ANDROID_HOME/licenses" || true
- echo "8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_HOME/licenses/android-sdk-license"
- echo "84831b9409646a918e30573bab4c9c91346d8abd" > "$ANDROID_HOME/licenses/android-sdk-preview-license"
- echo "d975f751698a77b662f1254ddbeed3901e976f5a" > "$ANDROID_HOME/licenses/intel-android-extra-license"
TL;DR
You need to copy the licenses from $ANDROID_HOME/licenses into your CircleCI environment.
You can zip up your licenses and store it on Dropbox (or something similar) and modify your circle.yml file to download the licenses and extract it to $ANDROID_HOME.
The last paragraph of the error pretty much explains it
Before building your project, you need to accept the license agreements and complete the installation of the missing components using the Android Studio SDK Manager. Alternatively, to learn how to transfer the license agreements from one workstation to another, go to http://d.android.com/r/studio-ui/export-licenses.html
This worked for me, and also checks for cached versions first:
dependencies:
pre:
# Android SDK Platform 24
- if [ ! -d "/usr/local/android-sdk-linux/platforms/android-24" ]; then echo y | android update sdk --no-ui --all --filter "android-24"; fi
# Android SDK Build-tools, revision 24.0.1
- if [ ! -d "/usr/local/android-sdk-linux/build-tools/24.0.1" ]; then echo y | android update sdk --no-ui --all --filter "build-tools-24.0.1"; fi
# Android Support Repository, revision 35 / Local Maven repository for Support Libraries
- if [ ! -d "/usr/local/android-sdk-linux/extras/android/m2repository/com/android/support/design/24.1.0" ]; then echo y | android update sdk --no-ui --all --filter "extra-android-m2repository"; fi
cache_directories:
- /usr/local/android-sdk-linux/platforms/android-24
- /usr/local/android-sdk-linux/build-tools/24.0.1
- /usr/local/android-sdk-linux/extras/android/m2repository
Taken from this post by CircleCI employee drazisil
I have same issue with ConstraintLayout, this is my working config circle.yml
I have been configured the Auto deploying the Apk file to Google Play Store via CircleCI. Now I've just faced with the problem that cause build failed and it shows:
expected <block end>, but found BlockMappingStart
By follow the article from CircleCI site here is my .yml file look like:
#Install android build tools, platforms
#Supported versions here https://circleci.com/docs/android
machine:
java:
version: openjdk8
environment:
ANDROID_HOME: /usr/local/android-sdk-linux
GRADLE_OPTS: '-Dorg.gradle.jvmargs="-Xmx4608m -XX:+HeapDumpOnOutOfMemoryError"'
dependencies:
pre:
- echo y | android update sdk --no-ui --all --filter "tools"
- echo y | android update sdk --no-ui --all --filter "platform-tools"
- echo y | android update sdk --no-ui --all --filter "build-tools-24.0.0"
- echo y | android update sdk --no-ui --all --filter "android-24"
- echo y | android update sdk --no-ui --all --filter "extra-google-m2repository"
- echo y | android update sdk --no-ui --all --filter "extra-google-google_play_services"
- echo y | android update sdk --no-ui --all --filter "extra-android-support"
- echo y | android update sdk --no-ui --all --filter "extra-android-m2repository"
- (./gradlew -version):
timeout: 360
override:
#- ANDROID_HOME=/usr/local/android-sdk-linux ./gradlew dependencies
- export TERM="dumb"; if [ -e ./gradlew ]; then ./gradlew clean dependencies -stacktrace;else gradle clean dependencies -stacktrace;fi
#Pull any submodules
checkout:
post:
- git submodule init
- git submodule update
#-PdisablePreDex is a must else gradle just dies due to memory limit
#Replace
test:
override:
- (./gradlew assemble -PdisablePreDex -stacktrace):
timeout: 360
- cp -r ${HOME}/${CIRCLE_PROJECT_REPONAME}/app/build/outputs/apk/ $CIRCLE_ARTIFACTS
- emulator -avd circleci-android22 -no-audio -no-window:
background: true
parallel: true
# wait for it to have booted
- circle-android wait-for-boot
# run tests against the emulator.
- ./gradlew connectedAndroidTest
#Deploy when tests pass
deployment:
release:
branch: master
commands:
-./gradlew publishApkRelease
-Dorg.gradle.project.track=alpha
staging:
branch: staging
commands:
- (./gradlew clean assembleStaging crashlyticsUploadDistributionStaging -PdisablePreFex):
timeout: 720
I already set classpath and apply a plugin:
apply plugin: 'com.github.triplet.play' // in app module
classpath 'com.github.triplet.gradle:play-publisher:1.1.4' // in project level
I tried to change the command to:
release:
branch: master
commands:
-(./gradlew publishApkRelease -Dorg.gradle.project.track=alpha):
timeout: 720
just like I have done on Crahlytic but it still doesn't work (Auto release to Crashlytic is working fine.)
Please suggest.
Thanks.