AndroidStudio创建的项目集成Unity导出的Android项目遇到的闪退问题

1、集成方法

1、Unity导出Android项目之后,将以下几个文件拷贝到AndroidStudio创建的新项目中
libs下的unity-classes.jar
src/main/assets
src/main/包路径/UnityPlayerActivity.java
src/main/jniLibs
src/main/res
src/main/AndroidManifest.xml
2、在MainActivity中使用Intent跳转到UnityPlayerActivity出现闪退,解决方法看需要注意的问题:

需要注意的问题如下几点(最后一条最重要):

1)、修改build.gradle配置文件:
dependencies {
	implementation fileTree(dir: 'libs', include: ['*.jar'])
	implementation 'androidx.appcompat:appcompat:1.1.0'
	implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
	testImplementation 'junit:junit:4.12'
	androidTestImplementation 'androidx.test.ext:junit:1.1.1'
	androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
	<!-- 引入unity-classes.jar -->
	api fileTree(dir: 'libs', include: 'unity-classes.jar')
}
2)、在AndroidManifest.xml中添加Unity游戏场景的Activity
<activity android:label="@string/app_name" android:screenOrientation="fullSensor" android:launchMode="singleTask" android:process=".unityplayer" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection|density" android:hardwareAccelerated="false" android:name="com.vip.test.UnityPlayerActivity">
    <intent-filter>
    	<!-- <action android:name="android.intent.action.MAIN" /> -->
        <category android:name="android.intent.category.LAUNCHER" />
        <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
    </intent-filter>
    <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
</activity>
3)、在AndroidManifest.xml文件中application的主题:
将:android:theme="@style/UnityThemeSelector"
修改为:android:theme="@style/AppTheme"
4、如果是使用AndroidStudio新建的项目,则把res文件夹下的所有文件删除(布局文件需要留着),然后拷贝Unity3d导出的Android项目的res文件夹下的所有文件
在Unity中使用Application.Quit退出时整个App都退出了,解决方法:

在AndroidManifest.xml文件中的UnityActivity的activity上配置

<!-- 给指定的Activity单独一个线程 -->
android:process=".unityplayer"
5)、加入Vuforia之后,出现的闪退情况使用以下方法解决

在这里插入图片描述

<string name="game_view_content_description">Game view</string>
ndk {
	abiFilters 'armeabi-v7a', 'x86'
}
6)、配置的EasyAR包名不一致

在这里插入图片描述

2、Unity导出Android项目打包Apk加载场景慢

在主项目的build.gradle中配置,可以在unity到处的项目的launcher项目的build.gradle中查看

aaptOptions {
	noCompress = ['.unity3d', '.ress', '.resource', '.obb']
}
另外在使用Application.Quit退出Unity场景后,再次进入需要重新加载,解决方法:

待解决

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值