2

Feel like Im going mad here - this must be so simple!

I have an android aar which I have built from gradle assembleRelease and also using the maven-publish plugin. I thought that /libs/ was included by default but evidently not.

Android tools site shows its an optional include

http://tools.android.com/tech-docs/new-build-system/aar-format

but for the life of me I don't see where this is configured.

I have asked a related Q Include folder in Gradle artifact but I dont see this as a duplicate as thats a generic gradle question really whereas this is aar specific and may be solved outside of gradle.

Edit I have also asked on the Gradle forum

Community
  • 1
  • 1
Dori
  • 18,283
  • 17
  • 74
  • 116

2 Answers2

5

The aar packages local libraries in libs/ so you need to have local jar dependencies.

dependencies {
  compile fileTree(include: ['*.jar'], dir: 'libs')
}
Xavier Ducrohet
  • 28,383
  • 5
  • 88
  • 64
  • Thats absolutely fantastic thanks. I had tried a few subtle variations of `compile fileTree...` approaches as suggested elsewhere (e.g. https://discuss.gradle.org/t/adding-libs-folder-to-android-aar-release/12334 and http://stackoverflow.com/questions/33243370/include-folder-in-gradle-artifact) without success - but this one works! I have also been using `compile(name:'-x.y.z')` to consume versioned _local_ (/libs/ based) dependencies but this also did not place anything in the compiled aar. Many many thanks! This has been driving me mad (silly I know as so simple...) – Dori Oct 21 '15 at 21:23
  • A related but slightly different question http://stackoverflow.com/questions/33277221/android-library-project-depending-on-other-library-projects if you get a mo :) – Dori Oct 22 '15 at 09:05
  • Is this still the case? I tried several approaches and still can't get the jar included in the final aar – tufyx Jun 02 '17 at 10:42
  • I had related problem - needed to include `libs` with jars inside of my AAR. Here is the solution: https://stackoverflow.com/a/53215936/3313614 – stepio Nov 08 '18 at 20:53
1

When the maven plugin runs uploadArchives then it will create a pom file that tells maven or gradle what dependencies your aar needs. Gradle will handle downloading the jar files and placing them in your class path for the build.

I commented on your other question as well

*reference: https://maven.apache.org/pom.html#Dependencies

*=gradle is backed by maven for dependency management so artifacts available to maven are also available to gradle and vice versa

JBirdVegas
  • 10,855
  • 2
  • 44
  • 50
  • thanks for the answer and have commented on other answer too - I specifically want to include the /libs/ folder in this case as the lib jars wont be available via a remote maven repo - otherwise I wouldve gone that route :) – Dori Oct 20 '15 at 20:53