我在将UnityPlayer
依赖项放入Unity的Android库插件时遇到问题。
我只是想不出向插件添加依赖项的正确方法。
在尝试将classes.jar
文件添加到我的libs
目录之前,该文件包含所有UnityPlayer代码,这使我到了可以编写代码而没有智能感知错误的地步,但是当我构建并运行,我得到大量输出。
CommandInvokationFailure: Gradle build failed.
C:\Program Files\Unity\Hub\Editor\2018.4.14f1\Editor\Data\PlaybackEngines\AndroidPlayer/Tools\OpenJDK\Windows\bin\java.exe -classpath "C:\Program Files\Unity\Hub\Editor\2018.4.14f1\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-5.1.1.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx4096m" "assembleRelease"
stderr[
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':checkReleaseDuplicateClasses'.
> 1 exception was raised by workers:
java.lang.RuntimeException: Duplicate class bitter.jnibridge.JNIBridge found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class bitter.jnibridge.JNIBridge$a found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.NativeLoader found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.ReflectionHelper found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.ReflectionHelper$1 found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.ReflectionHelper$a found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.UnityPlayer found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.UnityPlayer$1 found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.UnityPlayer$10 found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.UnityPlayer$11 found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.UnityPlayer$12 found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.UnityPlayer$13 found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.UnityPlayer$14 found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.UnityPlayer$15 found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.UnityPlayer$16 found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.UnityPlayer$17 found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.UnityPlayer$18 found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.UnityPlayer$19 found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.UnityPlayer$2 found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.UnityPlayer$3 found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.UnityPlayer$4 found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.UnityPlayer$5 found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.UnityPlayer$6 found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.UnityPlayer$7 found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.UnityPlayer$8 found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.UnityPlayer$9 found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.UnityPlayer$a found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.UnityPlayer$b found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.UnityPlayer$c found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.UnityPlayerActivity found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.a found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.a$1 found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.a$2 found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.a$a found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.b found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.c found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.d found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.e found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.f found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.g found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.h found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.i found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.j found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.k found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.k$1 found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.l found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.m found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.n found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.o found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.p found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.q found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.q$1 found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.q$2 found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class com.unity3d.player.q$3 found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class org.fmod.FMODAudioDevice found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Duplicate class org.fmod.a found in modules classes-2.jar (:coffeeplugin-release:) and unity-classes.jar (unity-classes.jar)
Go to the documentation to learn how to <a href="d.android.com/r/tools/classpath-sync-errors">Fix dependency resolution errors</a>.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 8s
]
stdout[
> Task :preBuild UP-TO-DATE
> Task :preReleaseBuild UP-TO-DATE
> Task :compileReleaseAidl NO-SOURCE
> Task :compileReleaseRenderscript NO-SOURCE
> Task :checkReleaseManifest UP-TO-DATE
> Task :generateReleaseBuildConfig UP-TO-DATE
> Task :prepareLintJar UP-TO-DATE
> Task :generateReleaseSources UP-TO-DATE
> Task :javaPreCompileRelease
> Task :mainApkListPersistenceRelease UP-TO-DATE
> Task :generateReleaseResValues UP-TO-DATE
> Task :generateReleaseResources UP-TO-DATE
> Task :mergeReleaseResources UP-TO-DATE
> Task :createReleaseCompatibleScreenManifests UP-TO-DATE
> Task :processReleaseManifest
> Task :processReleaseResources
> Task :compileReleaseJavaWithJavac
> Task :compileReleaseSources
> Task :lintVitalRelease
> Task :mergeReleaseShaders UP-TO-DATE
> Task :compileReleaseShaders UP-TO-DATE
> Task :generateReleaseAssets UP-TO-DATE
> Task :mergeReleaseAssets
> Task :validateSigningRelease UP-TO-DATE
> Task :signingConfigWriterRelease UP-TO-DATE
> Task :checkReleaseDuplicateClasses FAILED
Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.1.1/userguide/command_line_interface.html#sec:command_line_warnings
19 actionable tasks: 7 executed, 12 up-to-date
]
exit code: 1
UnityEditor.Android.Command.WaitForProgramToRun (UnityEditor.Utils.Program p, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <f92457847c324e90907abe57dde6951d>:0)
UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <f92457847c324e90907abe57dde6951d>:0)
UnityEditor.Android.Command.Run (System.String command, System.String args, System.String workingdir, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <f92457847c324e90907abe57dde6951d>:0)
UnityEditor.Android.AndroidJavaTools.RunJava (System.String args, System.String workingdir, System.Action`1[T] progress, System.String error) (at <f92457847c324e90907abe57dde6951d>:0)
UnityEditor.Android.GradleWrapper.Run (UnityEditor.Android.AndroidJavaTools javaTools, System.String workingdir, System.String task, System.Action`1[T] progress) (at <f92457847c324e90907abe57dde6951d>:0)
Rethrow as GradleInvokationException: Gradle build failed
UnityEditor.Android.GradleWrapper.Run (UnityEditor.Android.AndroidJavaTools javaTools, System.String workingdir, System.String task, System.Action`1[T] progress) (at <f92457847c324e90907abe57dde6951d>:0)
UnityEditor.Android.PostProcessor.Tasks.BuildGradleProject.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <f92457847c324e90907abe57dde6951d>:0)
UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <f92457847c324e90907abe57dde6951d>:0)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr) (at C:/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:179)
我几乎看到了重复的错误,所以我猜想我的Android Studio项目中的classes.jar
中已经包含了所有内容。我从Unity导出的项目中构建了项目,然后在Android Studio中将其打开,然后制作了"coffeeplugin"
模块。
当我尝试在Gradle构建脚本中添加com.unity3d.player.UnityPlayer
时,当我同步Gradle时,Android Studio会告诉我其无效的字符串。
我知道我猜是要:SomeTag
,但我不知道该放什么。
Unity documentation并没有真正涉及到这一部分(至少从我能找到的文档和博客中)。
coffeeplugin build.gradle
apply plugin: 'com.android.library'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
minSdkVersion 14
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.unity3d.player'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
task copyPlugin(type: Copy) {
dependsOn assemble
from ('build/output/aar')
into ('N:/Storage/UnityProjects/Coffee/Assets/Plugins/Android')
include (project.name + "-release.aar")
}
答案 0 :(得分:3)
将implementation
的{{1}}更改为compileOnly
。这样一来,就可以在编译时使用统一播放器classes.jar,而在运行时则不能使用,这会导致重复。
答案 1 :(得分:0)
我弄清楚了我一直导入Unity的这些AAR文件中包含的内容。
通过将Unity中的/cronjobs/
包含到我的.war
中,我一直在做正确的事情。问题在于,通过在classes.jar
中使用plugin/libs
在Android Studio中构建插件,classes.jar
被包含在最终的AAR输出中,这在Unity方面是多余的,因为Unity已经存在有这些数据,因此我一直在重复类错误。
修复方法是打开AAR,它是一些存档编辑器(7-zip或winrar),仅提取其中的libs
并将其仅导入Unity。
令我惊讶的是,此过程没有更多的官方文档。
此外,此修复程序意味着无需对Gradle构建脚本进行任何编辑,除非您希望将从中间构建到Unity的复制过程自动化。
答案 2 :(得分:0)
将implementation
的{{1}}更改为compileOnly
答案 3 :(得分:0)
在libs文件夹中的unity中添加classes.jar文件后,打开unity player类为我解决了这个问题。
答案 4 :(得分:0)