1

我正在尝试对FCM使用本机脚本 firebase插件,以便在我的本机脚本应用程序中实现推送通知。但是当我试图通过根据文档调用 firebase init 来启动 firebase 时。

  firebase.init({
        onMessageReceivedCallback: function(message) {
            console.log("Title: " + message.title);
            console.log("Body: " + message.body);
            // if your server passed a custom property called 'foo', then do this:
            console.log("Value of 'foo': " + message.data.foo);
        }
    }).then(function (instance) {
        console.log("firebase.init done");
    }, function (error) {
        console.log("firebase.init error: " + error);
    });

我收到此错误

Error in firebase.init: Error: A valid Facebook app id must be set in the AndroidManifest.xml or set by calling FacebookSdk.setApplicationId before initializing the sdk.
com.facebook.FacebookSdk.sdkInitialize(FacebookSdk.java:275)
com.facebook.FacebookSdk.sdkInitialize(FacebookSdk.java:231)
com.tns.Runtime.callJSMethodNative(Native Method)
com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1088)
com.tns.Runtime.callJSMethodImpl(Runtime.java:970)
com.tns.Runtime.callJSMethod(Runtime.java:957)
com.tns.Runtime.callJSMethod(Runtime.java:941)
com.tns.Runtime.callJSMethod(Runtime.java:933)
com.tns.gen.android.view.GestureDetector_SimpleOnGestureListener_frnal_ts_helpers_l58_c38__TapAndDoubleTapGestureListenerImpl.onSingleTapUp(GestureDetector_SimpleOnGestureListener_frnal_ts_helpers_l58_c38__TapAndDoubleTapGestureListenerImpl.java:12)
android.view.GestureDetector.onTouchEvent(GestureDetector.java:635)
android.support.v4.view.GestureDetectorCompat$GestureDetectorCompatImplJellybeanMr2.onTouchEvent(GestureDetectorCompat.java:480)
android.support.v4.view.GestureDetectorCompat.onTouchEvent(GestureDetectorCompat.java:543)
com.tns.Runtime.callJSMethodNative(Native Method)
com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1088)
com.tns.Runtime.callJSMethodImpl(Runtime.java:970)
com.tns.Runtime.callJSMethod(Runtime.java:957)
com.tns.Runtime.callJSMethod(Runtime.java:941)
com.tns.Runtime.callJSMethod(Runtime.java:933)

但是在插件安装过程中,我只对云消息Android平台设置了yes 。我没有使用firebase身份验证。对于 facebook 登录,我使用的是native-script-OAuth插件。

这是来自nativescript-plugin-firebase/platform/android的include.gradle

android {
   productFlavors {
     "fireb" {
        dimension "fireb"
      }
  }
}

repositories {
   jcenter()
    mavenCentral()
    maven {
       url "https://maven.google.com"
   }
}

def supportVersion = project.hasProperty("supportVersion") ? project.supportVersion : "26.0.0"

dependencies {
    compile "com.android.support:appcompat-v7:$supportVersion"
    compile "com.android.support:cardview-v7:$supportVersion"
    compile "com.android.support:customtabs:$supportVersion"
    compile "com.android.support:design:$supportVersion"
    compile "com.android.support:support-compat:$supportVersion"

     def firebaseVersion = "12.0.1"

    // make sure you have these versions by updating your local Android SDK's (Android Support repo and Google repo)
  compile "com.google.firebase:firebase-core:$firebaseVersion"
  compile "com.google.firebase:firebase-auth:$firebaseVersion"

  // for reading google-services.json and configuration
   def googlePlayServicesVersion = 
    project.hasProperty('googlePlayServicesVersion') ? 
    project.googlePlayServicesVersion : firebaseVersion
    compile "com.google.android.gms:play-services-
   base:$googlePlayServicesVersion"

   // Uncomment if you want to use the regular Database
  // compile "com.google.firebase:firebase-database:$firebaseVersion"

  // Uncomment if you want to use 'Cloud Firestore'
  // compile "com.google.firebase:firebase-firestore:$firebaseVersion"

  // Uncomment if you want to use 'Remote Config'
  // compile "com.google.firebase:firebase-config:$firebaseVersion"

  // Uncomment if you want to use 'Crash Reporting'
  // compile "com.google.firebase:firebase-crash:$firebaseVersion"

  // Uncomment if you want FCM (Firebase Cloud Messaging)
 compile "com.google.firebase:firebase-messaging:$firebaseVersion"

  // Uncomment if you want Google Cloud Storage
  // compile "com.google.firebase:firebase-storage:$firebaseVersion"

  // Uncomment if you want AdMob
  // compile "com.google.firebase:firebase-ads:$firebaseVersion"

  // Uncomment if you need Facebook Authentication
  // compile ("com.facebook.android:facebook-android-sdk:4.+"){ exclude group: 'com.google.zxing' }

  // Uncomment if you need Google Sign-In Authentication
  // compile "com.google.android.gms:play-services-auth:$googlePlayServicesVersion"

  // Uncomment if you need Firebase Invites or Dynamic Links
  // compile "com.google.firebase:firebase-invites:$firebaseVersion"
}
apply plugin: "com.google.gms.google-services"

如果有人在这方面帮助我,那就太好了。

4

1 回答 1

1

好的,问题是由于本机脚本 facebook插件而发生的。我之前还安装了导致此问题的 native-script-facebook插件。可能是插件冲突什么的。卸载本机脚本 facebook 后,现在已解决。

于 2018-04-08T17:13:25.603 回答