android 集成 unity 3d 错误
1.资源找不到
java.lang.RuntimeException:
Unable to start activity ComponentInfo{com.what.mobile.maintenance/com.unity3d.player.UnityPlayerActivity}:
android.content.res.Resources$NotFoundException: String resource ID #0x0
Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x0
解决方案
在string.xml中添加
<string name="game_view_content_description"></string>
2.jar包找不到
在项目配置页面添加
flatDir {
dirs "${project(':unityLibrary').projectDir}/libs"
}
allprojects {
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
maven { url = "https://dl.bintray.com/kotlin/kotlin-eap" }
maven { url "https://jitpack.io" }
flatDir {
dirs "${project(':unityLibrary').projectDir}/libs"
}
}
}
3.UnityPlayer 找不到
修改unityLibrary中的包引入
修改 implementation 为api
implementation类似于“praivte”
api类似于“public”,
dependencies {
api fileTree(dir: 'libs', include: ['*.jar'])
implementation(name: 'unity-ads', ext:'aar')
}
4.unity 退出app也退出
修改unityLibrary的manifest
添加 android:process=":unity"启用独立线程
注销 启动设置
<!-- <intent-filter>-->
<!-- <action android:name="android.intent.action.MAIN" />-->
<!-- <category android:name="android.intent.category.LAUNCHER" />-->
<!-- </intent-filter>-->
<activity
android:name="com.unity3d.player.UnityPlayerActivity"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection"
android:hardwareAccelerated="false"
android:launchMode="singleTask"
android:screenOrientation="fullSensor"
android:process=":unity"
android:theme="@style/UnityThemeSelector">
<!-- <intent-filter>-->
<!-- <action android:name="android.intent.action.MAIN" />-->
<!-- <category android:name="android.intent.category.LAUNCHER" />-->
<!-- </intent-filter>-->
<meta-data
android:name="unityplayer.UnityActivity"
android:value="true" />
<meta-data
android:name="android.notch_support"
android:value="true" />
</activity>