Android AAR library depending on another library

Hi, I have an Android library project that creates an AAR.

Everything is fine, but when I use AAR in another project, I get this error:

java.lang.NoClassDefFoundError: com.squareup.picasso.Picasso 

AAR uses picasso, is it possible to export AAR dependencies even when generating one?

+5
java android library-project aar
source share
1 answer

How can I set up a local maven repository.

WARNING: the following recipe works, but it probably can take advantage of improvements since I am far from the Maven expert. I earned this approach last year for use with my CWAC libraries.

Step # 1: add the classpath 'com.github.dcendents:android-maven-plugin:1.0' to the buildscript block dependencies block in the library's project project build.gradle library. Also add version and group instructions to provide this information about your AAR.

Step # 2: use gradle install to compile AAR and install it in the local Maven repository by default.

Step # 3: Usually you add mavenLocal() to the dependencies block of your application project to pick up the AAR through its artifact identifier. This may work again, although it is a little broken. Instead, use maven { url "${System.env.HOME}/.m2/repository" } as a short workaround.

So, for example, your build.gradle library build.gradle might contain:

 buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.9.+' classpath 'com.github.dcendents:android-maven-plugin:1.0' } } apply plugin: 'android-library' apply plugin: 'android-maven' version '0.4.0' group 'some.likely.group.name.goes.here' repositories { mavenCentral() } dependencies { compile 'com.squareup.picasso:picasso:2.2.0' compile fileTree(dir: 'libs', include: '*.jar') } android { // as normal } 

You must use gradle install to publish the JAR in your local Maven repository. Then your application project will have the following material in build.gradle :

 buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.9.+' } } apply plugin: 'android' repositories { mavenCentral() maven { url "${System.env.HOME}/.m2/repository" } // mavenLocal() } dependencies { compile 'some.likely.group.name.goes.here:name-of-library:0.4.0' } android { // as normal } 

where do you replace:

  • some.likely.group.name.goes.here with something

  • 0.4.0 with version number in XYZ format

  • name-of-library will be the name of the directory containing the Android library project (e.g. presentation or foo )

+6
source share

All Articles