I updated to Ionic 3.5, and after that I get this error, when i try to do cordova build ios
:
Invalid data, chunk must be a string or buffer, not object
There is no explanation of why this error is happening. I tried this both with Cordova 7.0.1 and 6.5.0. Interestingly, it works on Windows machine, but not on Mac. I only get the error on Mac. I appreciate any insights or helps.
ionic info
global packages:
@ionic/cli-utils : 1.5.0
Cordova CLI : 7.0.1
Ionic CLI : 3.5.0
local packages:
@ionic/app-scripts : 1.3.7
@ionic/cli-plugin-cordova : 1.4.1
@ionic/cli-plugin-ionic-angular : 1.3.2
Cordova Platforms : android 6.2.3
Ionic Framework : ionic-angular 3.5.3
System:
Node : v7.10.0
OS : Windows 10
Xcode : not installed
ios-deploy : not installed
ios-sim : not installed
npm : 4.6.1
I got the fix from one of the github issue. 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;
}
}
For fixing the issue:
Make sure you have copied the above file in "plugins" folder as cordova copies all the cordova-plugins from node_modules directory to plugins directory,
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 platforms and add again.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With