Capacitor: Ionic + Capacitor - Cordova Plugins exception

Created on 29 May 2019  路  15Comments  路  Source: ionic-team/capacitor

Description of the problem:

Affected platform

  • [ x] Android
  • [ ] iOS
  • [ ] electron
  • [ ] web

OS of the development machine

  • [x ] Windows
  • [ ] macOS
  • [ ] linux

Other information:

Capacitor version:
1.0.0

node version:
10.15.3
npm version:
6.9.0

Steps to reproduce:
When I run my app, I see the following exceptions (and the plugins don't work: AdMobFree and InAppPurchase v1)

V/Capacitor/Plugin: To native (Cordova plugin): callbackId: InAppBillingV31732914844, service: InAppBillingV3, action: init, actionArgs: []
W/System.err: java.lang.ClassNotFoundException: com.alexdisler.inapppurchases.InAppBillingV3
        at java.lang.Class.classForName(Native Method)
        at java.lang.Class.forName(Class.java:453)
        at java.lang.Class.forName(Class.java:378)
        at org.apache.cordova.PluginManager.instantiatePlugin(PluginManager.java:489)
        at org.apache.cordova.PluginManager.getPlugin(PluginManager.java:169)
        at org.apache.cordova.PluginManager.exec(PluginManager.java:122)
        at com.getcapacitor.MessageHandler.callCordovaPluginMethod(MessageHandler.java:73)
        at com.getcapacitor.MessageHandler.postMessage(MessageHandler.java:46)
        at android.os.MessageQueue.nativePollOnce(Native Method)
        at android.os.MessageQueue.next(MessageQueue.java:326)
        at android.os.Looper.loop(Looper.java:160)
        at android.os.HandlerThread.run(HandlerThread.java:65)
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        ... 12 more
        Suppressed: java.io.IOException: No original dex files found for dex location
        at dalvik.system.DexFile.openDexFileNative(Native Method)
        at dalvik.system.DexFile.openDexFile(DexFile.java:354)
        at dalvik.system.DexFile.<init>(DexFile.java:101)
        at dalvik.system.DexFile.<init>(DexFile.java:75)
        at dalvik.system.DexPathList.loadDexFile(DexPathList.java:394)
        at dalvik.system.DexPathList.makeDexElements(DexPathList.java:354)
        at dalvik.system.DexPathList.<init>(DexPathList.java:164)
        at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:74)
        at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:65)
        at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:64)
        at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:73)
        at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:88)
        at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:74)
        at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:40)
        at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:727)
        at android.app.LoadedApk.getClassLoader(LoadedApk.java:810)
        at android.app.LoadedApk.getResources(LoadedApk.java:1032)
        at android.app.ContextImpl.createAppContext(ContextImpl.java:2345)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5798)
        at android.app.ActivityThread.access$1100(ActivityThread.java:200)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1656)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6718)
W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
I/System.out: Error adding plugin com.alexdisler.inapppurchases.InAppBillingV3.
E/Capacitor: Post message error:
    java.lang.NullPointerException: Attempt to invoke virtual method 'void org.apache.cordova.CordovaPlugin.privateInitialize(java.lang.String, org.apache.cordova.CordovaInterface, org.apache.cordova.CordovaWebView, org.apache.cordova.CordovaPreferences)' on a null object reference
        at org.apache.cordova.PluginManager.getPlugin(PluginManager.java:171)
        at org.apache.cordova.PluginManager.exec(PluginManager.java:122)
        at com.getcapacitor.MessageHandler.callCordovaPluginMethod(MessageHandler.java:73)
        at com.getcapacitor.MessageHandler.postMessage(MessageHandler.java:46)
        at android.os.MessageQueue.nativePollOnce(Native Method)
        at android.os.MessageQueue.next(MessageQueue.java:326)
        at android.os.Looper.loop(Looper.java:160)
        at android.os.HandlerThread.run(HandlerThread.java:65)
V/Capacitor: callback: -1, pluginId: Console, methodName: log, methodData: {"level":"error","message":"ERROR {}"}
E/Capacitor/Plugin/Console: ERROR {}
E/Capacitor: Unable to inject Capacitor, Plugins won't work

Link to sample project:

Most helpful comment

@tgangso @orhan-swe did you guys find a way to add a billing key manually? I am struggling to find a solution myself

All 15 comments

I tested AdMobFree in the past and worked and other users have used cordova-plugin-inapppurchase without problems.
Can you provide a sample app?

I tested AdMobFree in the past and worked and other users have used cordova-plugin-inapppurchase without problems.
Can you provide a sample app?

I can't provide a sample app since it takes too much effort and time.
Can you share how you tested the plugins and how you installed them?

Sorry, as you said, testing it takes too much effort and time and I tested it in the past already, so I won't test again unless you provide a sample app.
Closing for now. Feel free to reopen if you get time to provide it.

@jcesarmobile I have asked how you tested it in the past with capacitor and how you installed it. I didn't ask you to test it again.

BTW it is horrible to close an issue because you can't test it. the issue exists and it should remain open otherwise proven it is not a real issue. There are exceptions when working with those plugins as you can see above.

It's you who have to provide information about how you installed and tested and a sample project if possible. But you didn't. The first time it was reported, I tested it and was working fine, it ended being an user problem. So I won't test it again unless you can prove it's not an user problem.

It's you who have to provide information about how you installed and tested and a sample project if possible. But you didn't. The first time it was reported, I tested it and was working fine, it ended being an user problem. So I won't test it again unless you can prove it's not an user problem.

Hi,
I was asking how you tested it the first time it was reported, I want to check if I installed the package correctly with the right commands.

I followed the instructions here:
https://ionicframework.com/docs/native/admob-free

but instead of ionic cordova plugin add cordova-plugin-admob-free I did npm install cordova-plugin-admob-free and then npx cap update android

I followed the instructions here:
https://ionicframework.com/docs/native/admob-free

but instead of ionic cordova plugin add cordova-plugin-admob-free I did npm install cordova-plugin-admob-free and then npx cap update android

Thanks.
How do you replace the "ionic cordova plugin add" with "npm install" command in case there is variable?
e.g equivilant to this in capacitor:

cordova plugin add cc.fovea.cordova.purchase --variable BILLING_KEY="<BILLING_KEY>"

Variables and hooks don't work on Capacitor, you have to check the plugin and see what they do with the variable/hook and do it yourself manually.

Hi @theunreal
Did you find out how to add the variable BILLING_KEY manually when installing the plugin in capacitor project with only "npm install cc.fovea.cordova.purchase" ?

Also curious how to add the billing key manually.

@tgangso @orhan-swe did you guys find a way to add a billing key manually? I am struggling to find a solution myself

Variables and hooks don't work on Capacitor, you have to check the plugin and see what they do with the variable/hook and do it yourself manually.

This is very, very sad.

I wonder if anyone figured this out. From the cordova-plugin-purchase docs:

I think that last link might give some ideas. I'm amazed at how difficult it is to do in-app billing with Capacitor -- seems like it's something so many people would need, and the capacitor docs say, "Here's some articles that are sorta kinda like what you're trying to do." :(

Was this page helpful?
0 / 5 - 0 ratings