When building an APK for Android, the DX tool fails in case you attempt to add the same library twice with an error such as this:
当为Android构建APK时,DX工具失败了,如果您试图添加两次错误,比如以下错误:
UNEXPECTED TOP-LEVEL EXCEPTION: java.lang.IllegalArgumentException: already added: Lcom/google/ads/AdRequest$Gender; at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:122) at com.android.dx.dex.file.DexFile.add(DexFile.java:161) at com.android.dx.command.dexer.Main.processClass(Main.java:685) at com.android.dx.command.dexer.Main.processFileBytes(Main.java:634) at com.android.dx.command.dexer.Main.access$600(Main.java:78) at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:572) at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284) at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166) at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229) at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158) at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144) at com.android.dx.command.dexer.Main.processOne(Main.java:596) at com.android.dx.command.dexer.Main.processAllFiles(Main.java:498) at com.android.dx.command.dexer.Main.runMonoDex(Main.java:264) at com.android.dx.command.dexer.Main.run(Main.java:230) at com.android.dx.command.dexer.Main.main(Main.java:199) at com.android.dx.command.Main.main(Main.java:103) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at SDKMain.main(SDKMain.java:129) 1 error; aborting
意想不到的*例外:. lang。IllegalArgumentException:已补充道:Lcom /谷歌/广告/ AdRequest性别美元;add(ClassDefsSection.java:122) at com.android.dx.dx.html . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ., . . . . . . . . . ., . . . . . . . ., . . . . . ., . . . . . ., . . . . . ., . . . .。mso - hansi - font - family: tahoma; mso - hansi - font - family: tahoma; mso - bidi - font - family: tahoma; mso - hansi - font - family: tahoma ' >, < / span > < span lang = en - us在com. android.dx.edu/main.main.main.main.main.main.main.main.main.main.main.main.main.main.main.main.main.main.main.main.main.main (Main.java:103)在sun.reflect.NativeMethodAccessorImpl。invoke0(本机方法)在sun.reflect.nativemethodaccessorrequest .invoke(NativeMethodAccessorImpl.java:62)在sun.reflec . delegate方法accessorrequest .invoke(委托methodaccessorrequest .java:43)在java.lang.reflect.Method.invoke(方法.java:483)在SDKMain.main(SDKMain.java:129) 1错误;流产
What if i have 2 different libraries (jars) that contain classes with the same package name and name ?
如果我有两个不同的库(jar),其中包含具有相同包名和名称的类,那该怎么办?
How can i add these into my APK? Is there any way to do this ?
我如何将这些添加到APK中?有什么办法吗?
1 个解决方案
#1
0
First please note that the "already added" error may pop up even if the two jars are not in the same project. For example: linking your project to a library project containing a jar with same classes.
首先请注意,即使两个jar不在同一个项目中,“已经添加的”错误也会出现。例如:将您的项目链接到一个包含同一个类的jar的库项目。
Secondly: if you do have two jars with the same class file the build system will simply use the first one that it sees. So, if you know which of them you want your runtime to use, the solution is simple: just place it earlier in the classpath. Or visually speaking - place it higher in the Order and Export list:
第二:如果您确实有两个与同一个类文件相同的jar文件,那么构建系统将简单地使用它所看到的第一个。因此,如果您知道您希望运行时使用哪一个,那么解决方案很简单:只需将它放在类路径的前面。或者从视觉上说,把它放在订单和出口清单上:
Thirdly: if you really have no other way, you can always open a jar file (e.e. using WinRAR) and delete some of its class files.
第三,如果你真的没有其他方法,你总是可以打开一个jar文件(使用WinRAR)并删除它的一些类文件。
#1
0
First please note that the "already added" error may pop up even if the two jars are not in the same project. For example: linking your project to a library project containing a jar with same classes.
首先请注意,即使两个jar不在同一个项目中,“已经添加的”错误也会出现。例如:将您的项目链接到一个包含同一个类的jar的库项目。
Secondly: if you do have two jars with the same class file the build system will simply use the first one that it sees. So, if you know which of them you want your runtime to use, the solution is simple: just place it earlier in the classpath. Or visually speaking - place it higher in the Order and Export list:
第二:如果您确实有两个与同一个类文件相同的jar文件,那么构建系统将简单地使用它所看到的第一个。因此,如果您知道您希望运行时使用哪一个,那么解决方案很简单:只需将它放在类路径的前面。或者从视觉上说,把它放在订单和出口清单上:
Thirdly: if you really have no other way, you can always open a jar file (e.e. using WinRAR) and delete some of its class files.
第三,如果你真的没有其他方法,你总是可以打开一个jar文件(使用WinRAR)并删除它的一些类文件。