【问题标题】:How to install android push notification in react native project?如何在反应原生项目中安装 android 推送通知?
【发布时间】:2023-03-11 11:45:02
【问题描述】:

我正在尝试像这样安装 android 推送通知: react-native-push-notification

但是当我尝试使用react-native run-android 构建我的应用程序时,我收到了这个错误:

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)

我的文件: 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"

知道为什么它不起作用吗?

【问题讨论】:

    标签: android push-notification react-native


    【解决方案1】:

    此命令修复问题:

    android update sdk -u -a -t

    【讨论】:

      猜你喜欢
      • 2016-05-29
      • 2017-12-18
      • 1970-01-01
      • 1970-01-01
      • 2018-01-17
      • 1970-01-01
      • 1970-01-01
      • 2020-05-07
      • 1970-01-01
      相关资源
      最近更新 更多