最近遇到Unity编译Android apk进度卡在"Calling IPostGenerateGradleAndroidProject callbacks"进度一直不变,如下图:
最后提示编译失败,类似错误如下:
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'Gradle'.
> Could not resolve all artifacts for configuration ':classpath'.
> Could not download fastutil-8.4.0.jar (it.unimi.dsi:fastutil:8.4.0)
> Could not get resource 'https://plugins.gradle.org/m2/it/unimi/dsi/fastutil/8.4.0/fastutil-8.4.0.jar'.
> Premature end of Content-Length delimited message body (expected: 19,052,190; received: 6,553,552)
* 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
虽然开了VPN,可以访问到提示下载超时的地址,但下次编译,又会提其它地址访问超时。而且
“C:\Users\当前用户\.gradle”这个文件夹的文件数也在以及慢的速度增长。但试了很多次还是编译失败。
解决方案如下:
在 Project Settings/Player/Android平台/Publishing Settings/下勾选Custom Gradle Settings Template, 并修改Assets\Plugins\Android\settingsTemplate.gradle文件的内容,
settingsTemplate.gradle内容修改为如下。
pluginManagement {
repositories {
**ARTIFACTORYREPOSITORY**
maven {
url 'https://mirrors.huaweicloud.com/repository/maven/'
}
//gradlePluginPortal()
//google()
//mavenCentral()
}
}
include ':launcher', ':unityLibrary'
**INCLUDES**
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
repositories {
**ARTIFACTORYREPOSITORY**
maven {
url 'https://mirrors.huaweicloud.com/repository/maven/'
}
//google()
//mavenCentral()
flatDir {
dirs "${project(':unityLibrary').projectDir}/libs"
}
}
}
还可以替换为下面的地址尝试。
阿里云:http://maven.aliyun.com/
中央仓库:https://repo1.maven.org/maven2/
网易:http://maven.netease.com/repository/public/
华为云:https://repo.huaweicloud.com/repository/maven/
腾讯云:https://mirrors.cloud.tencent.com/repository/maven/
中国科技大学:http://mirrors.ustc.edu.cn/maven/maven2/
南京大学:http://maven.nju.edu.cn/repository/
清华大学:https://repo.maven.apache.org/maven2/
北京理工大学:http://mirror.bit.edu.cn/maven/
东软信息学院:https://mirrors.neusoft.edu.cn/maven2/
中国科学院开源协会:http://maven.opencas.cn/maven/
北京交通大学:http://maven.bjtu.edu.cn/maven2/