这是我的开发项目结构:
projectFolder | +--App | +--MyLib | +--Libraries | +--LibA
MyLib depends on LibA, I have packaged MyLib as an AAR and release it to a Maven repo, But when I include MyLib in another project(TestProj) as a remote aar dependency, I get build error(can't resolve dependency of LibA, LibA is not included with the release of MyLib), This is the build.gradel in app folder of TestProj:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile ('xxx.xxxxxx:yyyyy:1.0-SNAPSHOT@aar'){
transitive = true
}
}
这是 MyLib 的 build.gradle:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':Libraries:LibA')
}
如何在 AAR 中打包了 LibA 的情况下发布 MyLib?
最佳答案
自己回答问题。最后,我将 MyLib 中的 build.gradle 更改为:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
provided project(':Libraries:LibA')
}
所以 LibA 只会在 MyLib 的构建过程中使用,TestProj 不会请求 LibA 编译时不再依赖。请注意,这可能会在运行时导致 NoClassDefFoundError,因此您必须告诉使用您的库的人员将自己的 LibA 包含在他们项目的 build.gradle 中。
起初,我一直在寻找一种将LibA与MyLib打包在一起的方法,但似乎很难。
看到这个问题:Android Studio how to package single AAR from multiple library projects?
关于android - 如何发布具有另一个 android 库项目依赖项的 AAR?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26828163/