赞
踩
LZ-Says:万事儿开头难,枪在手,不得不发~
最近在了解Unity这块的内容,不得不说,新的领域,陌生的代码世界,初入茅庐,太多的陌生与不适,唯有咬紧牙关,坚持下去,到最后,会发现,一切不过尔尔!
本文,将作为在Study Unity过程中遇到的问题记录汇总,欢迎各位补充~
Unity: Unity 2017.3.1f1 (64-bit)
Visual Studio: Visual Studio 2017 社区版
问题详细日志:
-bootclasspath "E:/WorkSoftware/AndroidStudio/sdk\platforms\android-27\android.jar" -d "E:\UntiyPro\UnityDemo\Temp\StagingArea\bin\classes" -source 1.6 -target 1.6 -encoding UTF-8 "com\aiyou\testlib\R.java" "com\aiyou\testlib\resources\R.java"
警告: E:\WorkSoftware\AndroidStudio\sdk\platforms\android-27\android.jar(java/lang/Object.class): 主版本 52 比 51 新, 此编译器支持最新的主版本
建议升级此编译器
警告: E:\WorkSoftware\AndroidStudio\sdk\platforms\android-27\android.jar(java/lang/AutoCloseable.class): 主版本 52 比 51 新, 此编译器支持最新的主版本
建议升级此编译器
2个警告
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
问题解决办法:
首先,我们需要清楚:
从Unity 2017开始,Unity与JDK 9不兼容,所以只能降级到 JDK 8 (1.8)
所以,第一步,需要将你电脑安装的JDK版本替换到JDK 8,并且配置好相关环境变量以及Unity所依赖的JDK。
其次,LZ属于由Android提供Jar包供Unity使用,所以,在打包过程中,需要指定当前使用的JDK版本,如下:
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
问题截图:
问题解决:
你可以点击左侧,去Update Android SDK,也可以点击右侧Use Highest Installed使用本地已下载安装的最高版本。
问题截图:
日志详情:
问题解决:
这个问题是:Unity编译Android包错误导致,也就是Unity找不到SDK的Tools。
需要官方下载对应的Tools包,之后解压到本地SDK安装目录即可,下面附上官方地址:
完成之后本地sdk目录如下:
而有的小伙伴会问了,我该下载什么呢?
类似这:tools_r25.2.3-windows.zip
根据你版本看即可,下面附上一张网上哥儿们对比的不同版本(25.2.3 vs 25.3.1)之间的tools目录区别。
问题截图:
日志详情:
CommandInvokationFailure: Gradle build failed.
C:/Program Files/Java/jdk1.8.0_161\bin\java.exe -classpath "E:\WorkSoftware\Unity\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-4.0.1.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx2048m" "assembleRelease"
stderr[
Dex: Error converting bytecode to dex:
Cause: Dex cannot parse version 52 byte code.
This is caused by library dependencies that have been compiled using Java 8 or above.
If you are using the 'java' gradle plugin in a library submodule add
targetCompatibility = '1.7'
sourceCompatibility = '1.7'
to that submodule's build.gradle file.
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.RuntimeException: Exception parsing classes
at com.android.dx.command.dexer.Main.processClass(Main.java:781)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:747)
at com.android.dx.command.dexer.Main.access$1200(Main.java:88)
at com.android.dx.command.dexer.Main$FileBytesConsumer.processFileBytes(Main.java:1689)
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.process(ClassPathOpener.java:144)
at com.android.dx.command.dexer.Main.processOne(Main.java:695)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:592)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:321)
at com.android.dx.command.dexer.Main.run(Main.java:292)
at com.android.builder.internal.compiler.DexWrapper.run(DexWrapper.java:54)
at com.android.builder.core.DexByteCodeConverter.lambda$dexInProcess$0(DexByteCodeConverter.java:174)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)
at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:476)
at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)
at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)
at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)
at com.android.dx.command.dexer.Main.parseClass(Main.java:793)
at com.android.dx.command.dexer.Main.access$1600(Main.java:88)
at com.android.dx.command.dexer.Main$ClassParserTask.call(Main.java:1728)
at com.android.dx.command.dexer.Main.processClass(Main.java:779)
... 16 more
1 error; aborting
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':transformClassesWithDexForRelease'.
> com.android.build.api.transform.TransformException: java.lang.RuntimeException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: Return code 1 for dex process
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED in 2s
问题原因以及解决:
这是由于使用Java 8 或 以上编译的库以来关系引起。
所以,将Unity JDK路径替换为JDK 1.7即可:
问题截图:
日志详情:
CommandInvokationFailure: Gradle build failed.
C:/Program Files/Java/jdk1.7.0_80\bin\java.exe -classpath "E:\WorkSoftware\Unity\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-4.0.1.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx2048m" "assembleRelease"
stderr[
FAILURE: Build failed with an exception.
* Where:
Build file 'E:\UntiyPro\UnityDemo\Temp\gradleOut\build.gradle' line: 20
* What went wrong:
A problem occurred evaluating root project 'gradleOut'.
> java.lang.UnsupportedClassVersionError: com/android/build/gradle/AppPlugin : Unsupported major.minor version 52.0
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED in 1s
]
stdout[
]
exit code: 1
UnityEditor.Android.Command.WaitForProgramToRun (UnityEditor.Utils.Program p, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
UnityEditor.Android.AndroidJavaTools.RunJava (System.String args, System.String workingdir, System.Action`1 progress, System.String error)
UnityEditor.Android.GradleWrapper.Run (System.String workingdir, System.String task, System.Action`1 progress)
Rethrow as GradleInvokationException: Gradle build failed
UnityEditor.Android.GradleWrapper.Run (System.String workingdir, System.String task, System.Action`1 progress)
UnityEditor.Android.PostProcessor.Tasks.BuildGradleProject.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context)
UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
重点关注:Unsupported major.minor version 52.0
JDK高版本能兼容低版本,但是低版本不能兼容高版本。由于之前使用JDK 1.8编译,遂导致JDK 1.7 无法编译 JDK 1.8 编译后的项目。
所以,只需要将Unity中的JDK版本修改为 1.8 的即可。
问题截图:
异常日志:
CommandInvokationFailure: Gradle build failed.
C:/Program Files/Java/jdk1.8.0_161\bin\java.exe -classpath "E:\WorkSoftware\Unity\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-4.0.1.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx2048m" "assembleRelease"
stderr[
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':transformClassesWithDexForRelease'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lcom/aiyou/testlib/BuildConfig;
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED in 2s
]
stdout[
NDK is missing a "platforms" directory.
If you are using NDK, verify the ndk.dir is set to a valid NDK directory. It is currently set to E:\WorkSoftware\AndroidStudio\sdk\ndk-bundle.
If you are not using NDK, unset the NDK variable from ANDROID_NDK_HOME or local.properties to remove this warning.
NDK is missing a "platforms" directory.
If you are using NDK, verify the ndk.dir is set to a valid NDK directory. It is currently set to E:\WorkSoftware\AndroidStudio\sdk\ndk-bundle.
If you are not using NDK, unset the NDK variable from ANDROID_NDK_HOME or local.properties to remove this warning.
The setTestClassesDir(File) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use the setTestClassesDirs(FileCollection) method instead.
The getTestClassesDir() method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use the getTestClassesDirs() method instead.
The ConfigurableReport.setDestination(Object) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use the method ConfigurableReport.setDestination(File) instead.
:preBuild UP-TO-DATE
:preReleaseBuild UP-TO-DATE
:checkReleaseManifest
:unity-android-resources:preBuild UP-TO-DATE
:unity-android-resources:preReleaseBuild UP-TO-DATE
:unity-android-resources:checkReleaseManifest
:unity-android-resources:prepareReleaseDependencies
:unity-android-resources:compileReleaseAidl
:unity-android-resources:compileReleaseNdk NO-SOURCE
:unity-android-resources:compileLint
:unity-android-resources:copyReleaseLint NO-SOURCE
:unity-android-resources:mergeReleaseShaders
:unity-android-resources:compileReleaseShaders
:unity-android-resources:generateReleaseAssets
:unity-android-resources:mergeReleaseAssets
:unity-android-resources:mergeReleaseProguardFiles UP-TO-DATE
:unity-android-resources:packageReleaseRenderscript NO-SOURCE
:unity-android-resources:compileReleaseRenderscript
:unity-android-resources:generateReleaseResValues
:unity-android-resources:generateReleaseResources
:unity-android-resources:packageReleaseResources
:unity-android-resources:processReleaseManifest
:unity-android-resources:generateReleaseBuildConfig
:unity-android-resources:processReleaseResources
:unity-android-resources:generateReleaseSources
:unity-android-resources:incrementalReleaseJavaCompilationSafeguard
:unity-android-resources:javaPreCompileRelease
:unity-android-resources:compileReleaseJavaWithJavac
:unity-android-resources:processReleaseJavaRes NO-SOURCE
:unity-android-resources:transformResourcesWithMergeJavaResForRelease
:unity-android-resources:transformClassesAndResourcesWithSyncLibJarsForRelease
:unity-android-resources:mergeReleaseJniLibFolders
:unity-android-resources:transformNativeLibsWithMergeJniLibsForRelease
:unity-android-resources:transformNativeLibsWithSyncJniLibsForRelease
:unity-android-resources:bundleRelease
:prepareReleaseDependencies
:compileReleaseAidl UP-TO-DATE
:compileReleaseRenderscript UP-TO-DATE
:generateReleaseBuildConfig UP-TO-DATE
:generateReleaseResValues UP-TO-DATE
:generateReleaseResources UP-TO-DATE
:mergeReleaseResources UP-TO-DATE
:processReleaseManifest
:processReleaseResources
:generateReleaseSources
:incrementalReleaseJavaCompilationSafeguard UP-TO-DATE
:javaPreCompileRelease
:compileReleaseJavaWithJavac UP-TO-DATE
:compileReleaseNdk NO-SOURCE
:compileReleaseSources UP-TO-DATE
:lintVitalRelease
:mergeReleaseShaders UP-TO-DATE
:compileReleaseShaders UP-TO-DATE
:generateReleaseAssets UP-TO-DATE
:mergeReleaseAssets
:transformClassesWithDexForRelease FAILED
40 actionable tasks: 30 executed, 10 up-to-date
]
exit code: 1
UnityEditor.Android.Command.WaitForProgramToRun (UnityEditor.Utils.Program p, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
UnityEditor.Android.AndroidJavaTools.RunJava (System.String args, System.String workingdir, System.Action`1 progress, System.String error)
UnityEditor.Android.GradleWrapper.Run (System.String workingdir, System.String task, System.Action`1 progress)
Rethrow as GradleInvokationException: Gradle build failed
UnityEditor.Android.GradleWrapper.Run (System.String workingdir, System.String task, System.Action`1 progress)
UnityEditor.Android.PostProcessor.Tasks.BuildGradleProject.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context)
UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
问题解决办法:
第一种方式: 这种方式也知道是什么鬼 后期有时间了解下
Build System选择Internal即可。
第二种方式:
解决办法:
直接用winrar打开然后选中BuildConfig.class文件 ,再点击工具栏的“删除”图标就可以了。
放大图、图、图~:
之后Build打包即可~
问题截图:
问题原因:
当前版本不兼容:
目前,Android上的IL2CPP需要特定版本的Android NDK(r13b)。
问题解决:
可以通过单击设置NDK路径的字段旁边的“Download”按钮来下载此版本
问题截图:
问题原因:
编译失败,有错误异常产生。
问题解决:
点击Window选择Console查看错误并解决即可。
错误日志:
ExitGUIException: Exception of type 'UnityEngine.ExitGUIException' was thrown.
UnityEngine.GUIUtility.ExitGUI () (at C:/buildslave/unity/build/Runtime/IMGUI/Managed/GUIUtility.cs:152)
UnityEditor.Android.AndroidJavaTools.BrowseForJDK (System.String jdkPath)
UnityEditor.Android.AndroidJavaTools.LocateJDKHome ()
UnityEditor.Android.AndroidJavaTools.get_javaPath ()
UnityEditor.Android.AndroidSDKTools.RunCommand (System.String[] sdkToolCommand, Int32 memoryMB, System.String workingdir, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
UnityEditor.Android.AndroidSDKTools.RunCommand (System.String[] sdkToolCommand, System.String workingdir, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
UnityEditor.Android.AndroidSDKTools.RunCommand (System.String[] sdkToolCommand, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
UnityEditor.Android.AndroidSDKTools.GetSDKBuildToolsDir ()
UnityEditor.Android.AndroidSDKTools.UpdateToolsDirectories ()
UnityEditor.Android.AndroidSDKTools..ctor (System.String sdkRoot)
UnityEditor.Android.AndroidSDKTools.GetInstance ()
UnityEditor.Android.PostProcessor.Tasks.CheckAndroidSDK.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context)
UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context)
UnityEditor.Android.PostProcessAndroidPlayer.PrepareForBuild (BuildOptions options, BuildTarget target)
UnityEditor.Android.AndroidBuildPostprocessor.PrepareForBuild (BuildOptions options, BuildTarget target)
UnityEditor.PostprocessBuildPlayer.PrepareForBuild (BuildOptions options, BuildTargetGroup targetGroup, BuildTarget target) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/PostprocessBuildPlayer.cs:87)
UnityEditor.BuildPlayerWindow:BuildPlayerAndRun()
解决:
查看本地JDK配置,LZ是由于更改了本地JDK版本导致。
错误日志:
Win32Exception: ApplicationName='C:/Program Files/Java/jdk1.8.0_161\bin\java.exe', CommandLine='-Xmx2048M -Dcom.android.sdkmanager.toolsdir="E:/WorkSoftware/AndroidStudio/sdk\tools" -Dfile.encoding=UTF8 -jar "E:\WorkSoftware\Unity\Editor\Data\PlaybackEngines\AndroidPlayer/Tools\sdktools.jar" -', CurrentDirectory='E:\UntiyPro\UcenterSdkTest'
System.Diagnostics.Process.Start_noshell (System.Diagnostics.ProcessStartInfo startInfo, System.Diagnostics.Process process)
System.Diagnostics.Process.Start_common (System.Diagnostics.ProcessStartInfo startInfo, System.Diagnostics.Process process)
System.Diagnostics.Process.Start ()
(wrapper remoting-invoke-with-check) System.Diagnostics.Process:Start ()
UnityEditor.Utils.Program.Start (System.EventHandler exitCallback) (at C:/buildslave/unity/build/Editor/Mono/Utils/Program.cs:44)
UnityEditor.Utils.Program.Start () (at C:/buildslave/unity/build/Editor/Mono/Utils/Program.cs:28)
UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
UnityEditor.Android.AndroidSDKTools.RunCommandInternal (System.String javaExe, System.String sdkToolsDir, System.String[] sdkToolCommand, Int32 memoryMB, System.String workingdir, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
UnityEditor.Android.AndroidSDKTools.RunCommandSafe (System.String javaExe, System.String sdkToolsDir, System.String[] sdkToolCommand, Int32 memoryMB, System.String workingdir, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
UnityEditor.Android.AndroidSDKTools.RunCommand (System.String[] sdkToolCommand, Int32 memoryMB, System.String workingdir, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
UnityEditor.Android.AndroidSDKTools.RunCommand (System.String[] sdkToolCommand, System.String workingdir, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
UnityEditor.Android.AndroidSDKTools.RunCommand (System.String[] sdkToolCommand, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
UnityEditor.Android.AndroidSDKTools.GetSDKBuildToolsDir ()
UnityEditor.Android.AndroidSDKTools.UpdateToolsDirectories ()
UnityEditor.Android.AndroidSDKTools..ctor (System.String sdkRoot)
UnityEditor.Android.AndroidSDKTools.GetInstance ()
UnityEditor.Android.PostProcessor.Tasks.CheckAndroidSDK.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context)
UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context)
UnityEditor.Android.PostProcessAndroidPlayer.PrepareForBuild (BuildOptions options, BuildTarget target)
UnityEditor.Android.AndroidBuildPostprocessor.PrepareForBuild (BuildOptions options, BuildTarget target)
UnityEditor.PostprocessBuildPlayer.PrepareForBuild (BuildOptions options, BuildTargetGroup targetGroup, BuildTarget target) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/PostprocessBuildPlayer.cs:87)
UnityEditor.BuildPlayerWindow:BuildPlayerAndRun()
问题解决:
由于LZ在打开Unity的时候,变更了本地JDK版本,导致找不到java.exe文件。
欢迎关注个人公众号,不定期发布博文,感叹等等~
让我们一起愉快的撸码~
如果感觉LZ所为对你有所帮助,不妨赞助LZ喝点小玩意,啦啦啦~
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。