cordova-plugin-inapppurchase
cordova-plugin-inapppurchase copied to clipboard
Cordova Android 7.0.0
Unable to build project with the new cordova android 7.0.0.
When I run ionic cordova build android i had this java compilation problem :
Console output
.... platforms\android\app\src\main\java\com\alexdisler\inapppurchases\IabHelper.java:33: error: package com.android .vending.billing does not exist
import com.android.vending.billing.IInAppBillingService; ....
Plz, can you update your plugin to support this new cordova android framework.
Thx.
I have the same problem.
I encountered the same error after updated our app to cordova-cli 8.0.0 and cordova-android 7.0.0.
It looks like this class is missing/or was unable to load:
com.android.vending.billing.IInAppBillingService;
Please advise. Thank you.
I experienced the same issue the solution is documented on this page: https://developer.android.com/google/play/billing/billing_integrate.html
In Android Studio, import the IInAppBillingService.aidl file to your project as described in the following steps:
- Create a directory named aidl under <cordovaProject>/platforms/android/app/source/main.
- Add a new package com.android.vending.billing in this directory.
- Import the IInAppBillingService.aidl file into this package
Simple Solution
So basically make the following folder structure:
and put the IInAppBillingService.aidl
file in there.
thanks a lot @azarus this answer helped me solve this problem. Works even with cordova plain when not working with android studio. Simply create the directory as described and put the file in there. then run cordova clean android and cordova build/run android e.g.
Thanks for this fix advice @azarus, it does allow build, still to check purchasing. Cheers.
Better to do this with the plugin itself: https://github.com/AlexDisler/cordova-plugin-inapppurchase/pull/207
It works for me. I can compile my code now. Thanks! Also, I found the file in this #38. You can download the file from the link below: IInAppBillingService.aidl
OK, weird. I was using the steps from @azarus above to build successfully. Then I did a cordova platform remove android
& cordova platform add android
& the steps no longer worked! In particular, adding IInAppBillingService.aidl
to the path suggested by azarus no longer worked (whereas it did before the platform reinstall), but now the alternate path /platforms/android/CordovaLib/src/com/android/vending/billing/IInAppBillingService.aidl
suggested by EvolveYourMind at https://github.com/AlexDisler/cordova-plugin-inapppurchase/issues/38 does work. I made no changes in the interim. Why would this happen? Seems like black magic at work. Please fix the plug-in itself as soon as you can.
@rhclayto the problem comes from and android sdk mismatch youre probably using and outdated version. That was the source of my problem not sure about yours.
Hey thanks. Soon after I posted my comment I realized I needed \platforms\android\app\src\main\aidl\com\android\vending\billing\
but I had left out app
, so because of my typo I had the file in the wrong path. Putting it at the right path works for me, as before.
thanks @azarus is worked ..
You can also add a build hook to do this in case you ever need to rebuild your project (so you don't have to copy the file manually again.) This is what I did...
Added to project-folder/hooks/after_prepare/010_copy_inapp_purchase_workaround.js
:
#!/usr/bin/env node
var ROOT_DIR = process.argv[2];
var DIRS_TO_COPY = [{
srcDir: "platforms/android/src/com/android/vending/billing",
destDir: "platforms/android/app/src/main/aidl/com/android/vending/billing"
}];
var fs = require('fs');
var path = require('path');
function copyFileSync(srcFile, target) {
var destFile = target;
//if target is a directory. a new file with the same name will be created inside it
if (fs.existsSync(target)) {
if (fs.lstatSync(target).isDirectory()) {
destFile = path.join(target, path.basename(srcFile));
}
}
//console.log('copying ' + srcFile + ' to ' + destFile);
fs.writeFileSync(destFile, fs.readFileSync(srcFile));
}
function copyFolderRecursiveSync(sourceFolder, targetFolder) {
var files = null;
if (!fs.existsSync(targetFolder)) {
fs.mkdirSync(targetFolder);
}
//copy
if (fs.lstatSync(sourceFolder).isDirectory()) {
files = fs.readdirSync(sourceFolder) || [];
files.forEach(function(curSource) {
var curSourceFull = path.join(sourceFolder, curSource);
if (fs.lstatSync(curSourceFull).isDirectory()) {
var curTargetFolder = path.join(targetFolder, path.basename(curSource));
copyFolderRecursiveSync(curSourceFull, curTargetFolder);
} else {
copyFileSync(curSourceFull, targetFolder);
}
});
}
}
DIRS_TO_COPY.forEach(function(dirInfo) {
var srcDirFull = path.join(ROOT_DIR, dirInfo.srcDir);
var destDirFull = path.join(ROOT_DIR, dirInfo.destDir);
copyFolderRecursiveSync(srcDirFull, destDirFull);
});
@lincolnthree good script but it does not work for me
change it to
var mkdirp = require('mkdirp');
.
.
.
mkdirp.sync(targetFolder, function (err) {
if (err) console.error(err);
else console.log('dir created');
});
Thanks! Saved me some time:)
My ROOT_DIR was incorrectly set so I had to comment it out.
Also, don't forget to add a hook to config.xml that will match your location:)
@lincolnthree tried the script but get this error:
Running command: "D:\Program Files\nodejs\node.exe" D:\www\ionic\codemurai-ionic\hooks\after_prepare\030_copy_iapp_workaround.js D:\www\ionic\codemurai-ionic
fs.js:922
return binding.mkdir(pathModule._makeLong(path),
^
Error: ENOENT: no such file or directory, mkdir 'D:\www\ionic\codemurai-ionic\platforms\android\app\src\main\aidl\com\android\vending\billing'
at Error (native)
at Object.fs.mkdirSync (fs.js:922:18)
at copyFolderRecursiveSync (D:\www\ionic\codemurai-ionic\hooks\after_prepare\030_copy_iapp_workaround.js:30:6)
at D:\www\ionic\codemurai-ionic\hooks\after_prepare\030_copy_iapp_workaround.js:53:2
at Array.forEach (native)
at Object.<anonymous> (D:\www\ionic\codemurai-ionic\hooks\after_prepare\030_copy_iapp_workaround.js:50:14)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
(node:28336) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Hook failed with error code 1: D:\www\ionic\codemurai-ionic\hooks\after_prepare\030_copy_iapp_workaround.js
I had a similar issue.
Below is a more complete steps to resolve for those in need.. Hopefully it helps someone else
1> Create folder hooks under your main project for example ./projectA/hooks
2> Create a js file and append the below content into it. For example 010_copy_inapp_purchase_workaround.js
` #!/usr/bin/env node
//var ROOT_DIR = process.argv[2];
//console.log('My root dir::', ROOT_DIR); var DIRS_TO_COPY = [{ srcDir: "platforms/android/src/com/android/vending/billing", destDir: "platforms/android/app/src/main/aidl/com/android/vending/billing" }];
var fs = require('fs'); var path = require('path'); var mkdirp = require('mkdirp');
function copyFileSync(srcFile, target) { var destFile = target;
console.log('copying ' + srcFile + ' to ' + destFile); //if target is a directory. a new file with the same name will be created inside it if (fs.existsSync(target)) { if (fs.lstatSync(target).isDirectory()) { destFile = path.join(target, path.basename(srcFile)); } }
fs.writeFileSync(destFile, fs.readFileSync(srcFile)); }
function copyFolderRecursiveSync(sourceFolder, targetFolder) { var files = null; console.log('copying ' + sourceFolder + ' to ' + targetFolder);
if (!fs.existsSync(targetFolder)) { mkdirp.sync(targetFolder, function (err) { if (err) console.error(err); else console.log('dir created'); }); }
//copy if (fs.lstatSync(sourceFolder).isDirectory()) { files = fs.readdirSync(sourceFolder) || [];
files.forEach(function (curSource) {
var curSourceFull = path.join(sourceFolder, curSource);
if (fs.lstatSync(curSourceFull).isDirectory()) {
var curTargetFolder = path.join(targetFolder, path.basename(curSource));
copyFolderRecursiveSync(curSourceFull, curTargetFolder);
} else {
copyFileSync(curSourceFull, targetFolder);
}
});
} }
DIRS_TO_COPY.forEach(function (dirInfo) { // var srcDirFull = path.join(ROOT_DIR, dirInfo.srcDir); // var destDirFull = path.join(ROOT_DIR, dirInfo.destDir); console.log('dirInfo.srcDir::', dirInfo.srcDir); copyFolderRecursiveSync(dirInfo.srcDir, dirInfo.destDir); }); `
3> While project is NOT running(otherwise, your config file will get rewritten and changes will be reverted), update config.xml file and add the above platform tag
<preference name="SplashShowOnlyFirstTime" value="false" /> <preference name="SplashScreen" value="screen" /> <preference name="SplashScreenDelay" value="3000" /> <hook src="hooks/010_copy_inapp_purchase_workaround.js" type="after_prepare" /> <platform name="android">
4> Run & Test
Thanks for the workaround! It helped.
Hi guys... Am using PhoneGap Build (CLI-8.0.0). Any suggestions/workarounds since PGB doesn't seem to allow hooks?
Thanks for the details @siege-nnn this worked fine. Just a note for anyone using ionic pro package for building - your gitignore will probably exclude checking in a hooks folder. I just created one called hooks2 and placed the workaround .js file in there and checked it in to GitHub then triggered my build and package.
Thanks @azarus for the workaround and @lincolnthree for the hook / script.
Another alternative is to do the following:
cd $PROJECT_ROOT
mkdir -pv platforms/android/app/src/main/aidl/com/android/vending/billing
cp -vf platforms/android/src/com/android/vending/billing/IInAppBillingService.aidl platforms/android/app/src/main/aidl/com/android/vending/billing
cordova build android --release
Hope this helps someone else too. Cheers! 😄 👍 🎉
@gpreg any luck? Same thing here, PGB...
@josiahbryan: Unfortunately not - had to stick with CLI-6.5 but now starting to get a bit squirrelly as no doubt PGB will start pushing toward building with a higher version at some point in the not too distant future (and it's also holding things back on using more recent versions of other plug-ins too). Would really much prefer to stay with this plug-in 'cos its been great but might not have a choice if this is no longer actively maintained... 😥
What I have done is made a fork of this plugin and added in the pull requests to fix several of these issues and added the repo to my config.Xml and it works just fine on pgb 8.0.0.
Hey really? That's awesome ... can you share your fork...? I'd love to use it as well ... using cli-8.1.1 via PhoneGap build and just having an incredibly tough time getting any inapp purchasing plugins to work....
On Thu, Mar 7, 2019 at 5:23 PM Kami [email protected] wrote:
What I have done is made a fork of this plugin and added in the pull requests to fix several of these issues and added the repo to my config.Xml and it works just fine on pgb 8.0.0.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/AlexDisler/cordova-plugin-inapppurchase/issues/196#issuecomment-470721339, or mute the thread https://github.com/notifications/unsubscribe-auth/AEmSLKcN6NFwwO3SsxP3myxbacpMNZAwks5vUZFngaJpZM4RCNv1 .
-- Josiah Bryan 765-215-0511 [email protected]
Yeah sure you can add it to your config with
<plugin spec="https://github.com/lilmnm-kamikaze-/customIAP.git" source="git" />
Great, thanks! How do you specify your Android Billing Key with this plugin...? I've tried so many different plugins I've lost count today.
On Thu, Mar 7, 2019 at 5:30 PM Kami [email protected] wrote:
Yeah sure you can add it to your config with
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/AlexDisler/cordova-plugin-inapppurchase/issues/196#issuecomment-470723799, or mute the thread https://github.com/notifications/unsubscribe-auth/AEmSLI5d-6YHWue12s66j1BFRvR3Y50xks5vUZLvgaJpZM4RCNv1 .
-- Josiah Bryan 765-215-0511 [email protected]
Hmm...odd, on PhoneGap build with cli-8.1.1
, I can't install your fork:
Are you using cli-8.0.0 or what exact version are you using for your PhoneGap build with this plugin..?
Repository "https://github.com/lilmnm-kamikaze-/customIAP.git" checked out to git ref "master" at "a0de2dc".
Installing "kami-inapppurchase" at "1.5.0" for android
Android Studio project detected
Error during processing of action! Attempting to revert...
Failed to install 'kami-inapppurchase': TypeError: Uh oh!
Path must be a string. Received undefined
at assertPath (path.js:28:11)
at Object.resolve (path.js:1168:7)
at copyNewFile (/var/gimlet/tmp/47363360608820/3486871/cordova/lib/pluginHandlers.js:258:28)
at install (/var/gimlet/tmp/47363360608820/3486871/cordova/lib/pluginHandlers.js:43:17)
at ActionStack.process (/var/gimlet/tmp/47363360608820/3486871/cordova/node_modules/cordova-common/src/ActionStack.js:56:25)
at PluginManager.doOperation (/var/gimlet/tmp/47363360608820/3486871/cordova/node_modules/cordova-common/src/PluginManager.js:114:20)
at PluginManager.addPlugin (/var/gimlet/tmp/47363360608820/3486871/cordova/node_modules/cordova-common/src/PluginManager.js:144:17)
at /var/gimlet/tmp/47363360608820/3486871/cordova/Api.js:247:74
at _fulfilled (/var/gimlet/tmp/47363360608820/3486871/cordova/node_modules/q/q.js:834:54)
at self.promiseDispatch.done (/var/gimlet/tmp/47363360608820/3486871/cordova/node_modules/q/q.js:863:30)
Uh oh!
Yes 8.0.0
<preference name="phonegap-version" value="cli-8.0.0" /> <preference name="pgb-builder-version" value="2" />
Thanks, I'll try that right now. And about the Billing Key, how do you set that?
On Thu, Mar 7, 2019 at 5:46 PM Kami [email protected] wrote:
Yes 8.0.0
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/AlexDisler/cordova-plugin-inapppurchase/issues/196#issuecomment-470729925, or mute the thread https://github.com/notifications/unsubscribe-auth/AEmSLHqbpxyzDeh-N4kMpJXtKLqMaD-Sks5vUZa1gaJpZM4RCNv1 .
-- Josiah Bryan 765-215-0511 [email protected]
Same as with this repo. Put it in the manifest.json in the same spot as this one