Android external library projects with Gradle

I am trying to create an Android project with Gradle and Android Gradle plugin . I would like to depend on library projects found in maven repositories, for example. ActionBarSherlock.

This is possible according to the official website:

Using the library is done in one of the following ways:

Set up multiple projects. Read here: http://www.gradle.org/docs/current/userguide/multi_project_builds.html

Dependencies through repos like maven or ivy.

The current contents of my build.gradle:

buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.2' } } apply plugin: 'android' repositories { mavenCentral() } dependencies { compile 'com.actionbarsherlock:library:4.2.0' } android { target = 'android-16' sourceSets { main { manifest { srcFile 'AndroidManifest.xml' } java { srcDir 'src' } res { srcDir 'res' } assets { srcDir 'assets' } resources { srcDir 'src' } } } } 

I am using Gradle 1.2. When I try to build using gradle assemble , I get the following error:

 Error: duplicate files during packaging of APK /[path to project]/build/apk/[project name]-debug-unaligned.apk Path in archive: AndroidManifest.xml Origin 1: /[path to project]/build/libs/[apk name]-debug.ap_ Origin 2: /[home directory]/.gradle/caches/artifacts-14/filestore/com.actionbarsherlock/actionbarsherlock/4.2.0/apklib/dd63451a922558005d8c10be1085b488ed731d19/actionbarsherlock-4.2.0.apklib :packageDebug FAILED 

It seems he is trying to include AndroidManifest.xml from the library project and my project. If I remove the manifest specification in sourceSets , I still get the same error.

The site mentions the use of apply plugin: 'android-library' for library projects; I assume that this is only when creating a real library (with multi-project configuration), as this does not create an APK.

How can I make external Android library projects work?

+16
android maven build gradle
Mar 02 '13 at 11:26
source share
3 answers

Although dependencies can be obtained through the Maven or Ivy repository, they are not packaged in the standard Jar archive. There is a new format designed specifically for this build system. Type "aar"

The current Android libraries available on Maven Central were created using the Maven plugin, which uses a different archive format (apklib), so they are incompatible.

If you look at com.actionbarsherlock: actionbacksherlock (which is the new location of this library), you will see that its format is apklib. http://search.maven.org/#artifactdetails%7Ccom.actionbarsherlock%7Cactionbarsherlock%7C4.2.0%7Capklib

Looking at the source code, we check the packaging of "aar" and return for processing all the rest as "jar", which, obviously, is the problem here. We need to detect apklib and provide the best error message.

+20
Mar 13 '13 at 1:23
source share

Now you can integrate ActionBarSherlock as aar.

Just add this to your dependency definition in the build.gradle file:

 dependencies { compile 'com.android.support:support-v4:18.0.+' compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar' 

Jake Wharton has posted a project that shows how to use ActionBarSherlock with Gradle

+14
Aug 10 '13 at
source share

You are using an older version of the android gradle plugin.
In the latest version 0.3, this area has been significantly improved.

I would advise you to upgrade to version 0.3 of this plugin. Also keep in mind that you need to use the newer version of gradle (1.3 or 1.4).

Additional information on how external libraries can be used with this plugin.

-one
Mar 06 '13 at 7:18
source share



All Articles