Circle CI and Constraint Layout
I recently decided to use Circle CI as Continuous Integration for my Android project.
I opened circleci’s website click sign up choose my GitHub account configured my project…and build failed.
The problem was with the license agreements which I didn’t accept (yeah right how do I suppose to accept those?)
Fast googling showed me several solutions which worked perfect except the fact that they didn’t.
First attempt
To accept the license agreements I added one line in circle.yml:
- echo yes | android update sdk --no-ui --all -filter "android-25,build-tools-25.0.0,extra-android-m2repository"
Apparently for simple project it might be enough, mine wasn’t so simple…
Second attempt
The problem was with the Constraint Layout library:
You have not accepted the license agreements of the following SDK components: [ConstraintLayout for Android 1.0.2, Solver for ConstraintLayout 1.0.2]
So I found better solution with caching from circleci employee (at least title said so):
dependencies:
pre:
# Android SDK Platform 25
- 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.0
- if [ ! -d "/usr/local/android-sdk-linux/build-tools/25.0.5" ]; then echo y | android update sdk --no-ui --all --filter "build-tools-25.0.5"; fi
# Android Support Repository, revision 39 / Local Maven repository for Support Libraries
- 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/platforms/android-25
- /usr/local/android-sdk-linux/build-tools/25.0.0
- /usr/local/android-sdk-linux/extras/android/m2repository
Ok he said that it should work…trying…failed.
Third attempt
Some guy in the stackoverflow said that I need to put licenses from my local machine to circleci…Sounds a bit weird right? Not exactly. In build logs I found interesting 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. 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
Wow even google tried to say me so many time that I can transfer the license agreements and I ignored it. Ok lets put them in circleci!
Final solution
Easiest way to resolve the problem is copy the license agreements to repository and add one copying line in circle.yml.
But I decided to hide the license agreements inside environment variables. I copied everything (1 line actually) from android-sdk-license file and add as a variable in circleci.
And configured circle.yml:
- mkdir -p $ANDROID_HOME/licenses
- echo $ANDROID_SDK_LICENSE > $ANDROID_HOME/licenses/android-sdk-license
Now everything works perfect!
The whole circle.yml file can be found here