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

原文链接: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

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 要下载Android Studio 4.0.1,首先需要确保您的计算机系统符合下载要求,例如操作系统版本、处理器类型和运行内存等。然后,您可以访问Android Studio的官方网站,在下载页面上选择合适的下载包,如Windows版、macOS版或Linux版。在下载之前,您还需同意开源许可协议,以便使用Android Studio并获得最新的更新。下载完成后,您就可以运行安装程序进行安装。在安装过程中,您需要确认一些设置,如安装位置、应安装的工具和选项等,同还需保证网络连接正常以便下载所需的库文件和模板。安装完成后,请在启动Android Studio之前确认您的计算机性能满足最低要求,否则可能会影响应用程序开发效率和体验。如果需要更多安装指导和使用教程,请参考官方文档和社区论坛等资源。 ### 回答2: 要下载Android Studio 4.0.1,首先您需要访问Android官方网站,选择下载页面。在这个页面上,您将看到最新版本的Android Studio已经被列出了。然后,您可以点击“Download”按钮,以开始下载Android Studio 4.0.1。 当然,在下载之前,您需要确认您的个人电脑或笔记本电脑已经满足了Android Studio的最小要求,如1.6 GHz的64位处理器,4GB RAM,和至少2GB的硬盘空间等等。 一旦下载完成,您需要打开安装程序并完成安装。在安装过程中,安装程序将提示您选择安装组件和安装位置等。一旦所有的步骤都完成,Android Studio 4.0.1就会被完全安装,并准备为您创建和开发Android应用程序。 您还可以更新现有的Android Studio软件,以便升级到最新的4.0.1版本。只需执行软件中的“检查更新”操作,软件会自动检测并下载升级,并按照上述过程进行安装。 总的来说,下载和安装Android Studio 4.0.1是非常简单的。因为Android Studio是由Google官方发布的,因此您可以放心使用它来构建和开发您的Android应用程序。 ### 回答3: Android Studio是由Google开发的开发工具,旨在为开发人员提供最佳的Android应用程序开发体验。在Android Studio中,可以使用Java、Kotlin等编程语言来开发应用程序,并且提供丰富的工具和组件库来简化开发过程。 要下载Android Studio 4.0.1,可以直接访问官方网站进行下载。安装过程非常简单,只需要按照提示操作即可。安装完成后,开发人员可以开始使用Android Studio创建项目、添加依赖关系、编写代码并生成应用程序。此外,Android Studio还提供了实预览等功能,方便开发人员在开发过程中进行测试和调试。 总之,Android Studio是一款非常强大、易于使用的Android开发工具。通过下载和使用Android Studio 4.0.1,开发人员可以轻松地创建高质量、高效率的Android应用程序。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值