使用同一罐子的多个模块 [英] Multiple modules using the same jar

查看:53
本文介绍了使用同一罐子的多个模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含多个模块的项目.一些模块依赖于同一个jar.现在,每个模块都有自己的"libs"文件夹,其中包含2个相同库的jar.更新jar文件可能会出现问题,因为我现在必须更改所有模块中的所有jar.另外,我遇​​到一个编译问题,说有重复的类.一种解决方法是从除一个模块之外的所有模块中删除jar文件.这是唯一的方法还是有更好的方法?

I have a project with several modules. Some modules depends on the same jar. Right now each of the modules have their own "libs" folder containing 2 jars of the same library. Updating a jar file can be problematic since I will now have to change all the jars from all of the modules. Also, I encounter a compilation problem saying that there are duplicate classes. One workaround is to remove the jar files from all of the modules except for one. Is this the only way to do it or is there a better way?

推荐答案

我已经能够解决此问题.此阅读有关Gradle的信息对我有很大帮助.这是我所做的:

I have been able to fix this issue. This reading about Gradle helped me a lot. Here is what I have done:

我没有将JAR file放入moduleA/libs folder中,而是通过单击project then right click -> new -> moduleJAR file导入了Android Studio中.然后,我单击Import .JAR/.AAR package.这样创建了module containing the JAR file + a gradle script.

Instead of putting the JAR file in moduleA/libs folder, I have imported the JAR file in Android Studio by clicking on the project then right click -> new -> module. I then clicked on Import .JAR/.AAR package. This created a module containing the JAR file + a gradle script.

然后,在moduleA’s gradle script中,我已将其添加到dependencies中:compile project(path: ':name_of_the_jar_file')

Then, in moduleA’s gradle script, I have added this in the dependencies: compile project(path: ':name_of_the_jar_file')

我重新构建了所有文件,并且一切正常. JAR file现在出现在APK中,并且在运行时不再崩溃.

I rebuilt all and it works. The JAR file is now present in the APK and there is no more crash at runtime.

这篇关于使用同一罐子的多个模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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