Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

maven - How do I ship an Android Library (aar) with remote dependencies (gradle)?

I am trying to build an aar file with gradle that has remote dependencies. An example build script is below. As you can see I have two dependencies. The problem I'm having is when I do a release, the aar file does not contain the remote dependencies, so when I include the aar file in other projects I get NoClassDefFound errors.

I found that if I copy the jar from my local maven repo to a libs folder in my project, then the jar does get included in the release aar. How do I include the remote dependencies in the aar file? I've also read elsewhere that it's bad practice to ship dependencies like this, so if there's a better way to do what I'm trying to do I'm all for it.

buildscript {

    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.9.+'
    }
}

apply plugin: 'android-library'

repositories {
    mavenCentral()
    mavenLocal()
}

android {
... omitted for brevity
}

dependencies {
    compile 'com.somepackage:someartifact:1.0'
    compile 'com.anotherpackage:artifact:2.0'
}
See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

try using the transitive attribute:

compile ('group_id:artifact_id:version_name@aar'){
    transitive = true
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...