How to make CircleCI use a specific Gradle version? - android

It's still using 2.14.1 while I wanted 3.3 in my case:
despite the following circle.yml:
machine:
environment:
PATH: "~/$CIRCLE_PROJECT_REPONAME/gradle-3.3/bin:$PATH"
TERM: "dumb"
ADB_INSTALL_TIMEOUT: "10"
GRADLE_OPTS: '-Dorg.gradle.jvmargs="-Xmx2048m -XX:+HeapDumpOnOutOfMemoryError"'
java:
version: oraclejdk8
dependencies:
pre:
# Install Android stuffs
- wget "https://services.gradle.org/distributions/gradle-3.3-bin.zip"; unzip gradle-3.3-bin.zip
- echo y | android update sdk --no-ui --all --filter tool
- 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
- echo y | android update sdk --no-ui --all --filter android-25
- echo y | android update sdk --no-ui --all --filter build-tools-25.0.2
test:
override:
# start the emulator
- emulator -avd circleci-android19 -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
Wrong version is likely the version why gradle dependencies is failing for me here:

In yourProject/gradle/wrapper/gradle-wrapper.properties", you can define gradle version. Like this:
distributionUrl=https\://services.gradle.org/distributions/gradle-3.4-all.zip
`
Update
I do not think it's necessary to wget "https://services.gradle.org/distributions/gradle-3.3-bin.zip" because when the CI invoke ./gradlew, it will download gradle automaticly.

Related

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 cannot failed to resolve build tools Android

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 :)

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.

Generating Android build with Gitlab CI

I just installed Gitlab as repository for my projects and I want to take advantages of their Gitlab CI system. I want to automatically generate a distribution and debug Apk after each commit. I googled but I didn't find anything as a tutorial or similar cases. If someone could guide me in some way, it would be great.
Thanks!
I've just written a blog post on how to setup Android builds in Gitlab CI using shared runners.
The quickest way would be to have a .gitlab-ci.yml with the following contents:
image: openjdk:8-jdk
variables:
ANDROID_TARGET_SDK: "24"
ANDROID_BUILD_TOOLS: "24.0.0"
ANDROID_SDK_TOOLS: "24.4.1"
before_script:
- apt-get --quiet update --yes
- apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1
- wget --quiet --output-document=android-sdk.tgz https://dl.google.com/android/android-sdk_r${ANDROID_SDK_TOOLS}-linux.tgz
- tar --extract --gzip --file=android-sdk.tgz
- echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter android-${ANDROID_TARGET_SDK}
- 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-${ANDROID_BUILD_TOOLS}
- 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
- export ANDROID_HOME=$PWD/android-sdk-linux
- chmod +x ./gradlew
build:
script:
- ./gradlew assembleDebug
artifacts:
paths:
- app/build/outputs/
This starts off using the Java 8 Docker image, then proceeds to download and install the necessary bits of the Android SDK before your build runs. My post also goes into detail as to how you can build this into a Docker image and host it on Gitlab itself.
Hopefully that helps!
UPDATE - 4/10/2017
I wrote the canonical blog post for setting up Android builds in Gitlab CI back in November '16 for the official Gitlab blog. Includes details on how to run tests and such as well. Linking here.
https://about.gitlab.com/2016/11/30/setting-up-gitlab-ci-for-android-projects/
You can add a build step to your GitLab CI project as below.
gradle assemble
This will generate debug and release APK's of the commit pushed at:
/build/outputs/apk/
You could then write a script to archive the generated APK's however you require.

Categories

Resources