1

I have created a library (aar) in Android Studio that includes some utility methods that rely on Joda Time classes. I am using the dependency from jcenter with the following line of code in my gradle file

compile 'joda-time:joda-time:2.9.4'

I then added my library to a private maven repository and created a new Android project and added my library to it from this repo.

When I try to use my library's methods in the new project I get the following error:-

java.lang.NoClassDefFoundError: org.joda.time.DateTime

I tried going back to my library and instead of including joda time via jcenter I added the .jar file directly to my 'libs' folder and this time when I tried the methods in my new project they worked and I didn't get the above error.

Does this mean that dependencies are not actually compiled into the aar file when included from jcenter? Is there a way to do so?

omelette
  • 13
  • 3

1 Answers1

2

The AAR file just contains the compiled dex code, manifest (partial) and resources for the library. When you copied the jar file for joda-time into your project, it gets built into the AAR. When using gradle dependencies, gradle (and therefore Android Studio) know how to resolve the joda-time library for building your AAR, but that is it. Since your AAR is being published on jcenter, you need to have a maven manifest for your AAR which also lists joda-time as a dependency. After that projects will be able to list just your library as a dependency and the dependency on joda-time will be resolved by gradle (via its maven support.)

Larry Schiefer
  • 15,687
  • 2
  • 27
  • 33
  • This explained it well thanks. I was using maven-publish and was just publishing the .aar artifact. I added the dependencies to this and it worked. – omelette Jul 07 '16 at 09:34
  • @omelette and Larry, just wanted to bring your attention to https://stackoverflow.com/questions/53876071/how-to-add-a-maven-manifest-to-an-aar-which-specifies-dependencies since I think you've already figured out the answer! Thanks. – ScottyB Jan 04 '19 at 16:19