Search code examples
androidfirebasefirebase-cloud-messagingnativescriptnativescript-plugin

Error while initializing firabase.init() from Nativescript firebase plugin


I'm trying to use native script firebase plugin for FCM in order to implement push notification in my native script app. But when I'm trying to initiate firebase by calling firebase init according to documentation.

  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);
    });

I am getting this 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)

But During the plugin installation, I only set yes to cloud messaging and Android platform.I am not using firebase authentication. For facebook login, I'm using the native-script-OAuth plugin.

This is the include.gradle from the nativescript-plugin-firebase/platform/android

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"

It would be great if someone helps me on this.


Solution

  • ok, the problem occurred because of native-script facebook plugin. I also installed native-script-facebook plugin earlier which was causing this issue. It might be a plugin conflict or something. After uninstalling native-script facebook it has been solved now.