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
Related
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
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.
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.