文章目录
- 一、 Android 工程打包
- 二、 Android Studio 打开 Unity 导出的 Android 工程
一、 Android 工程打包
Android 工程打包 就是将 Unity 项目导出为 Android Studio 项目 , 在 Unity 编辑器中选择 " 菜单栏 | File | Build Settings… " 选项 ,

在这里插入图片描述
在弹出的 " Build Settings " 对话框中 , 勾选上 " Export Project " 选框 , 然后点击右下角的 " Export " 导出按钮 ;

在这里插入图片描述
选择一个导出目录 ;

在这里插入图片描述
等待 Android 工程导出 ;

在这里插入图片描述
最终导出的 Android 工程如下 :

在这里插入图片描述
打开根目录的 build.gradle 查看 , 发现这是 Android Studio 工程的 Gradle 主构建脚本 ;
// GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN
allprojects {
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.1'
}
}
repositories {
google()
jcenter()
flatDir {
dirs "${project(':unityLibrary').projectDir}/libs"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
unityLibrary 模块就是我们开发的 Unity 游戏 ;
使用 Android Studio 打开该项目即可 ;
二、 Android Studio 打开 Unity 导出的 Android 工程
在 Android Studio 中 , 选择 " 菜单栏 | File | Open… " 选项 ,

在这里插入图片描述
在弹出的对话框中 , 选择 刚才在 Unity 编辑器中打包的 Android 工程 ;

在这里插入图片描述
这里建议选择使用默认选项选项 ;

在这里插入图片描述
等待 Android 工程编译 , 耗时比较长 ;
编译成功 ;

在这里插入图片描述
在华为手机中运行该应用 ;

在这里插入图片描述