Open cyclonmaster-zz opened 7 years ago
+1
+1
I get same problem, i solve this issue by running "ionic platform update android"
+1
Same here. Can't do anything until I remove the plugin.
Possible solution:
The first google-services.json I got didn't have an API key.
I opened the firebase project settings and re-downloaded the file. Now it contained the API key and it's working.
Same error here, this work for me: open file platforms/andoid/res/values/strings.xml then add 2 rows (that there aren't present):
I add the string:
Still; get the same problem. Any help here?
It just platform issue, try to remove and add the platform, also remove and add the plugin. I write this solution in my tutorial.
I was able to "fix it" by renaming (e.g. resetup/recreate App) the App from something like
Test App & Test
to
Test App and Test
As far as i can tell the & or &
caused those problems on iOS devices
I resolve with:
ionic platform rm android
ionic platform rm ios
ionic plugin rm cordova-plugin-firebase
ionic platform add android
ionic platform add ios
ionic plugin add cordova-plugin-firebase
any one still having this error do this ionic platform rm android ionic platform rm ios ionic plugin rm cordova-plugin-firebase ionic platform add android ionic platform add ios ionic plugin add cordova-plugin-firebase
copy the GoogleService-Info.plist into platforms/ios/'app name'/Resources and make sure no other copy exist within the project..
for me thats what caused the error i had another GoogleService-Info.plist in my root folder
Weird, @loveonwheels, in my case it ONLY works, if the plist and json files are located in root folder.
In my case, just removing the plist and the json from the root file and having these files on the respective platform/android - ios folder works. Don't need to remove the whole platforms, that's too much!
Doing these actions in specific order seems to be a reliable solution from my research:
cordova plugin rm cordova-plugin-fcm
cordova platform rm ios
cordova platform rm android
cordova plugin add cordova-plugin-fcm
cordova platform add ios
cordova platform add android
Definitely set me back a day or so of work trying to get this worked out, I hope this can save at least one person the same trouble.
I have resolved this problem by doing what @loveonwheels said. Nevertheless removing platform only to remove the plist / json file from the root folder
@circuitrider solution nailed it for me.
Resolved issue on IOS by adding 2 Resources folders under platform/ios/app name/Resources/Resources and placing the googleservices-info.plist in first resources folder.
[SOLVED]
In my case I had to edit file "fcm_config_files_process.js" located in folder "plugins/cordova-plugin-fcm/scripts/":
// fs.writeFileSync("platforms/ios/" + name + "/Resources/GoogleService-Info.plist", contents)
For some unknown reason while building the project this line (42) was throwing the error "Invalid data, chunk must be a string or buffer, not object" so what I did was to comment that line and then manually copy the file "GoogleService-Info.plist" to "platforms/ios/" + name + "/Resources/"
Hope this can help.
Thanks
for any one still have the same issue after trying remove and add platform , you should download the google-services.json file and GoogleService-Info.plist from your firebase account from your project there , because it has the API keys and IDs needed ,,
For me, the issue was solved by removing the ampersands (&) in config.xml as @bendspoons has described in his post.
Edit: Problem still exists
+ 1.. Problem still exists...
@walfro Does your solution only applies to people trying to run they projects on an iOS device?
@jeenn Yes, this solution applies for iOS only, I didn't have any issue for Android at that time. Are you having this error in Android? let me know and I might be able to help you.
Thanks, Walfrido
@walfridosp Yes, I'm having this issue when I try to run my ionic project in an Android device. I used to make my project work by editing the following files
FCMPlugin.gradle (located in /plugins/cordova-plugin-fcm/src/android)
project.properties (located in /platforms/android/project.properties)
build.gradle (located in /platforms/android/build.gradle) But after I updated my dependencies, the build.gradle file changed and I can't apply my previous solution.
Do you have any idea what could I be doing wrong?
@jeenn Did you try installing the plugin in a clean project? My idea of what could be happening is:
In android i solved.
i changd cordova-android ver ^7.0.0 -> ^6.3.0
then error message disappeared
@skout90 Did you just downgraded your "cordova-android"
package to 6.3.0, from you package.json?
@jeenn Then, i followed circuitrider
cordova plugin rm cordova-plugin-fcm
cordova platform rm ios
cordova platform rm android
cordova plugin add cordova-plugin-fcm
cordova platform add ios
cordova platform add android
dont forget delete the plataform folder
@fechanique the problem could be here maybe the new cordova version automatically puts the resource file in the resource folder. When i try to install the plugin i end up with a folder structure like this:
The Resources\Resources\
file is this one
And the Resources\
file is the one in my project root.
I don't know how to write plugins or how anything works in cordova, so it's just a guess. I know that cordova 7.0.0 changed some folder struct:
They changed the directory structure of cordova 7.0 so it probably won't work. It should be working with cordova 6.3.0 though. Make sure you clear everything before downgrading.
(crosswalk-project/cordova-plugin-crosswalk-webview/issues/188) So maybe that is the problem..
Edit: Nope, that's not the problem, installed the GH-335 branch but no solution. :/
Edit Edit:
I found a solution,
As i said this related to the folders structure changes, but the problem is in plugins/cordova-plugin-fcm/scripts/fcm_config_files_process.js
in line 58, 61 and 78
...
var contents = fs.readFileSync(path).toString();
fs.writeFileSync("platforms/android/google-services.json", contents); // <- here
var json = JSON.parse(contents);
var resourcesPath = "./platforms/android/app/src/main/res/";
var strings = fs.readFileSync(resourcesPath + "values/strings.xml").toString(); // <- here
...
fs.writeFileSync("platforms/android/res/values/strings.xml", strings); // <-- and here
To fix this change the paths on lines 61 and 78 from "platforms/android/res/values/strings.xml"
to "./platforms/android/app/src/main/res/values/strings.xml"
And change "platforms/android/google-services.json"
to "platforms/android/app/google-services.json"
in line 58
I got the fix from one of the forked repo. It just needed correct path for strings.xml.
There is no need to downgrade cordova or cordova-android
The fix is to replace the code in /cordova-plugin-fcm/scripts/fcm_config_files_process.js as below:
#!/usr/bin/env node
'use strict';
var fs = require('fs');
var path = require('path');
fs.ensureDirSync = function (dir) {
if (!fs.existsSync(dir)) {
dir.split(path.sep).reduce(function (currentPath, folder) {
currentPath += folder + path.sep;
if (!fs.existsSync(currentPath)) {
fs.mkdirSync(currentPath);
}
return currentPath;
}, '');
}
};
var config = fs.readFileSync('config.xml').toString();
var name = getValue(config, 'name');
var IOS_DIR = 'platforms/ios';
var ANDROID_DIR = 'platforms/android';
var PLATFORM = {
IOS: {
dest: [
IOS_DIR + '/' + name + '/Resources/GoogleService-Info.plist',
IOS_DIR + '/' + name + '/Resources/Resources/GoogleService-Info.plist'
],
src: [
'GoogleService-Info.plist',
IOS_DIR + '/www/GoogleService-Info.plist',
'www/GoogleService-Info.plist'
]
},
ANDROID: {
dest: [
ANDROID_DIR + '/google-services.json',
ANDROID_DIR + '/app/google-services.json',
],
src: [
'google-services.json',
ANDROID_DIR + '/assets/www/google-services.json',
'www/google-services.json'
],
stringsXml: ANDROID_DIR + '/app/src/main/res/values/strings.xml'
}
};
// Copy key files to their platform specific folders
if (directoryExists(IOS_DIR)) {
copyKey(PLATFORM.IOS);
}
if (directoryExists(ANDROID_DIR)) {
copyKey(PLATFORM.ANDROID, updateStringsXml)
}
function updateStringsXml(contents) {
var json = JSON.parse(contents);
var strings = fs.readFileSync(PLATFORM.ANDROID.stringsXml).toString();
// strip non-default value
strings = strings.replace(new RegExp('<string name="google_app_id">([^\@<]+?)</string>', 'i'), '');
// strip non-default value
strings = strings.replace(new RegExp('<string name="google_api_key">([^\@<]+?)</string>', 'i'), '');
// strip empty lines
strings = strings.replace(new RegExp('(\r\n|\n|\r)[ \t]*(\r\n|\n|\r)', 'gm'), '$1');
// replace the default value
strings = strings.replace(new RegExp('<string name="google_app_id">([^<]+?)</string>', 'i'), '<string name="google_app_id">' + json.client[0].client_info.mobilesdk_app_id + '</string>');
// replace the default value
strings = strings.replace(new RegExp('<string name="google_api_key">([^<]+?)</string>', 'i'), '<string name="google_api_key">' + json.client[0].api_key[0].current_key + '</string>');
fs.writeFileSync(PLATFORM.ANDROID.stringsXml, strings);
}
function copyKey(platform, callback) {
for (var i = 0; i < platform.src.length; i++) {
var file = platform.src[i];
if (fileExists(file)) {
try {
var contents = fs.readFileSync(file).toString();
try {
platform.dest.forEach(function (destinationPath) {
var folder = destinationPath.substring(0, destinationPath.lastIndexOf('/'));
fs.ensureDirSync(folder);
fs.writeFileSync(destinationPath, contents);
});
} catch (e) {
// skip
}
callback && callback(contents);
} catch (err) {
console.log(err)
}
break;
}
}
}
function getValue(config, name) {
var value = config.match(new RegExp('<' + name + '>(.*?)</' + name + '>', 'i'));
if (value && value[1]) {
return value[1]
} else {
return null
}
}
function fileExists(path) {
try {
return fs.statSync(path).isFile();
} catch (e) {
return false;
}
}
function directoryExists(path) {
try {
return fs.statSync(path).isDirectory();
} catch (e) {
return false;
}
}
Please consider fixing it quickly and release a new version.
For manually fixing the issue:
Please update @ketanyekale changes to master ? Tested and working perfect.
@ketanyekale works! 👍 Thanks
I tried above all solution but no one works for me for android.Please Help !
@ketanyekale works!
@krinakis, if you have already added the platforms before modifying the file plugins/cordova-plugin-fcm/scripts/fcm_config_files_process.js, you need to remove the platform android and add it again.
solution from @ketanyekale did the trick I'm running android@7.0.0 on my project.
Hi, I installed the plugin a week ago and run into the same issue fixed per the comment above, should be fixed in the main branch
Finally a solution that works @ketanyekale 👍 🥇 although a shame that it still hasn't been fixed in the main branch. Did look like an issue regarding paths as it couldn't read from the json file but didn't know how to fix that. Good work 👍 💯
In recent versions of cordova-android
, location of res/Strings.xml
file has changed, which mostly causes this error. So go to /plugins/cordova-plugin-fcm/scripts/fcm_config_files_process.js
and wherever you see platforms/android/res/values/strings.xml
, replace it with platforms/android/app/src/main/res/values/strings.xml
. There are mostly two occurrences.
This would fix it! Hope it helps.
tested the @ketanyekale solution in cordova-android@7.0.0
and works perfectly but, when will be implemented in master?
@ketanyekale fix work perfectly in cordova-android@7.0.0. Thanks.
@ketanyekale Thanks your solution fixed the problem (cordova-android@7.0.0)
@ketanyekale thanks for the solution..its working for me too
I had this problem trying to deploy for android and the solution for me was to remove the ios platform.
After that I could add the android platform and build the apk without any problem.
Hope this helps!
I was getting this error duing building Android on Windows. I had "ios" folder under cordova/platform. I deleteed "ios" folder in my Windows and it worked!
pull request made to fix this issue https://github.com/fechanique/cordova-plugin-fcm/pull/575
I am still getting this error with cordova-android@8.0.0 I got:
Cordova FCM plugin v2.1.2 installed
For more details visit https://github.com/fechanique/cordova-plugin-fcm
Adding cordova-plugin-fcm to package.json
Failed to restore plugin "cordova-plugin-fcm" from config.xml. You might need to try adding it again. Error: TypeError: Invalid data, chunk must be a string or buffer, not object
Discovered saved plugin "cordova-plugin-firebase". Adding it to the project
Installing "cordova-plugin-firebase" for android
Subproject Path: CordovaLib
Subproject Path: app
Adding cordova-plugin-firebase to package.json
Failed to restore plugin "cordova-plugin-firebase" from config.xml. You might need to try adding it again. Error: TypeError: Invalid data, chunk must be a string or buffer, not object
cordova-android-support-gradle-release: Android platform: V7+
cordova-android-support-gradle-release: Wrote custom version '27.+' to /builds/project-0/platforms/android/app/build.gradle
cordova-android-support-gradle-release: Wrote custom version '27.+' to /builds/project-0/platforms/android/cordova-android-support-gradle-release/progestNowApp-cordova-android-support-gradle-release.gradle
Invalid data, chunk must be a string or buffer, not object
for those still facing this issue
I run this to add this plugin in my project: cordova plugin add cordova-plugin-fcm --save
At the end I get this error: Invalid data, chunk must be a string or buffer, not object
`Fetching plugin "cordova-plugin-fcm" via npm Installing "cordova-plugin-fcm" for android ANDROID_HOME=C:\Users\mkhairunns\AppData\Local\Android\sdk JAVA_HOME=C:\Program Files\Java\jdk1.8.0_20 Subproject Path: CordovaLib Incremental java compilation is an incubating feature. :clean :CordovaLib:clean
BUILD SUCCESSFUL
Total time: 9.497 secs Subproject Path: CordovaLib
gin-fcm
Saved plugin info for "cordova-plugin-fcm" to config.xml Error: Invalid data, chunk must be a string or buffer, not object`
The I try cordova build android, I get same error: Invalid data, chunk must be a string or buffer, not object
This is my config.xml:
`<?xml version='1.0' encoding='utf-8'?>
`
Any help?