且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将 unity 项目导入到现有的 Android studios project 中?

更新时间:2022-04-13 22:28:39

有同样的需求,成功将 Unity 项目导入到现有的 Android Studio 项目中.如前所述,第一件事是导出 Unity 项目.我使用了 Unity 2017.1 版.下面的粗略步骤:

Had the same requirement and successfully imported the Unity project into an existing Android Studio project. As mentioned the first thing will be to export the Unity project. I used Unity version 2017.1. Rough steps below:

  1. 通过 Unity 构建设置导出 Android 项目

  1. 您只需选择现有项目所在的文件夹即可.Unity 应该添加一个包含 Android Studio 格式项目和所有依赖项以及运行所需的所有内容的子文件夹.

  1. You can simply select the folder where your existing project is located. Unity should add a sub folder with an Android Studio format project and all dependencies and everything it needs to run.

现在我们需要将此应用程序"项目转换为库"项目.这只需更改 build.gradle 文件即可完成.将应用插件:'com.android.application' 替换为应用插件:'com.android.library'.

Now we need to convert this "Application" project to a "Library" project. This is simply done by changing the build.gradle file. Replace apply plugin: 'com.android.application' with apply plugin: 'com.android.library'.

您还需要删除 applicationId 并更改编译版本以匹配您的项目版本.

You also need to remove the applicationId and change the compile versions to match your project's versions.

  1. 还要确保修改 Unity 模块 AndroidManifest.xml 文件.您需要删除 LAUNCHER 意图过滤器,因为 UnityPlayerActivity 将不再是主要活动.

  1. Also make sure to modify the Unity module AndroidManifest.xml file. You will need to remove the LAUNCHER intent-filter as the UnityPlayerActivity will not be the main activity anymore.

android.intent.action.MAIN

android.intent.action.MAIN

android.intent.category.LAUNCHER

android.intent.category.LAUNCHER

还需要删除 Application 节点属性,以免与您的项目清单冲突.

Also need to remove the Application node attributes so it won't conflict with your project's manifest.

  1. 最后在你的 settings.gradle 添加模块,然后在你的app"模块上添加 Unity 项目依赖:compile project(':UnityFolder')

构建,现在您应该能够通过调用来启动 Unity 场景:

Build and now you should be able to start the Unity Scene by calling:

Intent intent = new Intent(this, UnityPlayerActivity.class);

Intent intent = new Intent(this, UnityPlayerActivity.class);

startActivity(intent);

startActivity(intent);