DinDan DinDan - 19 days ago 10
Android Question

How to install android push notification in react native project?

I am trying to install android push notification like this:
react-native-push-notification

But when I trying to build my app with

react-native run-android
, I get this error:

BUILD FAILED

Total time: 2.666 secs
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/android-setup.html


D:\react\react-WriteNow>run
JS server already running.
Running C:\Program Files (x86)\Android\android-sdk/platform-tools/adb -s ce051605a9626a3304 reverse tcp:8081 tcp:8081
Building and installing the app on the device (cd android && gradlew.bat installDebug...
please apply google-services plugin at the bottom of the build file.
google-services plugin could not detect any version for com.google.android.gms or com.google.firebase, default version: 9.0.0 will be used.
please apply google-services plugin at the bottom of the build file.

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'WriteNow'.
> java.lang.NullPointerException (no error message)


my files:
android/app/build.gradle:

dependencies {
// compile ('com.google.android.gms:play-services-gcm:9.0.0') {
// force = true;
// }

compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+" // From node_modules
compile "com.facebook.android:facebook-android-sdk:4.8.+"
compile "com.android.support:support-v13:23+"
compile ('com.google.android.gms:play-services-gcm:8.4.0') {
force = true;
}
compile project(':react-native-push-notification')
compile project(':react-native-sqlite-storage')
compile project(':react-native-image-picker')
compile project(':react-native-vector-icons')
compile project(':react-native-contacts')


}
apply plugin: "com.google.gms.google-services"


android/settings.gradle

buildscript {
repositories {
mavenCentral()
jcenter()

}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
classpath 'com.google.gms:google-services:3.0.0'
}
}

allprojects {
repositories {
mavenLocal()
jcenter()
maven {
url "$rootDir/../node_modules/react-native/android"
}
}
}
apply plugin: "com.google.gms.google-services"


enter image description here

Any idea why it is not working?

Answer

This command fix the problem:

android update sdk -u -a -t