Unity 之 解决2019之后的版本打apk卡到Building Gradle project问题
【摘要】 Unity 之 解决2019之后的版本打apk卡到Building Gradle project问题
一,遇到问题
安装环境:安装Android Build Support;【需要将下拉菜单的两项一并安装】
问题:
Unity2019 版本打包apk,卡到Building Gradle project这一直不动,长时间等待后打包失败
二,分析问题
失败原因:是在下载的对应版本Gradle时,需要访问外网下载速度慢或者网络不稳定导致失败
三,解决问题
方法一:修改配置文件
1,找到Untiy安装目录下的AndroidPlayer\Tools\GradleTemplates文件夹下的 baseProjectTemplate.gradle 文件
参考我的目录:
D:\Program Files\Unity\2019.4.19f1c1\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\GradleTemplates
// GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN
allprojects {
buildscript {
repositories {**ARTIFACTORYREPOSITORY**
google()
jcenter()
}
dependencies {
// If you are changing the Android Gradle Plugin version, make sure it is compatible with the Gradle version preinstalled with Unity
// See which Gradle version is preinstalled with Unity here https://docs.unity3d.com/Manual/android-gradle-overview.html
// See official Gradle and Android Gradle Plugin compatibility table here https://developer.android.com/studio/releases/gradle-plugin#updating-gradle
// To specify a custom Gradle version in Unity, go do "Preferences > External Tools", uncheck "Gradle Installed with Unity (recommended)" and specify a path to a custom Gradle version
classpath 'com.android.tools.build:gradle:3.4.0'
**BUILD_SCRIPT_DEPS**
}
}
repositories {**ARTIFACTORYREPOSITORY**
google()
jcenter()
flatDir {
dirs "${project(':unityLibrary').projectDir}/libs"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
修改为:
// GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN
allprojects {
buildscript {
repositories {**ARTIFACTORYREPOSITORY**
//google()
//jcenter()
maven{ url 'http://maven.aliyun.com/repository/google'}
maven{ url 'http://maven.aliyun.com/repository/gradle-plugin'}
maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
maven{ url 'http://maven.aliyun.com/repository/jcenter'}
}
dependencies {
// If you are changing the Android Gradle Plugin version, make sure it is compatible with the Gradle version preinstalled with Unity
// See which Gradle version is preinstalled with Unity here https://docs.unity3d.com/Manual/android-gradle-overview.html
// See official Gradle and Android Gradle Plugin compatibility table here https://developer.android.com/studio/releases/gradle-plugin#updating-gradle
// To specify a custom Gradle version in Unity, go do "Preferences > External Tools", uncheck "Gradle Installed with Unity (recommended)" and specify a path to a custom Gradle version
classpath 'com.android.tools.build:gradle:3.4.0'
**BUILD_SCRIPT_DEPS**
}
}
repositories {**ARTIFACTORYREPOSITORY**
//google()
//jcenter()
maven{ url 'http://maven.aliyun.com/repository/google'}
maven{ url 'http://maven.aliyun.com/repository/gradle-plugin'}
maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
maven{ url 'http://maven.aliyun.com/repository/jcenter'}
flatDir {
dirs "${project(':unityLibrary').projectDir}/libs"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
然后重新打包即可。
方法二:修改Preferences属性
在官网上提前下载好需要版本gradle:https://gradle.org/releases/
然后在Preferences面板上,将Gradle Installed…选项前面√取消勾选,然后点击“Browse”,找到自己下载好的gradle,然后重新打包就可以了。
【版权声明】本文为华为云社区用户原创内容,未经允许不得转载,如需转载请自行联系原作者进行授权。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)