Unity 之 解决2019之后的版本打apk卡到Building Gradle project问题
gradle 解决 版本 Unity 2019 之后 project APK
2023-09-11 14:20:51 时间
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,然后重新打包就可以了。
相关文章
- gradle打包分编译环境
- 《gradle权威指南》--Gradle入门
- No cached version of com.android.tools.build:gradle:2.3.3 available for offline mode. Disable Gradle
- 【Android Gradle 插件】组件化中的 Gradle 构建脚本实现 ③ ( 在 Gradle 构建脚本中实现 AndroidManifest.xml 清单文件切换设置 )
- 【Android Gradle 插件】Gradle 基础配置 ③ ( 生成 Gradle Wrapper 配置 | 分析生成的 gradle-wrapper.properties 配置文件 )
- 【Android Gradle 插件】Gradle 扩展属性 ② ( 定义在根目录 build.gradle 中的扩展属性 | 使用 rootProject.扩展属性名访问 | 扩展属性示例 )
- 【Android Gradle 插件】Gradle 依赖管理 ① ( org.gradle.api.Project 配置 | Android Gradle 插件配置与 Gradle 配置关联 ) ★
- 【Android Gradle 插件】TestOptions 配置 ④ ( org.gradle.api.tasks.testing.Test 单元测试配置类 | Android 单元测试示例 )
- 【Android Gradle 插件】ProductFlavor 配置 ( AppExtension#variantFilter 过滤变体属性 )
- 【Android Gradle 插件】gradle.properties 中配置编译参数并在 Java 代码 BuildConfig 中调用该参数
- 【错误记录】Android Gradle 配置报错 ( gradle.properties 配置到 BuildConfig 中需要注意类型转换 | 位置: 类 BuildConfig )
- 【Android Gradle 插件】ProductFlavor 配置 ( consumerProguardFiles 配置 | dimension 配置 )
- 【Android Gradle 插件】Gradle 映射文件 ( settings.gradle 映射为 Settings 类 | build.gradle 映射为 Project 类 )
- 【Groovy】Gradle 构建工具 ( 自动下载并配置构建环境 | 提供 API 扩展与开发工具集成 | 内置 Maven 和 Ivy 依赖管理 | 使用 Groovy 编写构建脚本 )
- 001-快速搭建Spring web应用【springboot 2.0.4】-gradle、springboot的启动过程分析、gradle多模块构建
- 使用 gradle 在编译时动态设置 Android resValue / BuildConfig / Manifes中<meta-data>变量的值
- 解决AS gradle下载同步卡慢的问题
- gradle编译命令 & 自动打包等
- 解决Android studio 编译flutter项目 卡在Running Gradle task ‘assembleDebug‘ ——筑梦之路
- Win10解决Android Studio:Gradle sync failed: Failed to open zip file.