Unexpected Top-Level Exception after SDK Update

2019-03-05 18:38发布

I'm working on an Android Project which has an Android Library Project in his Build Path. Both projects have the AdWhirl SDK library in their libs folder and Build Path.

Now since updating android sdk tools to r15 the ant build of the main project fails on following exception:

[dx] UNEXPECTED TOP-LEVEL EXCEPTION:
       [dx] java.lang.IllegalArgumentException: already added: Lcom/adwhirl/AdWhirlLayout$AdWhirlInterface;
       [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

Now i tried to remove the AdWhirl SDK lib from the main project and export it from the Library project. Now the ant build works, but when starting the application from eclipse on any android device, there will be thrown some ClassNotFoundExceptions.

Actually i have the choice to build with ant or debug in eclipse, but i need both variants.

3条回答
Luminary・发光体
2楼-- · 2019-03-05 19:02

From my point of view, Android Library Project is not well-designed even from the very beginning, however, this could not be a real problem for consumer developer, as long as it stays like this and behavior exactly the same during each SDK upgrade.

But it is not, Android dev team started revamp the whole things during several recent release (probably since r14), and promise us a ultimate solution in next coming release. This leaves our continuous development in a extremely unstable stage at the moment, I don't use ant with my projects but had similar sort of problems using Maven manage library change during each SDK upgrade. Looks like Android Dev team even had difficulties manage the changes purely from their official ADT plugin (check out this blog), not to mention the un-official supported build tools like Ant or Maven.

I've done some search for you, there is a thread posted in Android JIRA system which is quite similar to your situation, and come with some workarounds (dirty fix in ant script), check out comments 16 by chris, see if this helps you out.

查看更多
戒情不戒烟
3楼-- · 2019-03-05 19:06

After upgrading to the latest adk, I got a message telling me to run adb refresh to rebuild the ant script. In the latest version of the adk there have been optimizations in the build process. I am assuming one of these optimizations is of the build path.

   [dx] java.lang.IllegalArgumentException: already added: Lcom/adwhirl/AdWhirlLayout$AdWhirlInterface;

Implies AdWhirlLayout$AdWhirlInterface is being added twice. Try removing the AdWhirl SDK from one of the projects. I would try removing it from your Android Project.

"Android Project" imports "Android Library Project" imports "AdWhirl SDK"

instead of

"Android Project" imports "Adwhirl SDK" imports "Android Library Project" imports "AdWhirl SDK"

查看更多
一夜七次
4楼-- · 2019-03-05 19:12

Try adding this jar to the libs directory.

查看更多
登录 后发表回答