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

React Native运行run-android安卓构建失败:FCM推送配置遇错求助

Troubleshooting React Native FCM Push Notification Build Errors (RN 0.53, Android Studio 3.0.1)

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.json is placed correctly in the android/app directory—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 compileSdkVersion is set to 26, buildToolsVersion to 26.0.2, and targetSdkVersion to 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:
    configurations.all {
        resolutionStrategy.force 'com.google.android.gms:play-services-base:16.0.1'
        resolutionStrategy.force 'com.google.firebase:firebase-core:16.0.9'
    }
    
    Adjust the version numbers to match what your react-native-fcm package 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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 09:15:15