I’m trying to set up the InAppPurchase plugin (ver 5.0.0-beta.17) with Ionic 4 (ver 4.0.0-beta.8). I’m using the /ngx
import for InAppPurchase
and all looks fine, after some initial hick-ups.
In the device console, I’m getting an error {"code":-2,"message":"Billing cannot be initialized","errorCode":-2}
. Which is due to the plugin not receiving the play_store_key
property. I used to set this property in the /src/mainfest.json file under Ionic 3.
I tried putting it in the /src directory, but no luck. What is the approach with Ionic 4?
Thanks a lot for your help!
1 Like
I worked it out, by employing a before_prepare
hook, which copies the /src/manifest.json
file to /www
. As the www folder gets recreated on every run, this seems like the only solution - for the moment.
This is the hook I used:
#!/usr/bin/env node
var FILES_TO_COPY = [{
srcPath: "src/manifest.json",
destPath: "www/manifest.json"
}];
var fs = require('fs');
var path = require('path');
function copyFileSync(srcFile, target) {
var destFile = target;
console.log('copying ' + srcFile + ' to ' + destFile);
if (fs.existsSync(target)) {
if (fs.lstatSync(target).isDirectory()) {
destFile = path.join(target, path.basename(srcFile));
}
}
fs.writeFileSync(destFile, fs.readFileSync(srcFile));
}
FILES_TO_COPY.forEach(function (fileInfo) {
copyFileSync(fileInfo.srcPath, fileInfo.destPath);
});
Put it in a .js file (you can change the filename, not the ending) in a new /hooks
folder and then plug it into your config.xml file:
<hook src="hooks/10_copy_manifest_hook.js" type="before_prepare" />
Hope it helps someone…
6 Likes
thanks for your solution @jccabron! this really helped me…
¿Don’t have a capacitor solution? problems accessing the www path.
2021-01-04 13:49:23.578 D/google.payments: Unable to read manifest file:java.io.FileNotFoundException: www/manifest.json
2021-01-04 13:49:23.578 D/google.payments: Unable to read manifest file:java.io.FileNotFoundException: www/manifest.json
2021-01-04 13:49:23.578 D/google.payments: Unable to initialize billing
2021-01-04 13:49:23.578 D/google.payments: executing on android
2021-01-04 13:49:23.578 D/google.payments: Error: Billing cannot be initialized