Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use support library in android projects and library (Android Studio)

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?

like image 713
rekire Avatar asked May 16 '13 09:05

rekire


1 Answers

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.

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.

Hope this helps!

like image 153
DanO Avatar answered Oct 21 '22 07:10

DanO