10

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?

2
  • Running into the same problem. Any luck? Nov 25, 2014 at 15:42
  • @lostintranslation , I post a answer, hope it helps. Nov 27, 2014 at 13:34

1 Answer 1

8

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?

5
  • MyLib's POM should have LibA declared as a dependency, which should solve the problem. Nov 27, 2014 at 13:39
  • LibA is a Library project and it is not on maven central, if other people want to use MyLib, how can gradle auto resolve the dependency? Nov 27, 2014 at 13:46
  • It should be published to some public or internal Maven repository. If this is an OSS project, Bintray offers a personal Maven repo for free. Nov 27, 2014 at 14:53
  • 2
    its 'provided', not 'provide', but this is apparently too short to be an edit.
    – Philipp E.
    Dec 15, 2014 at 13:58
  • So there is no way of attaching an .aar code sources in your lib also released as .aar ?
    – Adam Styrc
    Aug 17, 2015 at 13:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.