是否将来自jcenter的依赖项编译到aar库中? [英] Are dependencies from jcenter compiled into aar library?

查看:77
本文介绍了是否将来自jcenter的依赖项编译到aar库中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android Studio中创建了一个库(aar),其中包括一些依赖于Joda Time类的实用程序方法.我在gradle文件中将jcenter的依赖关系与以下代码行一起使用

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

编译'joda-time:joda-time:2.9.4'

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

然后,我将我的库添加到私有Maven存储库,并创建了一个新的Android项目,并从此存储库中将我的库添加到了它.

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

我尝试回到我的库,而不是通过jcenter包括joda时间,而是将.jar文件直接添加到我的"libs"文件夹中,这一次,当我在新项目中尝试这些方法时,它们却起作用了,出现上述错误.

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.

这是否意味着从jcenter包含依赖项时,它们实际上并没有编译到aar文件中?有办法吗?

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

推荐答案

AAR文件仅包含编译的dex代码,清单(部分)和库资源.当您将jar文件进行joda-time复制到您的项目中时,它将被内置到AAR中.使用gradle依赖项时,gradle(以及因此的Android Studio)知道如何解析joda-time库来构建AAR,仅此而已.由于您的AAR是在jcenter上发布的,因此您需要为AAR提供一个Maven清单,该清单也将joda-time列为依赖项.之后,项目将能够仅将您的库作为依赖项列出,而对joda-time的依赖关系将通过gradle(通过其maven支持)解决.

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

这篇关于是否将来自jcenter的依赖项编译到aar库中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