You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Unity安卓游戏部分机型崩溃,是否与Android Manifest相关?

安卓Unity游戏选相册图片后崩溃的Manifest排查与修复方案

我是Unity游戏开发新手,非安卓开发者。开发的安卓游戏需要访问相册,在华为Android 9系统上运行正常,但部分安卓机型打开相册选图后APK崩溃。怀疑问题和Android Manifest有关,使用了Asset Store的Android Photo Cropper插件,插件的Manifest内容如下:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.package.photocropper" android:versionName="1.0" android:versionCode="1" android:installLocation="preferExternal">
  <supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />
  <application>
    <activity android:label="@string/app_name" android:screenOrientation="fullSensor" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale" android:name="com.unity3d.player.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.UnityActisvity" android:value="true" />
    </activity>

    <activity android:name="com.photocropper.code.WebViewActivity" >
    </activity>
  </application>

  <uses-feature android:glEsVersion="0x00020000" />
  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="android.permission.READ_PHONE_STATE" />
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  <uses-permission android:name="android.permission.CAMERA" />
  <uses-permission android:name="android.permission.RECORD_AUDIO" />
  <uses-feature android:name="android.hardware.touchscreen" android:required="false" />
  <uses-feature android:name="android.hardware.touchscreen.multitouch" android:required="false" />
  <uses-feature android:name="android.hardware.touchscreen.multitouch.distinct" android:required="false" />
</manifest>

我曾尝试仅保留<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />权限,但问题仍未解决。


排查与修复步骤

  • 修正Manifest拼写错误
    插件Manifest里的UnityPlayerActivity存在拼写错误:<meta-data android:name="unityplayer.UnityActisvity" android:value="true" />,其中UnityActisvity应为UnityActivity(少了字母t)。这个错误会导致部分机型上Unity Activity初始化异常,选图返回时触发崩溃。

  • 适配Android 10+分区存储
    Android 10及以上采用分区存储机制,即使申请了READ_EXTERNAL_STORAGE,直接访问外部存储文件仍可能触发权限问题。需要在<application>标签中添加兼容配置:

    <application android:requestLegacyExternalStorage="true">
        <!-- 原有Activity配置 -->
    </application>
    
  • 调整Activity启动模式与配置
    插件中UnityPlayerActivity使用了launchMode="singleTask",部分机型上从相册返回时会导致Activity栈异常。可尝试改为launchMode="singleTop",同时确保相册返回的Intent处理逻辑正确。另外,确认configChanges覆盖了所有必要配置,避免因屏幕旋转等变化导致Activity重启崩溃。

  • 完善WebViewActivity配置
    WebViewActivity未添加configChanges配置,部分机型上选图返回时若发生屏幕方向等配置变化,会导致该Activity重启崩溃。建议添加和UnityPlayerActivity一致的configChanges:

    <activity android:name="com.photocropper.code.WebViewActivity"
              android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale">
    </activity>
    
  • 清理冗余权限
    插件Manifest包含大量不必要权限(如READ_PHONE_STATE、RECORD_AUDIO),虽不直接导致崩溃,但可能触发部分机型的安全机制。建议仅保留必要权限:READ_EXTERNAL_STORAGE、WRITE_EXTERNAL_STORAGE(若需保存裁剪后图片)、CAMERA(若插件支持拍照裁剪)。

  • 获取崩溃日志定位根因
    通过adb命令获取崩溃日志,直接定位具体报错信息(如空指针、权限异常、Activity未找到等):

    adb logcat -s Unity AndroidRuntime
    

内容的提问来源于stack exchange,提问作者crymea rvr

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 09:02:57