简体   繁体   中英

Are dependencies from jcenter compiled into aar library?

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?

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.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM