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:
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 withUnityPlayerActivity(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:configChangesto 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_MESSAGEpermission requires matching signature validation, and if you don't have the corresponding AWS libraries set up, this can trigger crashes. - Permissions like
GET_ACCOUNTSandWAKE_LOCKare 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_iconwith@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
packagevalue in your manifest matches exactly what's set in Unity'sPlayer 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
AndroidRuntimeerrors—these will give you precise details about what's failing (e.g., missing classes, resource errors).
内容的提问来源于stack exchange,提问作者Shway

