简体   繁体   English

使用jmDNS的Android构建失败

[英]Android build with jmDNS fails

PREAMBLE: since SDK level 16, Android has a built-in Zeroconf implementation. 预警:从SDK级别16开始,Android具有内置的Zeroconf实现。 Unless bronze age compatibility is a concern, don't use jmDNS anymore, use NsdManager instead. 除非担心青铜时代的兼容性,否则不要再使用NsdManager而应使用NsdManager


PREAMBLE #2: early versions of NsdManager are full of glitches, see SO question getSystemService(Context.NSD_SERVICE) freezes the 5.0 emulator and the linked bug records. 预览2:早期版本的NsdManager充满了故障,请参阅问题getSystemService(Context.NSD_SERVICE)冻结了5.0仿真器和链接的错误记录。


I've added jmDNS 3.4.1 to my Android project. 我已经将jmDNS 3.4.1添加到了我的Android项目中。 Copied the JAR under lib , then under "Java BuildPath"/Libraries added a reference. lib下复制了JAR,然后在“ Java BuildPath” / Libraries下添加了参考。

Now my build fails with the following message in Console: 现在我的构建失败,并在控制台中显示以下消息:

[2012-07-27 22:59:07 - Yarxi] Dx 
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Lcom/strangeberry/jmdns/tools/Browser$1;
at 

com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123)
    at com.android.dx.dex.file.DexFile.add(DexFile.java:163)
    at com.android.dx.command.dexer.Main.processClass(Main.java:486)
    at com.android.dx.command.dexer.Main.processFileBytes(Main.java:455)
    at com.android.dx.command.dexer.Main.access$400(Main.java:67)
    at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:394)
    at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:245)
    at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:131)
    at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:109)
    at com.android.dx.command.dexer.Main.processOne(Main.java:418)
    at com.android.dx.command.dexer.Main.processAllFiles(Main.java:329)
    at com.android.dx.command.dexer.Main.run(Main.java:206)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.android.ide.eclipse.adt.internal.build.DexWrapper.run(DexWrapper.java:180)
    at com.android.ide.eclipse.adt.internal.build.BuildHelper.executeDx(BuildHelper.java:703)
    at com.android.ide.eclipse.adt.internal.build.builders.PostCompilerBuilder.build(PostCompilerBuilder.java:577)
    at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:728)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:199)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:321)
    at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:396)
    at org.eclipse.core.internal.resources.Project$1.run(Project.java:618)
    at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2344)
    at org.eclipse.core.internal.resources.Project.internalBuild(Project.java:597)
    at org.eclipse.core.internal.resources.Project.build(Project.java:124)
    at com.android.ide.eclipse.adt.internal.project.ProjectHelper.doFullIncrementalDebugBuild(ProjectHelper.java:1000)
    at com.android.ide.eclipse.adt.internal.launch.LaunchConfigDelegate.launch(LaunchConfigDelegate.java:147)
    at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:854)
    at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:703)
    at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:937)
    at org.eclipse.debug.internal.ui.DebugUIPlugin$8.run(DebugUIPlugin.java:1141)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
[2012-07-27 22:59:10 - Yarxi] Dx 1 error; aborting
[2012-07-27 22:59:10 - Yarxi] Conversion to Dalvik format failed with error 1

And when I look at the JAR contents in the Package Explorer under Referenced Libraries, I see that every class under every package in the jmdns.jar is listed twice. 当我在“引用的库”下的“包资源管理器”中查看JAR内容时,我发现jmdns.jar中每个包下的每个类都列出了两次。 Two copies of JmDNS.class, two copies of JmmDNS.class, and so forth. JmDNS.class的两个副本,JmmDNS.class的两个副本,依此类推。

Any ideas what's wrong with the jar? 任何想法,罐子怎么了? I'm using other jars in the project, none of them act this way. 我在项目中使用了其他jar,它们都不是这种方式。 Tried cleaning a few times, removed and re-added the JAR - same effect. 尝试清洁几次,删除并重新添加JAR-效果相同。

Might be worth noting that this is a library project, and the error pops up when I build the app that refers to the library. 可能值得注意的是,这是一个库项目,并且在构建引用该库的应用程序时会弹出错误。

You Probably used the .jar from SourceForge. 您可能使用了SourceForge中的.jar。 That version has all .class files twice in the .jar and this leads to your error. 该版本在.jar中两次包含所有.class文件,这会导致您的错误。

Try using the .jar from Maven http://search.maven.org/#browse|1991004139 , this should work, I used it earlier this month. 尝试使用Maven http://search.maven.org/#browse|1991004139中的.jar,它应该可以工作,我本月初使用了它。

See if the answer here helps. 看看这里的答案是否有帮助。

Generally speaking, jar file from SourceForge Home Page is malformed and does not work with Android, try using the one from Maven Central Repository , or the dirty workaround mentioned in this blog post . 一般来说, SourceForge主页上的 jar文件格式错误,无法在Android上使用,请尝试使用Maven Central Repository中的 jar文件,或者尝试使用本博客文章中提到的肮脏解决方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM