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

时间:2015-12-30 15:07:45

标签: android android-studio unity3d unity5

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

enter image description here

然后,我生成了模块,并且我已经获得了文件' 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 个答案:

答案 0 :(得分:10)

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

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

要将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将libs/中放置的每个JAR文件视为与您的库捆绑在一起的依赖项,但classes.jar除外,它仅用于编译您的库。

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