One auto-download Android dependencies evening

🇺🇦 Eugen Martynov
3 min readNov 14, 2016

--

Our daily Gradle projects are dependent on Android. This is a fact!

We have to use or CI plugins/CI built in functionality/bash scripts or Android SDK manager plugin from Jake Wharton for headache less CI.

But if you follow updates for android build tools, you will notice that from the version 2.2.0-alpha4 we have SDK auto-download. That is great news! Hopefully, my teammate from BE side will be able just to clone android project repository and start contributing immediately. So let’s try it!

I took again a pet project to try “amazing” new thingy. It is open sourced and uses Travis CI as continuous integration (Thank you Travis CI team for great open source support!). Here is the .yaml file:

First of all, I’m upgrading Android Gradle plugin version:

and I’m removing all Travis preparation for the Android build:

The first iteration of commit/wait, and we are getting an error:

A problem occurred configuring project ':app'.> SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.

Ah, let’s quickly fix it:

And after second build attempt, we are getting a new error:

A problem occurred configuring project ':app'.> You have not accepted the license agreements of the following SDK components:[Android SDK Build-Tools 25, Android SDK Platform 25].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

Ah great! We are moving. Thank you Google Android team for giving a hint how to fix the build. So I’m adding license files from my machine and adding a line to copy them to build machine SDK location:

And next build attempt I’m getting new error:

A problem occurred configuring project ':app'.> Could not resolve all dependencies for configuration ':app:_debugApk'.> A problem occurred configuring project ':network'.> Could not resolve all dependencies for configuration ':network:_debugPublishCopy'.> Could not find com.android.support:support-annotations:25.0.0.Required by:android-template-project:network:unspecified > android-template-project:core:unspecified

Wait a minute! It was just downloaded:

Finishing "Install Android Support Repository"Installing Android Support Repository in /home/travis/.android/extras/android/m2repository"Install Android Support Repository" complete.

This is the showstopper! I was able to make the second build run successfully after caching and re-running the build. But why? I’ve created an issue in Google tracker.

So let’s make workaround and hope it will be fixed soon. The issue is that for one of submodules downloaded dependency is not propagated. So I’m going to change dependencies for core submodule and I need also exclude them from all submodules that depend on the core:

And it builds! It is amazing!

Are we done? Not yet. I think, since we have such great tool as Gradle, then all build and automation actions should be available through it. In this particular example, I will move all setup steps to Gradle script. It will save my teammate from BE, who builds project locally, manual installation for the Android SDK. It will also save a lot of time if I decided to migrate the project continuous integration from Travis CI another CI solution.

So, first, we need to check if we have Android SDK location and if we don’t let’s choose a default location:

And let’s also add licenses copying after:

And don’t forget to use it in the root build.gradle:

Wait for the build and it runs!

And, to collect all benefits, let’s also apply similar changes to Circle CI build (Thank you Circle CI for open source support!). And it also works in a similar way!

“That is all folks”©, thank you for reading!

If you like the article, follow me on Medium and Twitter. Or through the new developer social web site GitHub.

Used resources during writing:

--

--

🇺🇦 Eugen Martynov
🇺🇦 Eugen Martynov

Written by 🇺🇦 Eugen Martynov

Stand with Ukraine! The loving XP husband and freelance Android/Kotlin engineer.

Responses (1)