36

My app depends on a library project. This library project depends on the Android Compatibility Package V4. I have NOT exported the library project's dependency. In my own project, I've added ACL V13 as a dependency, but when compiling I get the error that essentially there's a duplicate dependency. I thought not exporting the library project's dependency would resolve this issue, but it's not.

How can I resolve this?

EDIT

Also, according to Android tools docs:

Special case for android-support-v4.jar and android-support-v13.jar.

We make a special case for these two libraries because -v13 contains a full version of -v4 inside. If both are found, then only -v13 will be used.

So it should just work...

LuxuryMode
  • 33,401
  • 34
  • 117
  • 188
  • Do you have detailed trace? It should mention which class Already added.. – Yasitha Waduge Mar 13 '13 at 14:09
  • You use eclipse or intelij idea? – Yasitha Waduge Mar 13 '13 at 14:10
  • @vmerror, intellij and Android Dex: [abc] java.lang.IllegalArgumentException: already added: Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat; – LuxuryMode Mar 13 '13 at 14:11
  • Create "ACL V4", and "ACL V13" as global libraries, in Project Structure add those libraries to modules, – Yasitha Waduge Mar 13 '13 at 14:17
  • @vmerror that doesn't resolve the issue. Anyways, why would I want to add as global projects. The library should be in /libs, no? – LuxuryMode Mar 13 '13 at 14:20
  • Usually if particular library is used in several modules, better to create Project level library and add it to required modules, I had the same issue and resolved it. eclipse there is no issue since it will automatically detect jar file from libs folder. – Yasitha Waduge Mar 13 '13 at 14:28
  • Looks like I messed something else up, somehow. Even when I removed the V13 one I still get the error. gotta figure out where the duplicate is coming from. – LuxuryMode Mar 13 '13 at 14:29
  • so you can create ACL_V13 as a project library, no need to add ACL_V4 as you mentioned in edited question. – Yasitha Waduge Mar 13 '13 at 14:29
  • you possible cz same v4 jar file is referenced from different locations. – Yasitha Waduge Mar 13 '13 at 14:31

6 Answers6

19

If you use exactly the same lib jar in different projects (libs project or standard projects), the apk tools get rid automatically of the duplicate ones.

The problem starts when you have two libs with the same name but not at the same revision.

The android-support-v4.jar and android-support-v13.jar files can be from different revision since there always have the same name in different support package release (http://developer.android.com/tools/extras/support-library.html#Notes)

I would check that you use exactly the same revision of the support libs in your main project and in your lib project.

To make sure, copy the two support libraries jars (located in the android-sdk folder) to your projects libs folder.

{android-sdk}/extras/android/support/v4/android-support-v4.jar
AND
{android-sdk}/extras/android/support/v13/android-support-v13.jar

It should get rid of the problem.

ol_v_er
  • 27,094
  • 6
  • 48
  • 61
  • 1
    This did not work for me. user1834249's answer is the solution that solves this problem. By making a common library that all modules use to get the android-support-v4.jar, IntelliJ/dex recognizes that it's the same thing. I think this is probably a bug with the integration of IntelliJ and the dex compiler. – kevinmrohr Dec 04 '13 at 15:05
8

Delete the v4 package from the library.

Clean the Projects.

Aditya Kushwaha
  • 839
  • 6
  • 12
4

In my case, I had just updated one of the JARs in the libs/ folder to a new version.

All it took to fix it was to run Build -> Rebuild Project, i.e. issue a 'clean' task before the 'assembleDebug' etc.

Giorgos Kylafas
  • 2,243
  • 25
  • 25
3

Well, in my story I had to delete module dependencies which were the same, add it in library, and then add this library to each module as a dependence.

So:

  • Module a : Depends on android-v4 (and has it in it's lib folder)
  • Module b : Depends on android-v4 (and has it in it's lib folder)

    1. Add to libraries of project "android-v4" (for ex from 1st module). Delete it in module b lib folder.

    2. Delete in modules a and b dependence of android-v4

    3. Add to each module dependence -> library -> android-v4 (which you created in 2 step)

I'm not sure if it is the right solution but it works.

1

Have you tried to change the dependency of the library from v4 to v13 and export it?

alexei burmistrov
  • 1,417
  • 10
  • 13
0

Sometimes simply removing v4 support library does not work, you also need to rebuild or the project.

Ivan V
  • 3,024
  • 4
  • 26
  • 36