React Native运行run-android安卓构建失败:FCM推送配置遇错求助
Hey there, let's work through this push notification setup issue with react-native-fcm on your older React Native stack. Since you followed the GitHub guide but hit build failures, here are targeted checks to help you nail down the problem:
1. Confirm Dependency Version Compatibility
React Native 0.53 is a fairly old version, so you need to make sure you're using a compatible version of react-native-fcm (likely v16.x or earlier, since newer versions dropped support for older RN releases). Also, verify your Firebase dependencies in android/app/build.gradle match the version required by your react-native-fcm package—mismatched versions are a super common cause of build crashes.
2. Validate AndroidManifest.xml Configs
Even though you didn't share your manifest code, these are non-negotiable entries for FCM to work:
- Ensure you've declared the FCM messaging service:
<service android:name="com.evollu.react.fcm.MessagingService"> <intent-filter> <action android:name="com.google.firebase.MESSAGING_EVENT" /> </intent-filter> </service> - Add the required permissions and C2D message permissions:
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <permission android:name="${applicationId}.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="${applicationId}.permission.C2D_MESSAGE" /> - Double-check that your
google-services.jsonis placed correctly in theandroid/appdirectory—this file is mandatory for Firebase to initialize properly.
3. Fix Gradle Configuration Issues
Older Android Studio and RN versions have specific Gradle requirements:
- In your root
build.gradle, confirm you have the Google Maven repo and the correct Google Services plugin classpath:buildscript { repositories { jcenter() maven { url 'https://maven.google.com' } // Or `google()` for newer AS, but 3.0.1 may need this } dependencies { classpath 'com.android.tools.build:gradle:3.0.1' // Match your Android Studio version classpath 'com.google.gms:google-services:3.2.1' // Compatible with RN 0.53 } } - In
android/app/build.gradle, make sure the Google Services plugin is applied at the very bottom of the file:apply plugin: 'com.google.gms.google-services' - Ensure your
compileSdkVersionis set to 26,buildToolsVersionto 26.0.2, andtargetSdkVersionto 26—these are the recommended values for RN 0.53.
4. Clear Build Cache and Resolve Conflicts
Old cache and dependency conflicts often cause cryptic errors:
- Run these commands to clean your build:
cd android ./gradlew clean cd .. react-native run-android - If you see dependency conflict errors (like mismatched Google Play Services versions), force a unified version in
android/app/build.gradle:
Adjust the version numbers to match what yourconfigurations.all { resolutionStrategy.force 'com.google.android.gms:play-services-base:16.0.1' resolutionStrategy.force 'com.google.firebase:firebase-core:16.0.9' }react-native-fcmpackage requires.
5. Share Exact Error Logs
The most critical piece missing here is the full build error message. Next time you run react-native run-android, copy everything from FAILURE: Build failed with an exception onward—this will tell us exactly what's breaking (e.g., missing class, manifest merge conflict, dependency mismatch).
内容的提问来源于stack exchange,提问作者datainsights

