React Native Navigation安卓应用崩溃:需使用Theme.AppCompat主题
Hey there, since your iOS build works perfectly but Android's giving you trouble after switching from react-navigation to react-native-navigation, let's walk through the most common fixes and checks to get it sorted.
First, Double-Check MainApplication.java
It looks like you only shared a snippet of this file—this is usually where the bulk of RNN's Android config lives. Make sure your full implementation matches this structure:
package com.client; import com.reactnativenavigation.NavigationApplication; import com.reactnativenavigation.react.NavigationReactNativeHost; import com.reactnativenavigation.react.ReactGateway; import java.util.Arrays; import java.util.List; import com.facebook.react.ReactPackage; public class MainApplication extends NavigationApplication { @Override protected ReactGateway createReactGateway() { NavigationReactNativeHost host = new NavigationReactNativeHost(this, isDebug(), createAdditionalReactPackages()) { @Override protected String getJSMainModuleName() { return "index"; // Confirm this matches your entry file name (e.g., index.js) } }; return new ReactGateway(this, isDebug(), host); } @Override public boolean isDebug() { return BuildConfig.DEBUG; } @Override public List<ReactPackage> createAdditionalReactPackages() { // Add any third-party React packages you're using here return Arrays.asList( // Example: new RNPushNotificationPackage() ); } }
Verify AndroidManifest.xml Settings
Your manifest needs to point to the correct application class and activity config:
- Ensure the
applicationtag uses your MainApplication:
<application android:name=".MainApplication" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" android:allowBackup="false" android:theme="@style/AppTheme">
- Check your MainActivity's theme and intent filter:
<activity android:name=".MainActivity" android:label="@string/app_name" android:theme="@style/SplashTheme" android:launchMode="singleTask"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
Check Your Splash Theme
If you haven't already, create a SplashTheme in res/values/styles.xml (this is required for RNN's SplashActivity):
<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar"> <!-- Use a drawable or solid color for the splash background --> <item name="android:windowBackground">@color/white</item> <item name="android:statusBarColor">@color/white</item> </style>
Gradle Configuration Checks
- In your project root's
build.gradle, confirm you've set compatible versions (match these to your React Native version):
ext { buildToolsVersion = "33.0.0" minSdkVersion = 21 compileSdkVersion = 33 targetSdkVersion = 33 rnnVersion = "7.37.0" // Use the latest compatible version with your RN setup }
- In
app/build.gradle, ensure you have the RNN dependencies:
dependencies { implementation fileTree(dir: "libs", include: ["*.jar"]) implementation "com.facebook.react:react-native:+" // Pulled from node_modules implementation "com.reactnativenavigation:navigation-react-native:${rootProject.ext.rnnVersion}" implementation "com.reactnativenavigation:navigation-android:${rootProject.ext.rnnVersion}" }
Clear Caches (Always a Good First Step)
- Clean Android build: Run
cd android && ./gradlew clean - Reset React Native cache: Run
npx react-native start --reset-cache - Uninstall the app from your device/emulator before rebuilding
Dig Into Error Logs
If none of the above works, grab the exact error messages from:
- The terminal when running
npx react-native run-android - Android Studio's Logcat (filter for "Error" or "Exception" to find critical issues)
Common culprits include missing packages, incompatible versions, or typos in class names.
内容的提问来源于stack exchange,提问作者Ata Mohammadi




