Quick Tips: Convert to new Gradle-based build system a project with ActionBarSherlock

I imagine that these days many devs are trying to migrate to the New Build System based on Gradle.
Many "big" open-source projects are still in migration...it still takes a bit of time.

Looking in the forums, everyone was having the same problems...and that consoles me, I am not alone.

Gradle is awesome,but there are many tips to learn, and one of the main pitfalls is that it is not yet able to deal with the most common dependency format for library projects: the maven apklib. Hence the first problem that I have come across.
How to work with actionbarsherlock.

This is a quick tips to use abs with Gradle and AndroidStudio 0.1.3.
The procedure will work for many other library projects.


Create a new project "MyApplicationProject", with a module MyApplication with the standard wizard.
Now you can create a folder "libraries" (the name is not important) and copy ActionBarSherlock source into (or clone from github).
To avoid problems with the support library, I deleted android-support-v4.jar from libs folders.
Now we have this project structure:

Now we can edit gradle files.

settings.gradle
include ':MyApplication'
include ':libraries:actionbarsherlock'
project/build (build.gradle)
buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:0.4.2'
    }
}
abs/build (build.gradle)
apply plugin: 'android-library'

dependencies {
    compile 'com.android.support:support-v4:13.0.0'
}

android {
  compileSdkVersion 17
  buildToolsVersion '17'

  sourceSets {
    main {
      manifest.srcFile 'AndroidManifest.xml'
      java.srcDirs = ['src']
      res.srcDirs = ['res']
    }
  }
}
In dependencies section we specify to use support-library-v4 (version 13).
You have to use gradle plugin version 0.4.2 and you have to update your sdk with 2 last components Android Support Repository, and Google Repository (you can see this Android Developers post on G+)

Now, you have to set "sourceSets" section because ABS is built with Eclipse that have different standard name for resources folders.
app/build (build.gradle)
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.4.2'
    }
}
apply plugin: 'android'

dependencies {
    compile 'com.android.support:support-v4:13.0.0'
    compile project(':libraries:actionbarsherlock')
}

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

    defaultConfig {
        minSdkVersion 7
        versionName '1.0'
        versionCode 1
        targetSdkVersion 17
    }
}
Now click "Sync project with your gradle files".

Wait a little bit.....

You can see process log (and errors!) here:

If everything worked fine... you'll notice the new format in which we all work soon:.aar

Comments

Popular posts from this blog

AntiPattern: freezing a UI with Broadcast Receiver

How to centralize the support libraries dependencies in gradle

NotificationListenerService and kitkat