Unity5.5.6 升级到 2018.4.1 打包出现的问题 : Gradle version 2.10 is required. Current version is 5.1.1

时间:2022-11-09 18:07:04

起因:最近要在googleplay上架新游戏,而谷歌要求新上架的应用要支持64位,鉴于老版本的unity不支持打包64位apk,所以决定升级unity版本到2018.4.1,

但打包过程中出现了几个问题  ->

问题1

Gradle version 配置错误,报错信息如下:

CommandInvokationFailure: Gradle build failed.
D:\Program Files\unity2018.4.17\Unity\Editor\Data\PlaybackEngines\AndroidPlayer/Tools\OpenJDK\Windows\bin\java.exe -classpath "D:\Program Files\unity2018.4.17\Unity\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-5.1.1.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx4096m" "assembleRelease"

stderr[

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\w_\_upgrade2018\CashBonanza_EN\Temp\gradleOut\build.gradle' line: 21

* What went wrong:
A problem occurred evaluating root project 'gradleOut'.
> Failed to apply plugin [id 'com.android.application']
> Gradle version 2.10 is required. Current version is 5.1.1. If using the gradle wrapper, try editing the distributionUrl in C:\w_\_upgrade2018\CashBonanza_EN\Temp\gradleOut\gradle\wrapper\gradle-wrapper.properties to gradle-2.10-all.zip

* 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

由信息可知:

当前Unity2018.4.1 中的Gradle version 是 5.1.1 而我的打包要求却是2.10,如此定位应该是配置不一致问题,查之果然:

因为我在unity 5.5.6也是用gradle方式打包,新游戏延用了旧游戏的部分配置,所以mainTemplate也被拷贝了过来,如图:

Unity5.5.6 升级到 2018.4.1   打包出现的问题 : Gradle version 2.10 is required. Current version is 5.1.1

查看Unity2018.4.1安装目录下的mainTemplate中的配置,路径:unity2018.4.17安装目录\Unity\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\GradleTemplates\mainTemplate.gradle,如图:

Unity5.5.6 升级到 2018.4.1   打包出现的问题 : Gradle version 2.10 is required. Current version is 5.1.1

如此,解决的办法就是把unity2018.4.17安装目录\Unity\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\GradleTemplates\mainTemplate.gradle文件拷贝到Unity/Assets/Plugins/Android路径下替换旧配置,

由此,问题1解决

问题2

安卓打包方法超过64k的问题,这个还是在mainTemplate.gradle配置中调整,加上multiDexEnabled true属性即可,如图:

Unity5.5.6 升级到 2018.4.1   打包出现的问题 : Gradle version 2.10 is required. Current version is 5.1.1

由此,问题2解决

最后,64位apk打包成功