How to release an AAR with another android library project dependency?

让人想犯罪 __ 提交于 2019-12-03 10:32:19

问题


Here is my development project structure:

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
  }
}

And here is the build.gradle of MyLib:

dependencies {
  compile fileTree(dir: 'libs', include: ['*.jar'])
  compile project(':Libraries:LibA')
}

How can I release MyLib with LibA already packaged in the AAR?


回答1:


Answer the question myself. finally I changed the build.gradle in MyLib to:

dependencies {
  compile fileTree(dir: 'libs', include: ['*.jar'])
  provided project(':Libraries:LibA')
}

so LibA will only be used in the build process of MyLib, TestProj will not ask for the LibA dependency anymore at compile time. NOTE THAT this may cause NoClassDefFoundError at runtime, so you must told the guys who used your library to include the LibA themselves in build.gradle of their project.

At first, I was looking for a method to package LibA with MyLib, but it seems diffcult.

See this question: Android Studio how to package single AAR from multiple library projects?



来源:https://stackoverflow.com/questions/26828163/how-to-release-an-aar-with-another-android-library-project-dependency

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!