2019安卓打包只有gradle模式了,因为某歌把adt删了

unity2019可以自定义gradle模板,国内请把repo地址改成阿里云的源

unity2019打apk配置

引擎版本:unity2019.3.7f1

android sdk,我仅保留28,29三个平台,system-images 仅保留23,29压缩后是2.5G,Android SDK Tools Version>26.1.1

  • platforms
  • system-images
  • build-tools

jdk提示需要JDK1.8 64位

家里电脑上安装的是:openjdk/16,打包会弹出提示版本不匹配,所以还是请安装JDK而不是OpenJDK

华为JDK国内镜像:https://mirrors.huaweicloud.com/openjdk/

Unity2019及Unity2020打包android的环境配置_Unity

此环境配置打包出来的APK可在mumu模拟器安卓6.0上正常跑

Unity2019及Unity2020打包android的环境配置_Unity_02

拷贝.gradle到离线环境

在断网的情况下,使用unity2018.4.15在打包apk时会报无法连接到远程的google.xxx,无法打包出apk,尝试过从其它电脑拷贝.gradle到打包机上,还是出现一样的提示,所以放弃离线的方法。

修改Unity的gradle为阿里云

以unity2019.3.7f1为例,在Unity的安装目录下,找到:PlaybackEngines/AndroidPlayer/Tools/GradleTemplates/baseProjectTemplate.gradle

替换这个文件的内容为如下,重启Unity进行build,下载一次之后后面build就会很快了。

// GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN

allprojects {
    buildscript {
        repositories {**ARTIFACTORYREPOSITORY**
            maven{ url 'https://maven.aliyun.com/repository/google'}
            //google()
            maven{ url 'https://maven.aliyun.com/repository/jcenter'}
            //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**
            maven{ url 'https://maven.aliyun.com/repository/google'}
            //google()
            maven{ url 'https://maven.aliyun.com/repository/jcenter'}
            //jcenter()
        flatDir {
            dirs "${project(':unityLibrary').projectDir}/libs"
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}