Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
464 views
in Technique[技术] by (71.8m points)

java - Android Library AAR depending on another library

Hi I have a Android Library Project which produces an AAR.

All is good but when I use the AAR in another project I get this error:

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

The AAR makes use of picasso, is it possible to export the dependencies of the AAR as well when generating one?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

How can one go about setting up a local maven repo.

WARNING: the following recipe works, but probably could use improvement, as I am far from a Maven expert. I hammered out this approach last year for use with my CWAC libraries.

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

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

Step #3: Ordinarily, you would add mavenLocal() to the dependencies block of your application project to pick up the AAR via its artifact ID. That may be working again, though it was broken for a bit. Instead, use maven { url "${System.env.HOME}/.m2/repository" } as a short-term workaround.

So, for example, your library project build.gradle file 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 would use gradle install to publish the JAR to your local Maven repo. Your application project would then have the following stuff in its 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 you replace:

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

  • 0.4.0 with a version number in X.Y.Z format

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...