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
771 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 Reply

0 votes
by (71.8m points)

try using the transitive attribute:

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

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

...