[aerogear-dev] Android Studio / Gradle support

Marc Sluiter marc at slintes.net
Tue Apr 1 16:54:54 EDT 2014


Hi all,

some time ago there was already a discussion about using Android Studio / Gradle 
[1], but as far as I can see nothing happened afterwards.

So I was curious if I can get the cookbook application running with Android's 
new build system, and want to share what I found out so far:

My first approach was to migrate the cookbook first, and using the library as 
dependency only. But that didn't work out, because the Androd dependencies in 
the pom.xml of the lib could not be found. I really didn't want to install them 
with the maven-android-sdk-deployer, because that's not needed anymore with the 
new build system, it accesses directly the installed Android SDK.

So I migrated the lib first. The first issue was: how do I get the aar into my 
local maven repository? Solution: the Gradle Android Maven plugin [2]. After 
some configuration I could install the lib into my local maven repo with 
"gradlew clean install". Nice.

Then I looked how I can run the Robolectric tests in the lib. That seems to be a 
problem, because the Android Gradle plugin team seems to be focused on running 
tests in AVDs or on real devices only [3]. Then I found another Gradle plugin to 
the rescue... at least I thought: the Robolectric team itself maintains the 
Gradle Android Unit Testing plugin [4], which should run JUnit and Robolectric 
tests, but unfortunatly it was broken by the latest Android Gradle plugin 
update... [5]. So I prepared running the tests, but had to comment out the 
plugin for the moment.

So back to the cookbook: here I had to use a workaround now for accessing my 
local maven repo, because the official and easy way is broken in Gradle itself 
atm [6]. But with the workaround I could run the cookbook app on my device with 
"gradle clean installDebug"... finally :) (And with the OpenShift Push Server it 
was easy to test the push functionality, great!)

So my resume of this adventure:
before that I liked Android Studio very much, I used it for some little private 
fun apps already, and had only few problems. It has features (e.g. product 
flavors) which were more difficult to handle with maven. But I tested only by 
deploying and using the apps on my own devices (shame on me, I know...), so 
missing JUnit/Robolectric support was not an issue for me. And my library 
project was part of the app's project (works nice with Gradle!), so no local 
maven issues.
But now I think that there is still some work to do with Android Studio and the 
Android Gradle plugin. Some gaps can be filled with 3rd party plugins, but the 
chance that they get broken by new versions of the build system is not low, 
development is very fast.

One point I forgot: I did not have a look into the Travis stuff, because I don't 
know it yet.

If you are interested in my results, see here:

https://github.com/slintes/aerogear-android/tree/gradle
https://github.com/slintes/aerogear-android-cookbook/tree/gradle

Kind regards,

Marc


[1] 
http://aerogear-dev.1069024.n5.nabble.com/aerogear-dev-Android-Google-s-Gradle-build-tool-and-AAR-td4508.html
[2] https://github.com/dcendents/android-maven-plugin
[3] http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Testing
[4] https://github.com/robolectric/gradle-android-test-plugin
[5] https://github.com/robolectric/gradle-android-test-plugin/issues/8
[6] https://code.google.com/p/android/issues/detail?id=63908



More information about the aerogear-dev mailing list