1

Android工程接入UnityLibrary工程 - 小紫苏

 1 year ago
source link: https://www.cnblogs.com/littleperilla/p/17197370.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Unity工程指UnityLibrary目录下文件;

安卓工程指app目录下文件;

整体指App目录下不包括app和UnityLibrary;

1.Unity打包时勾选导出安卓工程;

拷贝gradle.properties中:unityStreamingAssets=xxx 到整体工程的gradle.properties中

拷贝local.properites中ndk、jdk路径到整体工程的local.properites

2.AndroidStudio创建Empty Activity工程;

整体工程的setting.gradle中添加:

include ':unityLibrary'
project(':unityLibrary').projectDir=new File('.\\unityLibrary')

安卓工程app目录下build.gradle中添加:

dependencies{
	implementation project(':unityLibrary')
	implementation fileTree(dir:project(':unityLibrary').getProjectDir().toString() + ('\\libs'), include: ['*.jar'])
}

3.修改安卓工程和Unity工程Build.Gradle

targetsdk,minsdk,compilesdk,buildToolsVersion都要一致

也可在File/ProjectStructure/Modules中切换Version

4.在安卓工程MainActivity中添加切换Activity代码

在OnCreate中添加:

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

这样一开始就会打开Unity界面,也可以在原生工程添加按钮跳转;

1.Gradle Version和 Gradle Plugin Version出错

Gradle Plugin Version中包含了多个Gradle Version;根据提示选择对应版本的GradleVersion;如果没有对应版本,就下载新的Gradle Plugin Version;

File/ProjectStructure/Project中切换;

2.sdk、ndk、jdk版本出错

建议使用Unity本体目录下的sdk和jdk,同样ProjectStructure界面选择;

之前local.properites也配置过;

3.跳转Unity工程闪退

安卓工程的main/res/values/string.xml中添加

<string name="game_view_content_description">Game view</string>

4.编译过程中找不到libillcpp.so,libmain.so等问题

重新拷贝Unity导出工程的jiniLibs文件夹到UnityLibrary对应目录工,删除buid,重新打包;

5.打包编译il2cpp报错

如果做了代码热更有可能是没有正确生成依赖,找不到对应类型;

我使用HybridCLR热更,可以重新生成依赖,再次导出安卓工程;

6.两个app图标

注释UnityLibray目录中AndroidManifest.xml以下配置;

<!--      <intent-filter>-->
<!--        <action android:name="android.intent.action.MAIN" />-->
<!--        <category android:name="android.intent.category.LAUNCHER" />-->
<!--      </intent-filter>-->

Life is too short for so much sorrow.
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 小紫苏

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK