Skip to content

Commit

Permalink
Merge pull request #1012 from windhamwong/patch-1
Browse files Browse the repository at this point in the history
Update README.md
  • Loading branch information
Libin Lu authored Aug 17, 2018
2 parents c35a853 + e165b82 commit 35893bb
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 51 deletions.
103 changes: 55 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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-<resolution>/` folder. Feel free to change the filename if you have a customised icon for notification.

```diff
<application
Expand All @@ -90,42 +124,12 @@ https://github.com/evollu/react-native-fcm/blob/master/Examples/simple-fcm-clien
...
```

- Edit `{YOUR_MAIN_PROJECT}/build.gradle`:
```diff
buildscript {
repositories {
jcenter()
+ maven {
+ url 'https://maven.google.com/'
+ name 'Google'
+ }
}
dependencies {
+ classpath 'com.android.tools.build:gradle:3.1.1'
+ classpath 'com.google.gms:google-services:3.1.2'
### Edit `android/app/build.gradle`:

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
**NOTE:** after v16.0.0, Android target SDK has be to >= 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"
Expand All @@ -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'
Expand All @@ -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<ReactPackage> getPackages() {
Expand Down
6 changes: 3 additions & 3 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 35893bb

Please sign in to comment.