CircleCI Android constraintLayout doesn't work - android

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

Related

CircleCI is failing to accept license for Android SDK Platform 27

I have the following configuration which worked for months/years, but has recently started failing on android-27
#
# Build configuration for Circle CI
#
general:
artifacts:
- /home/ubuntu/austin-feeds-me/app/build/outputs/apk/
machine:
java:
version: openjdk8
environment:
ANDROID_HOME: /usr/local/android-sdk-linux
GRADLE_OPTS: '-Dorg.gradle.jvmargs="-Xmx2048m -XX:+HeapDumpOnOutOfMemoryError"'
dependencies:
pre:
- echo y | android update sdk --no-ui --all --filter tools,platform-tools,android-27
- echo y | android update sdk --no-ui --all --filter build-tools-26.0.2
- echo y | android update sdk --no-ui --all --filter tools
- echo y | android update sdk --no-ui --all --filter extra-android-m2repository
- echo y | android update sdk --no-ui --all --filter extra-android-support
- echo y | android update sdk --no-ui --all --filter extra-google-google_play_services
- echo y | android update sdk --no-ui --all --filter extra-google-m2repository
override:
- ANDROID_HOME=/usr/local/android-sdk-linux ./gradlew dependencies
test:
override:
- (./gradlew assemble):
timeout: 360
When my circleci job runs now I get the following exception even though I am sending y to the android update sdk command.
IDLE<=============> 100% CONFIGURING [31s]<=============> 100% CONFIGURING [32s]Checking the license for package Android SDK Platform 27 in /usr/local/android-sdk-linux/licenses
Warning: License for package Android SDK Platform 27 not accepted.
<=============> 100% CONFIGURING [32s]> IDLE> IDLE> IDLE
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:
[Android SDK Platform 27].
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
* 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 43s
I ended up migrating to CircleCi 2.0. Below is a quick and dirty circle.yml file for android on circleci 2.0:
version: 2
jobs:
build:
working_directory: ~/code
docker:
- image: circleci/android:api-27-alpha
environment:
JVM_OPTS: -Xmx3200m
steps:
- checkout
- restore_cache:
key: jars-{{ checksum "build.gradle" }}-{{ checksum "app/build.gradle" }}
- run:
name: Download Dependencies
command: |
sudo chmod +x gradlew
./gradlew androidDependencies
- save_cache:
paths:
- ~/.gradle
key: jars-{{ checksum "build.gradle" }}-{{ checksum "app/build.gradle" }}
- run:
name: Build Debug
command: ./gradlew assembleDebug
- store_artifacts:
path: app/build/outputs/apk/debug/app-debug.apk
destination: app-debug.apk
- run:
name: Uploading on Beta
command: ./gradlew crashlyticsUploadDistributionDebug
Here's the workaround:-
- run:
name: Approve license for build tools
command: (echo y; echo y; echo y; echo y; echo y; echo y) | $ANDROID_HOME/tools/bin/sdkmanager --licenses

ConstraintLayout issue with circleci on Android

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

CircleCI: auto deploy to Google Playstore: expected <block end>, but found BlockMappingStart

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.

GitLab.com CI shared runner for Android projects

I'd like to use GitLab CI system for my Android application gradle project. The project repository is hosted on GitLab.com, so I'd like to use one of the Shared Runners provided by Gitlab Inc.
While the official tutorial provides an example for NodeJS project runner configuration and there are also shared runners for Ruby projects, I couldn't find any example or even a runner that supports Android applications.
Is there a shared runner provided by GitLab.com, which supports Android projects out of the box (by specifying image: android:4.2.2 or something like this)?
Is there a way to configure existing shared runner provided by GitLab.com to support Android projects (by modifying the .gitlab-ci.yml file)?
I'm using this docker image to run android build on gitlab-ci
Update:
Moved to Gitlab registry
image: registry.gitlab.com/showcheap/android-ci:latest
before_script:
- export GRADLE_USER_HOME=`pwd`/.gradle
- chmod +x ./gradlew
cache:
paths:
- .gradle/wrapper
- .gradle/caches
build:
stage: build
script:
- ./gradlew assemble
test:
stage: test
script:
- ./gradlew check
Full Guide can check in this Gitlab Repository:
https://gitlab.com/showcheap/android-ci
If your Target SDK and Build Tools version are not listed, please make a pull request or fork my repo then make your custom target and build version.
This is the .gitlab-ci.yml file which I'm using in my android project. Since I changed it to install one component at a time it is pretty stable. Sometimes the licence can't be accepted and the build fails. But that's a rare case.
It is important that your build-tools are the same as in this script (build-tools-23.0.3) maybe you have to change the script here.
You can leave out the artifacts declaration I use it to get the lint report.
before_script:
- apt-get --quiet update --yes
- apt-get --quiet install --yes wget tar unzip openjdk-7-jdk lib32stdc++6 lib32z1
- wget --quiet --output-document=android-sdk.tgz https://dl.google.com/android/android-sdk_r24.4.1-linux.tgz
- tar --extract --gzip --file=android-sdk.tgz
- echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter android-23
- echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter platform-tools
- echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter build-tools-23.0.3
- echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter extra-android-m2repository
- echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter extra-google-google_play_services
- echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter extra-google-m2repository
- wget --quiet --output-document=gradle.zip https://services.gradle.org/distributions/gradle-2.12-bin.zip
- unzip -q gradle.zip
- export ANDROID_HOME=$PWD/android-sdk-linux
build:
script:
- gradle-2.12/bin/gradle assembleDebug check --stacktrace
artifacts:
paths:
- library/build/outputs/lint-results.html
- app/build/outputs/lint-results.html
UPDATE
According to this post you'll need to set up your own runner.
You'll find more information regarding building Android Apps on the same post.

