cordova-plugin-firebase: Error on second build

Hello, Thank you for this project and your great job!

I have problem in ionic project. First, I add the string in my config.xml: <plugin name="cordova-plugin-firebase" spec="https://github.com/arnesson/cordova-plugin-firebase" /> Second, I put google-services.json (which I got from firebase web console) in root directory. I run my build, and this works:

$ cordova run android
Running command: /home/user/android-app/App/hooks/after_prepare/010_add_platform_class.js /home/user/android-app/App
add to body class: platform-android
**Discovered plugin "cordova-plugin-firebase" in config.xml. Adding it to the project**
Fetching plugin "https://github.com/arnesson/cordova-plugin-firebase" via git clone
Repository "https://github.com/arnesson/cordova-plugin-firebase" checked out to git ref "master".
Installing "cordova-plugin-firebase" for android
ANDROID_HOME=/home/user/Android/Sdk/
JAVA_HOME=/opt/java/jdk1.8.0_92
No target specified, deploying to device 'F9AZCY31J032'.
:preBuild UP-TO-DATE

But my second build always fails…

$ cordova run android
Running command: /home/user/android-app/App/hooks/after_prepare/010_add_platform_class.js /home/user/android-app/App
add to body class: platform-android
Error: Invalid data, chunk must be a string or buffer, not object

I was trying to install plugin by cordova plugin add https://github.com/arnesson/cordova-plugin-firebase.git --save. But in this case even first build crashes with Error: Invalid data, chunk must be a string or buffer, not object

And when I start android application with first build, code below doesn’t work for me:

angular.module('app', ['ionic', 'app.controllers', 'app.routes', 'app.services', 'app.directives', 'firebase'])

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
    // for form inputs)
    if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
      cordova.plugins.Keyboard.disableScroll(true);
    }
    if (window.StatusBar) {
      // org.apache.cordova.statusbar required
      StatusBar.styleDefault();
    }

    window.FirebasePlugin.getInstanceId(function(token) {
      // save this server-side and use it to push notifications to this device
      console.log("Token", token);
    }, function(error) {
      console.error(error);
    });

  });
})

This code returns [“Token”, “null”] to console.

Thank you in advance.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 22 (4 by maintainers)

Commits related to this issue

Most upvoted comments

@raducostea - I suggest you to use APN (Apple Push Notification). Here is the link of plugin: https://github.com/phonegap-build/PushPlugin. It is working very accurately for me in iOS.

Reinstalling cordova-plugin-firebase worked for me

I facing the same issue with ionic. I fix that by remove platform and plugin then add again platform and plugin, then everything is completely normal again. For this issue in ionic 2 I write this tutorial.

Having a GoogleService-Info.plist when there’s no ios platform will cause the “second build error”. I’d recommend GoogleService-Info.plist is copied only if platform/ios exists…

You can patch after_prepare.js to work around this, though I’ve not tested my patch yet. I’ll post it if it works