Unity2019及Unity2020打包android的環境配置


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/

提示需要JDK1.8

因為JDK8u211和8u212之后的版本商用收費,所以請下載舊版本的JD,可以在這里下載》華為國內JDK鏡像:https://repo.huaweicloud.com/java/jdk/8u202-b08/

關於新版本JDK商用收費的文章《Java JDK 1.8 下載及其版本說明 8u202(最后一個免費版) - 夢相隨1006 - 博客園 (cnblogs.com)

此環境配置打包出來的APK可在mumu模擬器安卓6.0上正常跑

image-20210328234504952

拷貝.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
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM