当前位置:  开发笔记 > Android > 正文

为Unity 3D 5.3构建Android库时出错 - Android Studio

如何解决《为Unity3D5.3构建Android库时出错-AndroidStudio》经验,为你挑选了1个好方法。

我正在使用Android Studio尝试为Unity3d 5.3构建Android库.为此,我创建了一个Android库模块,我添加了classes.jar文件以与UnityPlayer一起使用,如下图所示:

在此输入图像描述

然后,我生成了模块,我得到了'wrapper-debug.aar'文件,我把它放在'\ Assets\Plugins\Android'中.最后,当我构建时,我遇到以下错误:

Error building Player: CommandInvokationFailure: Unable to convert classes   into dex format. See the Console for details.
C:/Program Files/Java/jdk1.8.0_45\bin\java.exe -Xmx2048M -Dcom.android.sdkmanager.toolsdir="C:/Users/.../AppData/Local/Android\tools" -Dfile.encoding=UTF8 -jar "C:\Program Files\Unity\Editor\Data\PlaybackEngines\AndroidPlayer/Tools\sdktools.jar" -

stderr[
Uncaught translation error: java.lang.IllegalArgumentException: already added: Lbitter/jnibridge/JNIBridge;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Lbitter/jnibridge/JNIBridge$a;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/unity3d/player/NativeLoader;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/unity3d/player/ReflectionHelper;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/unity3d/player/ReflectionHelper$1;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/unity3d/player/ReflectionHelper$a;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/unity3d/player/UnityPlayer;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/unity3d/player/UnityPlayer$1;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/unity3d/player/UnityPlayer$10;

UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.RuntimeException: Translation has been interrupted
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:608)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:311)
at com.android.dx.command.dexer.Main.run(Main.java:277)
at com.android.dx.command.dexer.Main.main(Main.java:245)
at com.android.dx.command.Main.main(Main.java:106)
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:497)
at SDKMain.main(SDKMain.java:129)
Caused by: java.lang.InterruptedException: Too many errors
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:600)
... 9 more
]
stdout[
processing archive G:\...\Unity5\Projects\AndroidPlugin\AndroidPlugin\Temp\StagingArea\android-libraries\wrapper-debug\bin\classes.jar...
processing unitywrapper/wrapper/BuildConfig.class...
processing unitywrapper/wrapper/Wrapper.class...
processing archive G:\...\Unity5\Projects\AndroidPlugin\AndroidPlugin\Temp\StagingArea\android-libraries\wrapper-debug\libs\.\classes.jar...
processing bitter/jnibridge/JNIBridge.class...
processing bitter/jnibridge/JNIBridge$a.class...
processing com/unity3d/player/NativeLoader.class...
processing com/unity3d/player/ReflectionHelper.class...
processing com/unity3d/player/ReflectionHelper$1.class...
processing com/unity3d/player/ReflectionHelper$a.class...
processing com/unity3d/player/UnityPlayer.class...
processing com/unity3d/player/UnityPlayer$1.class...
processing com/unity3d/player/UnityPlayer$10.class...
processing com/unity3d/player/UnityPlayer$11.class...
processing com/unity3d/player/UnityPlayer$12.class...
processing com/unity3d/player/UnityPlayer$13.class...
processing com/unity3d/player/UnityPlayer$14.class...
processing com/unity3d/player/UnityPlayer$15.class...
processing com/unity3d/player/UnityPlayer$15$1.class...
processing com/unity3d/player/UnityPlayer$16.class...
processing com/unity3d/player/UnityPlayer$17.class...
processing com/unity3d/player/UnityPlayer$18.class...
processing com/unity3d/player/UnityPlayer$19.class...
processing com/unity3d/player/UnityPlayer$2.class...
processing com/unity3d/player/UnityPlayer$20.class...
processing com/unity3d/player/UnityPlayer$3.class...
processing com/unity3d/player/UnityPlayer$4.class...
processing com/unity3d/player/UnityPlayer$5.class...
processing com/unity3d/player/UnityPlayer$6.class...
processing com/unity3d/player/UnityPlayer$7.class...
processing com/unity3d/player/UnityPlayer$8.class...
processing com/unity3d/player/UnityPlayer$9.class...
processing com/unity3d/player/UnityPlayer$a.class...
processing com/unity3d/player/UnityPlayer$b.class...
processing com/unity3d/player/UnityPlayer$c.class...
processing com/unity3d/player/UnityPlayerActivity.class...
processing com/unity3d/player/UnityPlayerNativeActivity.class...
processing com/unity3d/player/UnityPlayerProxyActivity.class...
processing com/unity3d/player/UnityWebRequest.class...
processing com/unity3d/player/WWW.class...
processing com/unity3d/player/a.class...
processing com/unity3d/player/a$1.class...
processing com/unity3d/player/a$2.class...
processing com/unity3d/player/a$a.class...
processing com/unity3d/player/b.class...
processing com/unity3d/player/b$1.class...
processing com/unity3d/player/b$2.class...
processing com/unity3d/player/c.class...
processing com/unity3d/player/d.class...
processing com/unity3d/player/d$1.class...
processing com/unity3d/player/d$2.class...
processing com/unity3d/player/e.class...
processing com/unity3d/player/f.class...
processing com/unity3d/player/g.class...
processing com/unity3d/player/h.class...
processing com/unity3d/player/i.class...
processing com/unity3d/player/j.class...
processing com/unity3d/player/k.class...
processing com/unity3d/player/k$1.class...
processing com/unity3d/player/k$2.class...
processing com/unity3d/player/k$2$1.class...
processing com/unity3d/player/k$2$1$1.class...
processing com/unity3d/player/l.class...
processing com/unity3d/player/l$1.class...
processing com/unity3d/player/m.class...
processing com/unity3d/player/n.class...
processing com/unity3d/player/n$1.class...
processing com/unity3d/player/o.class...
processing com/unity3d/player/p.class...
processing com/unity3d/player/p$1.class...
processing com/unity3d/player/q.class...
processing com/unity3d/player/r.class...
processing com/unity3d/player/s.class...
processing com/unity3d/player/s$1.class...
processing com/unity3d/player/s$2.class...
processing com/unity3d/player/s$3.class...
processing com/unity3d/player/t.class...
processing com/unity3d/player/u.class...
processing com/unity3d/player/v.class...
processing com/unity3d/player/w.class...
processing com/unity3d/player/w$1.class...
processing org/fmod/FMODAudioDevice.class...
processing org/fmod/a.class...
processing bin\classes\.\com\androidplugin\android\R.class...
processing bin\classes\.\com\androidplugin\android\R$attr.class...
processing bin\classes\.\com\androidplugin\android\R$drawable.class...
processing bin\classes\.\com\androidplugin\android\R$string.class...
processing bin\classes\.\unitywrapper\wrapper\R.class...
processing bin\classes\.\unitywrapper\wrapper\R$attr.class...
processing bin\classes\.\unitywrapper\wrapper\R$drawable.class...
processing bin\classes\.\unitywrapper\wrapper\R$string.class...
processing archive bin\classes.jar...
processing bitter/jnibridge/JNIBridge.class...
processing bitter/jnibridge/JNIBridge$a.class...
processing com/unity3d/player/NativeLoader.class...
processing com/unity3d/player/ReflectionHelper.class...
processing com/unity3d/player/ReflectionHelper$1.class...
processing com/unity3d/player/ReflectionHelper$a.class...
processing com/unity3d/player/UnityPlayer.class...
processing com/unity3d/player/UnityPlayer$1.class...
processing com/unity3d/player/UnityPlayer$10.class...
processing com/unity3d/player/UnityPlayer$11.class...
processing com/unity3d/player/UnityPlayer$12.class...
processing com/unity3d/player/UnityPlayer$13.class...
processing com/unity3d/player/UnityPlayer$14.class...
processing com/unity3d/player/UnityPlayer$15.class...
processing com/unity3d/player/UnityPlayer$15$1.class...
processing com/unity3d/player/UnityPlayer$16.class...
processing com/unity3d/player/UnityPlayer$17.class...
processing com/unity3d/player/UnityPlayer$18.class...
processing com/unity3d/player/UnityPlayer$19.class...
processing com/unity3d/player/UnityPlayer$2.class...
processing com/unity3d/player/UnityPlayer$20.class...
processing com/unity3d/player/UnityPlayer$3.class...
processing com/unity3d/player/UnityPlayer$4.class...
processing com/unity3d/player/UnityPlayer$5.class...
processing com/unity3d/player/UnityPlayer$6.class...
processing com/unity3d/player/UnityPlayer$7.class...
processing com/unity3d/player/UnityPlayer$8.class...
processing com/unity3d/player/UnityPlayer$9.class...
processing com/unity3d/player/UnityPlayer$a.class...
processing com/unity3d/player/UnityPlayer$b.class...
processing com/unity3d/player/UnityPlayer$c.class...
processing com/unity3d/player/UnityPlayerActivity.class...
processing com/unity3d/player/UnityPlayerNativeActivity.class...
processing com/unity3d/player/UnityPlayerProxyActivity.class...
processing com/unity3d/player/UnityWebRequest.class...
processing com/unity3d/player/WWW.class...
processing com/unity3d/player/a.class...
processing com/unity3d/player/a$1.class...
processing com/unity3d/player/a$2.class...
processing com/unity3d/player/a$a.class...
processing com/unity3d/player/b.class...
processing com/unity3d/player/b$1.class...
processing com/unity3d/player/b$2.class...
processing com/unity3d/player/c.class...
processing com/unity3d/player/d.class...
processing com/unity3d/player/d$1.class...
processing com/unity3d/player/d$2.class...
processing com/unity3d/player/e.class...
processing com/unity3d/player/f.class...
processing com/unity3d/player/g.class...
processing com/unity3d/player/h.class...
processing com/unity3d/player/i.class...
processing com/unity3d/player/j.class...
processing com/unity3d/player/k.class...
processing com/unity3d/player/k$1.class...
processing com/unity3d/player/k$2.class...
processing com/unity3d/player/k$2$1.class...
processing com/unity3d/player/k$2$1$1.class...
processing com/unity3d/player/l.class...
processing com/unity3d/player/l$1.class...
processing com/unity3d/player/m.class...
processing com/unity3d/player/n.class...
processing com/unity3d/player/n$1.class...
processing com/unity3d/player/o.class...
processing com/unity3d/player/p.class...
processing com/unity3d/player/p$1.class...
processing com/unity3d/player/q.class...
processing com/unity3d/player/r.class...
processing com/unity3d/player/s.class...
processing com/unity3d/player/s$1.class...
processing com/unity3d/player/s$2.class...
processing com/unity3d/player/s$3.class...
processing com/unity3d/player/t.class...
processing com/unity3d/player/u.class...
processing com/unity3d/player/v.class...
processing com/unity3d/player/w.class...
processing com/unity3d/player/w$1.class...
processing org/fmod/FMODAudioDevice.class...
processing org/fmod/a.class...
]

