Unity 发布APK报错

问题1:

Build Gradle错误

CommandInvokationFailure: Gradle build failed. 
D:/JAVASDK/jdk1.8.0_251\bin\java.exe -classpath "F:\Unity2018\install\Unity\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-4.2.1.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx2048m" "assembleRelease"

stderr[

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'gradleOut'.
> Could not resolve all files for configuration ':classpath'.
   > Could not download layoutlib-api.jar (com.android.tools.layoutlib:layoutlib-api:26.0.1)
      > Could not get resource 'http://maven.aliyun.com/nexus/content/groups/public/com/android/tools/layoutlib/layoutlib-api/26.0.1/layoutlib-api-26.0.1.jar'.
         > Could not GET 'http://maven.aliyun.com/nexus/content/groups/public/com/android/tools/layoutlib/layoutlib-api/26.0.1/layoutlib-api-26.0.1.jar'.
            > Connect to archiva-maven-storage-prod.oss-cn-beijing.aliyuncs.com:443 [archiva-maven-storage-prod.oss-cn-beijing.aliyuncs.com/49.7.22.5] failed: Connection timed out: connect

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

* Get more help at https://help.gradle.org

BUILD FAILED in 1m 7s
]
stdout[
Download http://maven.aliyun.com/nexus/content/groups/public/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.pom
Download http://maven.aliyun.com/nexus/content/groups/public/com/android/tools/build/gradle-core/3.0.1/gradle-core-3.0.1.pom
Download http://maven.aliyun.com/nexus/content/groups/public/com/android/tools/lint/lint/26.0.1/lint-26.0.1.pom
Download http://maven.aliyun.com/nexus/content/groups/public/com/android/tools/build/gradle-api/3.0.1/gradle-api-3.0.1.pom
Download http://maven.aliyun.com/nexus/content/groups/public/com/android/databinding/compilerCommon/3.0.1/compilerCommon-3.0.1.pom
Download http://maven.aliyun.com/nexus/content/groups/public/com/android/tools/build/builder/3.0.1/builder-3.0.1.pom
Download http://maven.aliyun.com/nexus/content/groups/public/com/android/tools/build/builder-test-api/3.0.1/builder-test-api-3.0.1.pom
Download http://maven.aliyun.com/nexus/content/groups/public/com/android/tools/sdklib/26.0.1/sdklib-26.0.1.pom
Download http://maven.aliyun.com/nexus/content/groups/public/com/android/tools/analytics-library/shared/26.0.1/shared-26.0.1.pom
Download http://maven.aliyun.com/nexus/content/groups/public/com/android/tools/build/apksig/3.0.1/apksig-3.0.1.pom
Download http://maven.aliyun.com/nexus/content/groups/public/com/android/tools/analytics-library/tracker/26.0.1/tracker-26.0.1.pom
Download http://maven.aliyun.com/nexus/content/groups/public/com/android/tools/sdk-common/26.0.1/sdk-common-26.0.1.pom
Download http://maven.aliyun.com/nexus/content/groups/public/com/android/tools/build/builder-model/3.0.1/builder-model-3.0.1.pom
Download http://maven.aliyun.com/nexus/content/groups/public/com/android/tools/analytics-library/protos/26.0.1/protos-26.0.1.pom
Download http://maven.aliyun.com/nexus/content/groups/public/com/android/tools/lint/lint-checks/26.0.1/lint-checks-26.0.1.pom
Download http://maven.aliyun.com/nexus/content/groups/public/com/android/databinding/baseLibrary/3.0.1/baseLibrary-3.0.1.pom
Download http://maven.aliyun.com/nexus/content/groups/public/com/android/tools/layoutlib/layoutlib-api/26.0.1/layoutlib-api-26.0.1.pom
Download http://maven.aliyun.com/nexus/content/groups/public/com/android/tools/repository/26.0.1/repository-26.0.1.pom
Download http://maven.aliyun.com/nexus/content/groups/public/com/android/tools/lint/lint-api/26.0.1/lint-api-26.0.1.pom
Download http://maven.aliyun.com/nexus/content/groups/public/com/android/tools/annotations/26.0.1/annotations-26.0.1.pom
Download http://maven.aliyun.com/nexus/content/groups/public/com/android/tools/build/gradle-core/3.0.1/gradle-core-3.0.1.jar
Download http://maven.aliyun.com/nexus/content/groups/public/com/android/tools/build/builder/3.0.1/builder-3.0.1.jar
Download http://maven.aliyun.com/nexus/content/groups/public/com/android/tools/sdklib/26.0.1/sdklib-26.0.1.jar
Download http://maven.aliyun.com/nexus/content/groups/public/com/android/tools/lint/lint/26.0.1/lint-26.0.1.jar
Download http://maven.aliyun.com/nexus/content/groups/public/com/android/tools/lint/lint-api/26.0.1/lint-api-26.0.1.jar
Download http://maven.aliyun.com/nexus/content/groups/public/com/android/tools/lint/lint-checks/26.0.1/lint-checks-26.0.1.jar
Download http://maven.aliyun.com/nexus/content/groups/public/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.jar
Download http://maven.aliyun.com/nexus/content/groups/public/com/android/tools/sdk-common/26.0.1/sdk-common-26.0.1.jar
Download http://maven.aliyun.com/nexus/content/groups/public/com/android/tools/repository/26.0.1/repository-26.0.1.jar
Download http://maven.aliyun.com/nexus/content/groups/public/com/android/databinding/compilerCommon/3.0.1/compilerCommon-3.0.1.jar
Download http://maven.aliyun.com/nexus/content/groups/public/com/android/tools/analytics-library/shared/26.0.1/shared-26.0.1.jar
Download http://maven.aliyun.com/nexus/content/groups/public/com/android/tools/analytics-library/protos/26.0.1/protos-26.0.1.jar
Download http://maven.aliyun.com/nexus/content/groups/public/com/android/tools/build/builder-test-api/3.0.1/builder-test-api-3.0.1.jar
Download http://maven.aliyun.com/nexus/content/groups/public/com/android/tools/build/builder-model/3.0.1/builder-model-3.0.1.jar
Download http://maven.aliyun.com/nexus/content/groups/public/com/android/tools/analytics-library/tracker/26.0.1/tracker-26.0.1.jar
Download http://maven.aliyun.com/nexus/content/groups/public/com/android/tools/build/apksig/3.0.1/apksig-3.0.1.jar
Download http://maven.aliyun.com/nexus/content/groups/public/com/android/tools/annotations/26.0.1/annotations-26.0.1.jar
Download http://maven.aliyun.com/nexus/content/groups/public/com/android/databinding/baseLibrary/3.0.1/baseLibrary-3.0.1.jar
Download http://maven.aliyun.com/nexus/content/groups/public/com/android/tools/build/gradle-api/3.0.1/gradle-api-3.0.1.jar
]
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 (UnityEditor.Android.AndroidJavaTools javaTools, System.String workingdir, System.String task, System.Action`1 progress)
Rethrow as GradleInvokationException: Gradle build failed
UnityEditor.Android.GradleWrapper.Run (UnityEditor.Android.AndroidJavaTools javaTools, 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 Settings—Publishing Settings—Build 勾选Custom Gradle Template

问题2

IndexOutOfRangeException: Array index is out of range.
UnityEditor.Android.AndroidBuildWindowExtension.GetBuildPlayerWindow ()
UnityEditor.Android.AndroidBuildWindowExtension.RepaintTargetList ()
UnityEditor.EditorApplication.Internal_CallUpdateFunctions () (at C:/buildslave/unity/build/Editor/Mono/EditorApplication.cs:191)

解决方法:
复制以下内容替换到的EditorSettings.asset文件中就可以了;
EditorSettings.asset文件在项目文件夹—ProjectSettings文件夹中

%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!159 &1
EditorSettings:
  m_ObjectHideFlags: 0
  serializedVersion: 1
  m_ExternalVersionControlSupport: 1
  m_SerializationMode: 2
  m_WebSecurityEmulationEnabled: 0
  m_WebSecurityEmulationHostUrl: http://www.mydomain.com/mygame.unity3d

参考:https://forum.unity.com/threads/reset-in-editor-settings-results-in-indexoutofrangeexception-and-breaks-version-control-on-windows.469858/


版权声明:本文为weixin_45684148原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。