Dalvik可以将匿名内部类转换为dex格式吗?

时间:2013-02-14 11:41:07

标签: dalvik xmlbeans dex anonymous-inner-class

我正在尝试从xmlbeans-2.6.0.jar和xmlbeans-2.3.0.jar构建dex文件。我收到以下错误

[2013-02-14 14:57:08 - SOSTestProject] Dx warning: Ignoring InnerClasses attribute for an anonymous inner class
(org.apache.xmlbeans.impl.store.Locale$1) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.

[2013-02-14 14:57:08 - SOSTestProject] Dx 
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Lorg/apache/xmlbeans/xml/stream/Location;
[2013-02-14 14:57:08 - SOSTestProject] Dx   at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123)
[2013-02-14 14:57:08 - SOSTestProject] Dx   at com.android.dx.dex.file.DexFile.add(DexFile.java:163)
[2013-02-14 14:57:08 - SOSTestProject] Dx   at com.android.dx.command.dexer.Main.processClass(Main.java:490)
[2013-02-14 14:57:08 - SOSTestProject] Dx   at com.android.dx.command.dexer.Main.processFileBytes(Main.java:459)
[2013-02-14 14:57:08 - SOSTestProject] Dx   at com.android.dx.command.dexer.Main.access$400(Main.java:67)
[2013-02-14 14:57:08 - SOSTestProject] Dx   at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:398)
[2013-02-14 14:57:08 - SOSTestProject] Dx   at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:245)
[2013-02-14 14:57:08 - SOSTestProject] Dx   at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:131)
[2013-02-14 14:57:08 - SOSTestProject] Dx   at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:109)
[2013-02-14 14:57:08 - SOSTestProject] Dx   at com.android.dx.command.dexer.Main.processOne(Main.java:422)
[2013-02-14 14:57:08 - SOSTestProject] Dx   at com.android.dx.command.dexer.Main.processAllFiles(Main.java:333)
[2013-02-14 14:57:08 - SOSTestProject] Dx   at com.android.dx.command.dexer.Main.run(Main.java:209)
[2013-02-14 14:57:08 - SOSTestProject] Dx   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[2013-02-14 14:57:08 - SOSTestProject] Dx   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
[2013-02-14 14:57:08 - SOSTestProject] Dx   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
[2013-02-14 14:57:08 - SOSTestProject] Dx   at java.lang.reflect.Method.invoke(Unknown Source)
[2013-02-14 14:57:08 - SOSTestProject] Dx   at com.android.ide.eclipse.adt.internal.build.DexWrapper.run(DexWrapper.java:187)
[2013-02-14 14:57:08 - SOSTestProject] Dx   at com.android.ide.eclipse.adt.internal.build.BuildHelper.executeDx(BuildHelper.java:745)
[2013-02-14 14:57:08 - SOSTestProject] Dx   at com.android.ide.eclipse.adt.internal.build.builders.PostCompilerBuilder.build(PostCompilerBuilder.java:598)
[2013-02-14 14:57:08 - SOSTestProject] Dx   at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:728)
[2013-02-14 14:57:08 - SOSTestProject] Dx   at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
[2013-02-14 14:57:08 - SOSTestProject] Dx   at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:199)
[2013-02-14 14:57:08 - SOSTestProject] Dx   at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:321)
[2013-02-14 14:57:08 - SOSTestProject] Dx   at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:396)
[2013-02-14 14:57:08 - SOSTestProject] Dx   at org.eclipse.core.internal.resources.Project$1.run(Project.java:618)
[2013-02-14 14:57:08 - SOSTestProject] Dx   at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2344)
[2013-02-14 14:57:08 - SOSTestProject] Dx   at org.eclipse.core.internal.resources.Project.internalBuild(Project.java:597)
[2013-02-14 14:57:08 - SOSTestProject] Dx   at org.eclipse.core.internal.resources.Project.build(Project.java:124)
[2013-02-14 14:57:08 - SOSTestProject] Dx   at com.android.ide.eclipse.adt.internal.project.ProjectHelper.doFullIncrementalDebugBuild(ProjectHelper.java:1046)
[2013-02-14 14:57:08 - SOSTestProject] Dx   at com.android.ide.eclipse.adt.internal.launch.LaunchConfigDelegate.launch(LaunchConfigDelegate.java:147)
[2013-02-14 14:57:08 - SOSTestProject] Dx   at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:855)
[2013-02-14 14:57:08 - SOSTestProject] Dx   at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:704)
[2013-02-14 14:57:08 - SOSTestProject] Dx   at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:1047)
[2013-02-14 14:57:08 - SOSTestProject] Dx   at org.eclipse.debug.internal.ui.DebugUIPlugin$8.run(DebugUIPlugin.java:1251)
[2013-02-14 14:57:08 - SOSTestProject] Dx   at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
[2013-02-14 14:57:08 - SOSTestProject] Dx 1 error; aborting
[2013-02-14 14:57:08 - SOSTestProject] Conversion to Dalvik format failed with error 1

我认为DVM无法将匿名内部类转换为.dex格式。如果有人可以提供帮助,那将非常有用。

1 个答案:

答案 0 :(得分:2)

匿名内部类没有问题。正如警告所提到的,这几乎肯定是一种较旧的类文件格式,并且警告可能会被忽略。

该错误与正在添加到您尝试创建的dex文件的类集中存在多个所提及类的副本有关。

根据您提供的稀疏信息,我猜测您将jar的两个版本都放入项目的lib目录中。这不会起作用,因为dex文件不能包含类的多个副本(即1.3版本和1.6版本)。

如果您必须同时拥有这两个版本,则需要重命名其中一个库中的类。例如,您可以使用jarjar工具自动更改类的包名称。