在Android的项目和libary使用支持库(Android的工作室) [英] Use support library in android projects and libary (Android Studio)

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

问题描述

我使用的是最新的Andr​​oid工作室,我正在寻找一种方式来使用支持库,从多个项目。基本上我有一个使用 ActionBarSherlock 这个项目需要支持库的项目。所以我增加了一个referece像在这个问题

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 referece as like in this question.

现在我有我的主要项目还采用了支持库,所以我把它包括两次在某些方面的问题。如果我从两个项目之一删除libary我会得到错误,一些支持库相关的类是未知这是明确的我,但如果我有这两个项目的参考,我会面对这样的错误:

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 libary 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?

推荐答案

我通过进入文件&gt解决了这个问题;项目结构... 并选择模块然后在模块的依赖设置页。然后旁边的图书馆我改变范围从编译提供

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的项目和libary使用支持库(Android的工作室)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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