Stable Version : 16.2.0
React Native Version : 0.55.4
Installation : npm install react-native-fcm
Recommended : npm install react-native-admob@2.0.0-beta.5
Configuration:
Android/build.gradle:
Add “google()” in maven repositoryAdd “maven {url "https://maven.google.com"}” in all project repository Example:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.google.gms:google-services:4.0.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
maven {url "https://maven.google.com"}
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
google()
}
}
Android/app/build:
Android compileSdkVersion : 27buildToolVersion :27.0.3
targetSdkVersion(recommended):27
Add “compile project(':react-native-fcm')” in dependencies
Add “compile 'com.google.firebase:firebase-core'”, compile 'com.google.firebase:firebase-messaging' in dependencies
Add “apply plugin: 'com.google.gms.google-services'” at the end of the file
Example:
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
defaultConfig {
applicationId "com.fbnotification"
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
dependencies {
compile project(':react-native-fcm')
compile fileTree(d00000000000000ir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+" // From node_modules
compile 'com.google.firebase:firebase-core'
compile 'com.google.firebase:firebase-messaging'
}
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
apply plugin: 'com.google.gms.google-services'
Android/app/src/main/AndroidManifest.xml:
Add some lines in manifest fileAdd FcmMessaging service under
Set app notification icon in <meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@mipmap/ic_launcher"/>
Change your own icon and set the icon path in the place of mipmap/ic_launcher
<Application>
<meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@mipmap/ic_launcher"/>
<meta-data android:name="com.google.firebase.messaging.default_notification_channel_id" android:value="my_default_channel"/>
<service android:name="com.evollu.react.fcm.MessagingService" android:enabled="true" android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<service android:name="com.evollu.react.fcm.InstanceIdService" android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
</Application>
Update gradle distribution url:
In Gradle/gradle-wrapper.properties you can find the gradle didtribution url version like this.distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip Update this version with : distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
Settings.gradle :
Add the following lines in settings.gradleinclude ':react-native-fcm'
project(':react-native-fcm').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-fcm/android')