Two Android libraries duplicate the same jar - Ant build error

I have a project that uses two independent Android libraries. Each of them contains an Android support package, so ant build does not work in the dex step:

[dx] UNEXPECTED TOP-LEVEL EXCEPTION: [dx] java.lang.IllegalArgumentException: already added: Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat; [dx] at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123) [dx] at com.android.dx.dex.file.DexFile.add(DexFile.java:163) [dx] at com.android.dx.command.dexer.Main.processClass(Main.java:486) [dx] at com.android.dx.command.dexer.Main.processFileBytes(Main.java:455) [dx] at com.android.dx.command.dexer.Main.access$400(Main.java:67) [dx] at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:394) [dx] at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:245) [dx] at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:131) [dx] at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:109) [dx] at com.android.dx.command.dexer.Main.processOne(Main.java:418) [dx] at com.android.dx.command.dexer.Main.processAllFiles(Main.java:329) [dx] at com.android.dx.command.dexer.Main.run(Main.java:206) [dx] at com.android.dx.command.dexer.Main.main(Main.java:174) [dx] at com.android.dx.command.Main.main(Main.java:95) [dx] 1 error; aborting 

What should I do?

I am going to transfer one of these jar files from the libs folder to the -post-compile target. And then move it back after completing the dex step. What are your recommendations?

UPDATE: I tried moving the support package from one library to -post-compile , but still fails due to another reason. This jar is already included in the path that is being processed by the dex task. And the dex task cannot open the remote jar.

+6
source share
2 answers

The fix is โ€‹โ€‹already implemented in the ADT-r17 preview builds.

More details here: http://tools.android.com/recent/dealingwithdependenciesinandroidprojects

+5
source

You should avoid having the same library in both. Can't you exclude one support package by specifically using wildcards from one of the libraries when compiling your project? Filtering it out with proguard, for example:

 -libraryjars ${android.libraryjars}(!org/xmlpull/v1/XmlPullParser.class,!org/xmlpull/v1/XmlPullParserException.class,!META-INF/MANIFEST.MF,!META-INF/NOTICE.txt,!META-INF/LICENSE.txt) 
+1
source

Source: https://habr.com/ru/post/911224/


All Articles