一、安装unity
第二步jdk和第三步sdk其实下载unity的时候可以自行安装(unity2019版本之上才有这个功能)
但是这里我出现了问题!!!
网上查阅了好多办法,卸载重装unityHub也不行,所以只能乖乖的自己网上下载jdk和sdk
如果出现没有添加模块这种问题,将Unity卸载从UnityHub中重新下载就好了
二、安装jdk,jre (具体安装方法网上好多,这里就不多说了)
下载jdk时一定要对应好unity中所需要的版本,版本不对应打包容易出错找到文件夹
三、下载安装AndroidSDK 下载地址
四、配置环境 传送门
这里要注意如果是从unity的安装模块中下载的jdk和sdk得话,下载的路径可以从unity中找到
四、配置Gradle
一般经历以上步骤可以打包成功的话,那你是幸运的。如果不行那就自己手动配置
找到baseProjectTemplate.gradle文件 ,文件夹路径(unity下载安装路径下):D:\Unity3D\2019.4.4f1\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\GradleTemplates
使用记事本打开找到这句话
classpath ‘com.android.tools.build:gradle:3.4.0’
其中3.4.0就是unity要使用的插件版本 插件版本对应网址
根据表中显示我们需要下载5.1.1版本Gradel Gradle下载地址
版本好多,我们选择后缀名为all并且文件最大的下载
在unity中设置对应路径
有时候gradle还是需要下载一些东西,这时候我们配置阿里云库下载,打开baseProjectTemplate.gradle文件(上面讲如何找到Gradle对应版本,该文件路径有讲过),
在buildscript和repositories 添加这四句话
maven {
url 'https://maven.aliyun.com/repository/google' }
maven {
url 'https://maven.aliyun.com/repository/gradle-plugin' }
maven {
url 'http://maven.aliyun.com/nexus/content/groups/public/' }
maven {
url 'https://maven.aliyun.com/repository/jcenter'}
添加前的样子
// 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 'https://maven.aliyun.com/repository/google' }
maven {
url 'https://maven.aliyun.com/repository/gradle-plugin' }
maven {
url 'http://maven.aliyun.com/nexus/content/groups/public/' }
maven {
url 'https://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 'https://maven.aliyun.com/repository/google' }
maven {
url 'https://maven.aliyun.com/repository/gradle-plugin' }
maven {
url 'http://maven.aliyun.com/nexus/content/groups/public/' }
maven {
url 'https://maven.aliyun.com/repository/jcenter'}
flatDir {
dirs "${project(':unityLibrary').projectDir}/libs"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
这时候小伙伴就可以打包啦。
参考连接:
>重要事情说三遍:
打包路径下不能存在中文
打包路径下不能存在中文
打包路径下不能存在中文
这里附上我当前配置的资源包 密码:syq1