原文标题: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.
orientation | The 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. |
screenSize | The 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. |
smallestScreenSize | The 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.