Gradle assembleDebug and preDexDebug fail with CircleCI

I tried to assembleDebug using CircleCI, but it must fail to build(preDex).
Why can't I do that?
Using ProductFlavor(the name is production)
Android Gradle ver.1.1.0-rc1
Problem
./gradlew assembleProductionDebug died unexpectedly Building 92%3% >
:app:preDexProductionDebugaction ./gradlew assembleProductionDebug
failed
circle.yml
general:
artifacts:
- "app/build/outputs/apk/app-production-release-unaligned.apk"
machine:
java:
version: openjdk7
environment:
ANDROID_HOME: /usr/local/android-sdk-linux
dependencies:
pre:
- echo y | android update sdk --no-ui --all --filter "build-tools-21.1.2"
- echo y | android update sdk --no-ui --all --filter "platform-tools"
- echo y | android update sdk --no-ui --all --filter "tools"
- echo y | android update sdk --no-ui --all --filter "extra-google-google_play_services"
- echo y | android update sdk --no-ui --all --filter "extra-google-m2repository"
- echo y | android update sdk --no-ui --all --filter "extra-android-m2repository"
- echo y | android update sdk --no-ui --all --filter "extra-android-support"
- echo y | android update sdk --no-ui --all --filter "android-21"
- git submodule sync
- git submodule update --init
cache_directories:
- ~/.android
- ~/android
override:
- ./gradlew dependencies
test:
override:
- ./gradlew test
deployment:
master:
branch: master
commands:
- ./gradlew assembleProductionDebug
I had the same issue. It turned out that I had to disable preDex for the ci builds.
Put this in the root build.gradle:
project.ext.preDexLibs = !project.hasProperty('disablePreDex')
subprojects {
project.plugins.whenPluginAdded { plugin ->
if ("com.android.build.gradle.AppPlugin".equals(plugin.class.name)) {
project.android.dexOptions.preDexLibraries = rootProject.ext.preDexLibs
} else if ("com.android.build.gradle.LibraryPlugin".equals(plugin.class.name)) {
project.android.dexOptions.preDexLibraries = rootProject.ext.preDexLibs
}
}
}
Then you can build on your ci with the following command:
./gradlew ... -PdisablePreDex
So I had the same issue and found even though java and gradle heap sizes were being set they were not being fully respected as the dex tasks spawn a ton of fresh threads with their own heap size (check your memory log and you may see the same)
If so, the method I used to fix it for Android Gradle plugin 1.3 and above was to use:
-Pcom.android.build.threadPoolSize=1
This will stop the dexing step spawning a bunch of fresh 1G threads. There is also:
-Porg.gradle.parallel=false
But I found this to be ineffective when using multidex for some reason.
For CircleCI I found this to be the most consistent build task, if a little slow. I'm sure the heap sizes can be tweaked a little further for better results:
./gradlew build -PpreDexEnable=false -Pcom.android.build.threadPoolSize=1 -Dorg.gradle.parallel=false -Dorg.gradle.jvmargs="-Xms512m -Xmx512m" -Dorg.gradle.daemon=false
I had a same problem, it was caused since the memory limits per a container (it is 4GB).
For me, the solution was to use:
gradle.properties
org.gradle.jvmargs=-Xms256m -Xmx2048m

Categories

Resources