您的位置:首页 > 移动开发 > Unity3D

在Android4.0.1上,Unity3D游戏在加载场景时崩溃(译)

2013-10-21 11:05 357 查看
原文链接:http://www.atomic-gear.net/2012/07/unity3d-game-crashes-during-loading-screen-on-android-4-0-1-android-ics/

原文标题:Unity3D game crashes during loading screen on Android 4.0.1 (Android ICS)

一句话翻译:为了使得Unity3D在Android4.0.1机器上正常运行,需要在AndroidManifest.xml里面给Activity加上android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen"属性,这也就是为什么360SDK的文档里面会要求编译时使用API17以上版本。具体原因请详细看e文。

One common issue people having on the
Unity3D Android Forums and keep asking over and over is a certain crash issue, which happens during the start of the Unity3D game app on Android 4.0.1 (Ice
Cream Sandwich).

This is a very common error, which happens when old apps are being ported to Android 4.0.1 (ICS). With
Android 4.0.1, new configOrientation options were added, due to the new design changes in the Android Operating System.

<activity
android:configChanges=["mcc", "mnc", "locale",
"touchscreen", "keyboard", "keyboardHidden",
"navigation", "screenLayout", "fontScale", "uiMode",
"orientation", "screenSize", "smallestScreenSize"]


The last 3 options – orientation, screenSize andsmallestScreenSize – where added with Android 4.0 ICS. Unity3D 3.5 added support for those and since then Unity3D needs to be built against Android API 13 (ICS).

When these are missing in the AndroidManifest.xml’s activity declaration, then Unity3D won’t get notified when this events occurs and can’t do the necessary steps to react on it.

One of the reason this events were added was because the new Android 4.0 devices have no physical buttons and the buttons appear as part of the display which get displayed or hidden depending on the current applications context.

orientationThe screen orientation has changed — the user has rotated the device.

Note: If your application targets API level 13 or higher (as declared by the minSdkVersion and targetSdkVersion attributes), then you should also declare the “screenSize” configuration, because it also changes when a device switches between
portrait and landscape orientations.
screenSizeThe current available screen size has changed. This represents a change in the currently available size, relative to the current aspect ratio, so will change when the user switches between landscape and portrait. However, if your application targets API
level 12 or lower, then your activity always handles this configuration change itself (this configuration change does not restart your activity, even when running on an Android 3.2 or higher device).

Added in API level 13.
smallestScreenSizeThe physical screen size has changed. This represents a change in size regardless of orientation, so will only change when the actual physical screen size has changed such as switching to an external display. A change to this configuration corresponds to
a change in the smallestWidth configuration. However, if your application targets API level 12 or lower, then your activity always handles this configuration change itself (this configuration change does not restart your activity, even when running on an Android
3.2 or higher device).

Added in API level 13
By default, Unity3D uses it’s own AndroidManifest.xml file, which can be found atC:\Program Files (x86)\Unity\Editor\Data\PlaybackEngines\androiddevelopmentplayer\AndroidManifest.xml on Windows Vista and Windows 7 or inC:\Program Files\Unity\Editor\Data\PlaybackEngines\androiddevelopmentplayer\AndroidManifest.xml
on older Windows versions.

But when the users place their own AndroidManifest.xml file in the Unity3D project’sAssets/Plugins/Android folder, Unity3D include this file into the final APK. Usually people take a copy of this file, place it in theAssets/Plugins/Android
and modify it for their needs. There are also some Eclipse integration example projects, which makes it easier creating an Eclipse project which can be later included into Unity3d build process (i.e. exporting the Eclipse project as Android.jar and placing
it in Assets/Plugins/Android folder) and they use an outdated AndroidManifest.xml file too.

In order to fix that, the AndroidManifest.xml file needs to be updated and the missing configChanges and change them to

android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen"


This is what the default Unity3D AndroidManifest.xml file from version 3.5 does. A complete example AndroidManifest.xml can be found below.

<?xmlversion="1.0"encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.unity3d.player"
android:installLocation="preferExternal"
android:versionCode="1"
android:versionName="1.0">
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true"/>

<application
android:icon="@drawable/app_icon"
android:label="@string/app_name"
android:debuggable="true">
<activityandroid:name="com.unity3d.player.UnityPlayerProxyActivity"
android:label="@string/app_name"
android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
<intent-filter>
<actionandroid:name="android.intent.action.MAIN"/>
<categoryandroid:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activityandroid:name="com.unity3d.player.UnityPlayerActivity"
android:label="@string/app_name"
android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
</activity>
<activityandroid:name="com.unity3d.player.UnityPlayerNativeActivity"
android:label="@string/app_name"
android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
<meta-dataandroid:name="android.app.lib_name"android:value="unity"/>
<meta-dataandroid:name="unityplayer.ForwardNativeEventsToDalvik"android:value="false"/>
</activity>
<activityandroid:name="com.unity3d.player.VideoPlayer"
android:label="@string/app_name"
android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
</activity>
</application>
</manifest>


If that doesn’t help solving the problem, disabling auto screen-rotation often helps, i.e. by adding

android:screenOrientation="landscape"

to the tag and/or setting it in Unity3D Android player settings
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: