简体   繁体   English

如何将Android库导出为.aar并保持Gradle依赖关系?

[英]How can I export an Android library as .aar & keep my Gradle dependencies?

I have an Android module from which I export an .aar file. 我有一个Android模块,可以从其中导出.aar文件。 I imported this .aar with Android Studio Wizard, project compiles, but crashes at runtime with "java.lang.NoClassDefFoundError". 我使用Android Studio向导导入了此.aar,进行了项目编译,但在运行时因“ java.lang.NoClassDefFoundError”而崩溃。 I checked with debugger, Class.forName("retrofit2.Retrofit").. not found. 我检查了调试器Class.forName(“ retrofit2.Retrofit”)..找不到。

After unzipping the .aar & checking the classes.jar, I see only my packages, clearly it didn't packaged the libraries I was referencing in build.gradle (ex: Okhttp, Retrofit, Gson.. ). 解压缩.aar并检查classes.jar后,我只看到我的包,显然它没有打包我在build.gradle中引用的库(例如:Okhttp,Retrofit,Gson ..)。

What I want is a way to keep my build.gradle dependencies. 我想要的是一种保持build.gradle依赖关系的方法。 I would prefer it to be packaged into the .aar if possible, else what is the option? 如果可能,我希望将其打包到.aar中,否则有什么选择? Force the client to add in his own gradle my dependencies? 强制客户端添加自己的gradle我的依赖项?

Extra info: I only have gradle dependencies, no jars. 额外信息:我只有gradle依赖项,没有jar。

Distribute the AAR via an artifact repository. 通过工件存储库分发AAR。 The metadata in the artifact repository (eg, the POM file) will contain the information about your transitive dependencies. 工件存储库中的元数据(例如POM文件)将包含有关您的传递依赖项的信息。 It also will have information about the version of your AAR, so that consumers of the AARs have clear information about what version they are using. 它还将提供有关您的AAR版本的信息,以便AAR的使用者可以清楚地了解其使用的版本。 This is how nearly everything else that you are using is distributed: support libraries, Retrofit, etc. 这就是您正在使用的几乎所有其他东西的分布方式:支持库,翻新等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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