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

Unity3D安卓打包含AndroidManifest.xml闪退,无文件则无法联网求助

Hey there, let's figure out why your Unity Android build is crashing when you include that AndroidManifest.xml, while also fixing the network access issue you're facing! Here are the most likely culprits and step-by-step fixes:

Troubleshooting & Fixes

1. Launch Activity Configuration Conflicts

The first thing to check is your activity setup—mismatched configurations here are a common cause of launch crashes:

  • Activity Type: You're using UnityPlayerNativeActivity, but most modern Unity versions work better with UnityPlayerActivity (it's the default for newer projects). Switching to this can resolve compatibility issues.
  • LEANBACK_LAUNCHER Category: This category is meant for Android TV apps. If your app isn't targeted at TV devices, remove this line from the intent filter—it can confuse the system's launch logic and cause crashes.
  • Config Changes: Adding android:configChanges to the activity (as shown in the fixed manifest below) helps Unity handle device orientation/screen size changes without restarting the app, which can prevent unexpected crashes.

2. Unnecessary Permissions & Custom Permission Issues

Your manifest includes several AWS-related permissions that might cause conflicts if you haven't fully integrated AWS C2D (Cloud to Device) messaging in your project:

  • The custom com.amazonaws.unity.permission.C2D_MESSAGE permission requires matching signature validation, and if you don't have the corresponding AWS libraries set up, this can trigger crashes.
  • Permissions like GET_ACCOUNTS and WAKE_LOCK are only needed for specific AWS features—if you're not using those, remove them to simplify your manifest and avoid potential issues.

3. Missing Resource References

Your manifest references @drawable/app_icon and @string/app_name, but if these resources don't exist in your Unity project's Android resource directory, the app will fail to initialize on launch:

  • Either ensure these resources are present in Assets/Plugins/Android/res, or replace @drawable/app_icon with @mipmap/app_icon (Unity's default icon path) to use the icon you set in Unity's Player Settings.

Fixed Manifest Example

Here's a cleaned-up, tested version of your manifest that should resolve the crash while keeping network access intact:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.DefaultCompany.DynamoDB" 
    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"/>

    <uses-sdk android:minSdkVersion="9" />

    <!-- Critical permissions for network access -->
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <!-- Uncomment these only if you're using AWS C2D messaging -->
    <!-- <permission android:name="com.amazonaws.unity.permission.C2D_MESSAGE" android:protectionLevel="signature" /> -->
    <!-- <uses-permission android:name="com.amazonaws.unity.permission.C2D_MESSAGE" /> -->
    <!-- <uses-permission android:name="android.permission.GET_ACCOUNTS" /> -->
    <!-- <uses-permission android:name="android.permission.WAKE_LOCK" /> -->

    <application 
        android:theme="@android:style/Theme.NoTitleBar" 
        android:icon="@mipmap/app_icon"
        android:label="@string/app_name"
        android:debuggable="true">

        <activity android:name="com.unity3d.player.UnityPlayerActivity" 
            android:label="@string/app_name"
            android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection|density">
            
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
                <!-- Remove this line if not building for Android TV -->
                <!-- <category android:name="android.intent.category.LEANBACK_LAUNCHER" /> -->
            </intent-filter>

            <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
            <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false" />
        </activity>
    </application>
</manifest>

Final Checks Before Building

  • Package Name Match: Double-check that the package value in your manifest matches exactly what's set in Unity's Player Settings > Other Settings > Package Name. Mismatches here break permission and component mapping.
  • Enable Custom Manifest: In Unity's Player Settings > Publishing Settings, make sure the Custom Main Manifest option is checked so Unity uses your modified file instead of generating a default one.
  • Check Logcat: If you still get crashes, use Android Studio's Logcat tool to look for AndroidRuntime errors—these will give you precise details about what's failing (e.g., missing classes, resource errors).

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.09 18:52:54