diff --git a/README.md b/README.md index c4e4f1cb74216d8904033fe76a25b38347e04d76..77daca95f0feb090bc946705c117d9b647ffcd8b 100644 --- a/README.md +++ b/README.md @@ -39,33 +39,67 @@ I've created [an example project](https://github.com/evollu/react-native-fcm/tre ### FCM config file In [firebase console](https://console.firebase.google.com/), you can: -- for **Android**: download `google-services.json` file and place it in `android/app` directory +- for **Android**: download `google-services.json` file and place it in `android/app` directory. - for **iOS**: download `GoogleService-Info.plist` file and place it in `/ios/your-project-name` directory (next to your `Info.plist`) Make sure you have certificates setup by following https://firebase.google.com/docs/cloud-messaging/ios/certs +--- + ## Android Configuration - As `react-native link` sometimes has glitches, make sure you have this line added -https://github.com/evollu/react-native-fcm/blob/master/Examples/simple-fcm-client/android/app/src/main/java/com/google/firebase/quickstart/fcm/MainApplication.java#L28 +### Edit `android/build.gradle`: + +**NOTE:** The followed line may not be up-to-dated. Please refer to https://firebase.google.com/docs/android/setup -- Edit `android/build.gradle`: -```diff - dependencies { - classpath 'com.android.tools.build:gradle:2.0.0' -+ classpath 'com.google.gms:google-services:3.0.0' ``` +buildscript { + repositories { + // ... + google() // Google's Maven repository + } + // ... + dependencies { + // ... + classpath 'com.google.gms:google-services:4.0.2' // google-services plugin + } +} -- Edit `android/app/build.gradle`. Add at the bottom of the file: -```diff - apply plugin: "com.android.application" - ... -+ apply plugin: 'com.google.gms.google-services' +allprojects { + // ... + repositories { + // ... + google() // Google's Maven repository + } +} ``` -- Edit `android/app/src/main/AndroidManifest.xml`: +### Edit `android/app/build.gradle`: + +**NOTE:** Please refer to https://firebase.google.com/docs/android/setup + +``` +dependencies { + // ... + compile project(':react-native-fcm') + + // ... + + // Automatically selecting the latest available version + implementation 'com.google.firebase:firebase-core' + implementation 'com.google.firebase:firebase-messaging' +} + +// ADD THIS AT THE BOTTOM +apply plugin: 'com.google.gms.google-services' +``` + +### Edit `android/app/src/main/AndroidManifest.xml`: + +**NOTE:** The resource `@mipmap/ic_notif` is referring to `android/app/src/res/mipmap-/` folder. Feel free to change the filename if you have a customised icon for notification. ```diff = 26 and build tool has to be >= 26.0.x -allprojects { - repositories { - mavenLocal() - jcenter() - maven { - // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm - url "$rootDir/../node_modules/react-native/android" - } -+ maven { -+ url 'https://maven.google.com/' -+ name 'Google' -+ } - } -} -``` +**NOTE:** Make sure the version matches this library. -- Edit `{YOUR_MAIN_PROJECT}/app/build.gradle`: ```diff + compileSdkVersion 27 + buildToolsVersion "27.0.3" @@ -152,7 +156,7 @@ allprojects { ``` If you are using other firebase libraries, check this for solving dependency conflicts https://github.com/evollu/react-native-fcm/blob/master/Examples/simple-fcm-client/android/app/build.gradle#L133 -- Edit `android/settings.gradle` +### Edit `android/settings.gradle` ```diff ... + include ':react-native-fcm' @@ -173,7 +177,10 @@ public class MainActivity extends ReactActivity { } ``` -- Make sure in `MainApplication.java` you have +### Make sure in `MainApplication.java` you have the code below: + +**NOTE:** The packages listed inside should appear once only. `react-native link` sometimes can mess up this part, please remove duplicated packeges. + ```diff @Override protected List getPackages() { diff --git a/android/build.gradle b/android/build.gradle index 8e2d0078c0f565e92c466752622d35b94a974c66..b5f66bfbbfc266c30054426161385156036094a1 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -3,9 +3,9 @@ apply plugin: 'com.android.library' def DEFAULT_COMPILE_SDK_VERSION = 27 def DEFAULT_BUILD_TOOLS_VERSION = "27.0.3" def DEFAULT_TARGET_SDK_VERSION = 27 -def DEFAULT_GOOGLE_PLAY_SERVICES_VERSION = "12.+" -def DEFAULT_FIREBASE_CORE_VERSION = "12.+" -def DEFAULT_FIREBASE_MESSAGING_VERSION = "12.+" +def DEFAULT_GOOGLE_PLAY_SERVICES_VERSION = "+" +def DEFAULT_FIREBASE_CORE_VERSION = "+" +def DEFAULT_FIREBASE_MESSAGING_VERSION = "+" android { compileSdkVersion project.hasProperty('compileSdkVersion') ? project.compileSdkVersion : DEFAULT_COMPILE_SDK_VERSION