在android项目和库中使用支持库(Android Studio) [英] Use support library in android projects and library (Android Studio)

查看:206
本文介绍了在android项目和库中使用支持库(Android Studio)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用新的Android Studio,正在寻找一种使用多个项目中的支持​​库的方法。基本上,我有一个使用 ActionBarSherlock 的项目,该项目需要支持库。因此,我在此问题中添加了参考。

I'm using the new Android Studio, I'm looking for a way to use the support library from multiple projects. Basically I have a project that uses the ActionBarSherlock this projects requires the support library. So I added a reference as like in this question.

现在,我的主项目也使用了支持库,因此我以某种方式包含了两次支持库。如果我从这两个项目之一中删除该库,则会收到一些错误,指出与支持库相关的某些类是未知的,这对我来说很明显,但是如果我在这两个项目中都有引用,则会遇到此错误:

Now I have the problem that my main project also uses the support library so I have it includes twice in some way. If I remove the library from one of both projects I'll get errors that some support library related classes are unknown which is clear for me, but if I have a reference in both projects I'll face this error:

Android Dex: [ProjectName] UNEXPECTED TOP-LEVEL EXCEPTION:
Android Dex: [ProjectName] java.lang.IllegalArgumentException: already added: Landroid/support/v4/app/ShareCompat$ShareCompatImplJB;
Android Dex: [ProjectName] at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123)
Android Dex: [ProjectName] at com.android.dx.dex.file.DexFile.add(DexFile.java:163)
Android Dex: [ProjectName] at com.android.dx.command.dexer.Main.processClass(Main.java:490)
Android Dex: [ProjectName] at com.android.dx.command.dexer.Main.processFileBytes(Main.java:459)
...

有什么办法解决这个问题吗?

Any idea how to fix this?

推荐答案

我通过进入文件>项目结构... ,然后选择模块,然后单击模块的依赖项标签。然后在库旁边,将范围从 Compile 更改为已提供

I fixed this by going into File > Project Structure... and selecting Modules then click on the module's Dependencies tab. Then next to the library I changed the scope from Compile to Provided.

这意味着该模块仍然可以使用它,但是由于尚未实现编译,因为我认为您已经在主项目中使用了该JAR。

This means the module can still use it, but it doesn't reach compile, since I assume you are already using that JAR in your main project.

希望这会有所帮助!

这篇关于在android项目和库中使用支持库(Android Studio)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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