我能理解的是,我正在添加已经添加的类.问题在于文件classes.jar.如果我把它取下来,插件工作正常但没有它,我不能在我的库中使用unityPlayer,这是我真正需要的东西.

另一种方法是做一个.jar库,但在这种情况下,我必须将res文件夹放在Unity的android插件文件夹中,但这是不推荐的.

还有另一种方法可以使用Android 5.x的android库吗?

非常感谢你如果您需要更多信息,请告诉我.



1> Leo Nikkilä..:

Unity在构建应用程序时会自动将其自己的类添加到项目中.如果将它们与库捆绑在一起,它们将被添加两次.

provided除了compile您当前使用的配置之外,Android的Gradle插件还定义了一个被调用的配置.它在某种意义上是不同的,它假设依赖项将在运行时出现在应用程序的类路径上,并且不包括构建库中的类.

要使用该provided特定JAR 的配置,请替换这两行

compile fileTree(include: ['*.jar'], dir: 'libs')

compile files('libs/classes.jar')

用这些

compile fileTree(dir: 'libs', include: ['*.jar'], exclude: ['classes.jar'])

provided files('libs/classes.jar')

这将使Gradle将放置在其中的每个JAR文件libs/视为与库捆绑在一起的依赖项,但classes.jar仅用于编译库.

请注意,如果您使用的是Android的摇篮插件3.0.0或更高版本,你应该使用implementation,而不是compilecompileOnly代替provided.这些配置已重命名:https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration#new_configurations.

推荐阅读
mylvfamily
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有