j3k0 / cordova-plugin-purchase

In-App Purchase for Cordova on iOS, Android and Windows
https://purchase.cordova.fovea.cc
1.29k stars 529 forks source link

[ANDROID] 6777001 Init failed - String resource ID #0x0 #673

Closed diegodem closed 6 years ago

diegodem commented 6 years ago

system info

Debian 4.9.65-3+deb9u2
Cordova 8.0.0 // ionic CLI 3.19.1
Android 6.0.1
Plugin Version: 7.1.0

Expected behavior

Product gets registered, then gets loaded.

Observed behavior

Product gets registered, then "Init failed - String resource ID #0x0". ready() never fires, and the error is caused by refreshing (I suppose it is due to refreshing before ready() is 'ready')

Steps to reproduce

Register the product, then call ready(), then refresh().

error

tobika commented 6 years ago

@diegodem it's difficult to imagine a solution without code, but just one idea maybe

did you add the plugin cordova plugin add cc.fovea.cordova.purchase --variable BILLING_KEY="<BILLING_KEY>" with a billing key? maybe the missing string id is the missing billing key?

diegodem commented 6 years ago

Yes, I added it in the installation of the plugin, and I can see my billing key in the file config.xml. My code is the following:

this.plt.ready().then(()=>{ alert("enter"); this.iap.verbosity = this.iap.DEBUG; this.iap.when("com.example.app.inappid1").updated( (product) => { alert(JSON.stringify(product)); }); this.iap.register({ id: "com.example.app.inappid1", alias: "100 coins", type: this.iap.CONSUMABLE }); this.iap.error( (err) => { alert('Store Error ' + JSON.stringify(err)); }); this.iap.ready(function() { alert("Will this alert ever show?"); }); this.iap.refresh(); });

Thank you

tobika commented 6 years ago

@diegodem did you check out this issue? https://github.com/j3k0/cordova-plugin-purchase/issues/74#issuecomment-62410789

the comment could be helpful to verify

diegodem commented 6 years ago

@tobika Yeah I saw that, but I think that back then the billing key had to be added manually. I just added it in the installation of the plugin, as the documentation says and as you said in your previous comment

tobika commented 6 years ago

@diegodem maybe you can just verify if you have a file here with the correct content? platforms/android/res/values/billing_key_param.xml

diegodem commented 6 years ago

@tobika Well, I don't even have a res folder under android, but I do have a file platforms/android/app/src/main/res/values/billing_key_param.xml However, I don't know if the contents are correct. Can you show me the format of your billing_key_param.xml?

diegodem commented 6 years ago

I solved my problem by downgrading Cordova to 7.1.0. So I think there's some sort of incompatibility between this plugin and Cordova 8. Thanks anyway @tobika for your help

Bohica1 commented 6 years ago

@diegodem I am experiencing the same issue. Same paths that you are seeing, not what is reference everywhere else. I just tried downgrading to 7.1.0 and still experiencing the issue.

image image

diegodem commented 6 years ago

@Bohica1 Have you removed and added the android platform?

Bohica1 commented 6 years ago

I didn't remove it and add it back in. I just downgraded Cordova version. I will try that out.

Bohica1 commented 6 years ago

@diegodem That worked! Thank you VERY much this was a tremendous pain to try and work through for a moment.

znegva commented 6 years ago

I also had this problem with the following configuration:

cordova (Cordova CLI) : 8.0.0
Cordova Platforms  : android 7.0.0
Ionic Framework    : ionic-angular 3.9.2

As mentioned with Cordova 8 and/or cordova-android 7.0.0 some file locations have changed.
Therefore the "hooks" in the plugins config.xml (esp. lines 90 to 97) don't seem to work as expected and need to be done by hand.

add billing key to xml file

Edit the file platforms/android/app/src/main/res/values/billing_key_param.xml to:

<?xml version='1.0' encoding='utf-8'?>
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="MissingTranslation">
    <string name="billing_key_param">"MIIB...AQAB"</string>
</resources>

copy IInAppBillingService.aidl

Another modification I had to do by hand was: move directories
platforms/android/src/com/android/vending/billing to platforms/android/app/src/main/java/com/android/vending/billing
and
platforms/android/src/aidl/com/android/vending/billing to platforms/android/app/src/main/aidl/com/android/vending/billing

both contain the file IInAppBillingService.aidl - not sure if both files/dirs really need to be moved, but it is working for me now 👍

tlhunter commented 6 years ago

@znegva I attempted to add the <string> line to billing_key_param.xml, unfortunately once I compile the application I'm met with the following error:

FAILURE: Build failed with an exception.                                                                                                                                      

* What went wrong:                                                                                                                                                            
Execution failed for task ':app:mergeReleaseResources'.                                                                                                                       
> [...]/platforms/android/app/src/main/res/values/billing_key_param.xml: Error: In DataSet 'main', no data file for changedFile. This is an internal error in the incremental builds code; to work around it, try doing a full clean build.

* Try:                                                                                                                                                                        
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.                                                                

* Get more help at https://help.gradle.org                                                                                                                                    

As far as moving the IInAppBillingService.aidl files around, I see that the first one you reference does exist, however the second one does not.

FWIW, I started to write a script to automate fixing this issue (useful for when you don't check in platforms/). Maybe if your changes works for others then they'll find this script useful:

#!/bin/sh

set -e

echo "This fixes an incompatability between Cordova 8 and cordova-plugin-purchase"
echo "This needs to be run after installation / Cordova initialization and before building the app"
echo "The reason it needs to be run is that platforms/* isn't checked into git"
echo "See https://github.com/j3k0/cordova-plugin-purchase/issues/673#issuecomment-369071933"

FILE=./platforms/android/app/src/main/res/values/billing_key_param.xml

cat > $FILE <<- XMLPayload
<?xml version='1.0' encoding='utf-8'?>
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="MissingTranslation">
  <string name="billing_key_param">"MIIB...AQAB"</string>
</resources>
XMLPayload

mkdir -p ./platforms/android/app/src/main/java/com/android/vending/billing/
cp ./platforms/android/src/com/android/vending/billing/* ./platforms/android/app/src/main/java/com/android/vending/billing

#mkdir -p ./platforms/android/app/src/main/aidl/com/android/vending/billing/
#cp ./platforms/android/src/aidl/com/android/vending/billing/* ./platforms/android/app/src/main/aidl/com/android/vending/billing
K-Endo369 commented 5 years ago

This issue occurs on my app.

I dont know where I should report this issue, so I report here.

Please tell me, if someone knows where I should report.

System info

For cordova:

Cordova 8.0.0 Android 6.3.0 Plugin Version: 7.2.2

For devide:

Android OS version 5.0.1

My billing key is written in the file config.xml, and in the file \platforms\android\res\values\billing_key_param.xml.

Observed behavior

On my code, "Init failed - String resource ID #0x0" is fired, and " STORE READY " is not fired.

Steps to reproduce

Boot my app.

Then, my code is called.

My code

onDeviceReady: function() {
    initializeStore();
}

function initializeStore() {
    store.verbosity = store.INFO;

    store.register({
        id:    "product_id",
        alias: "payed content",
        type:  store.PAID_SUBSCRIPTION
    });

    store.error(function(e){
        alert("ERROR " + e.code + ": " + e.message);
    });

    store.ready(function() {
        alert("*** STORE READY ***");
    });

    store.refresh();
}
j3k0 commented 5 years ago

@K-Endo369 Can you provide some adb logcat traces or anything?

Did you follow all the steps for Android setup?

https://github.com/j3k0/cordova-plugin-purchase/wiki/Android-Troubleshooting

K-Endo369 commented 5 years ago

I have a question about the steps of Android-Troubleshooting.

"Are you testing on a non-rooted device?"

Sorry for my poor English, is this means "Device is not broken and works with no problem." ?

If so, there is no problem with my setup for Android.

I'm trying to get the logs with adb logcat.

I will show you the logs ASAP.

j3k0 commented 5 years ago

Google "android rooted device"

Rooting is the Android equivalent of jailbreaking, a means of unlocking the operating system so you can install unapproved apps, deleted unwanted bloatware, update the OS, replace the firmware, overclock (or underclock) the processor, customize anything and so on...

K-Endo369 commented 5 years ago

Sorry for being late my reply.

Thank you for explaining Android rooted device.

My Android devices is not rooted device.

And I show the logs got by adb logcat below.

Currently, the product ID of payed content is "1".

I/chromium( 1097): [INFO:CONSOLE(2)] "Uncaught Error: The custom element being constructed was not registered withcustomElements.", source: https://unpkg.com/onsenui@2.10.5/js/onsenui.min.js (2) I/chromium( 1097): [INFO:CONSOLE(1513)] "[store.js] DEBUG: store.queries !! '1 registered'", source: file:///android_asset/www/plugins/cc.fovea.cordova.purchase/www/store-android.js (1513) I/chromium( 1097): [INFO:CONSOLE(1513)] "[store.js] DEBUG: store.queries !! 'payed content registered'", source: file:///android_asset/www/plugins/cc.fovea.cordova.purchase/www/store-android.js (1513) I/chromium( 1097): [INFO:CONSOLE(1513)] "[store.js] DEBUG: store.queries !! 'paid subscription registered'", source: file:///android_asset/www/plugins/cc.fovea.cordova.purchase/www/store-android.js (1513) I/chromium( 1097): [INFO:CONSOLE(1513)] "[store.js] DEBUG: store.queries !! 'subscription registered'", source: file:///android_asset/www/plugins/cc.fovea.cordova.purchase/www/store-android.js (1513) I/chromium( 1097): [INFO:CONSOLE(1513)] "[store.js] DEBUG: store.queries !! 'registered'", source: file:///android_asset/www/plugins/cc.fovea.cordova.purchase/www/store-android.js (1513) I/chromium( 1097): [INFO:CONSOLE(1513)] "[store.js] DEBUG: store.queries !! '1 updated'", source: file:///android_asset/www/plugins/cc.fovea.cordova.purchase/www/store-android.js (1513) I/chromium( 1097): [INFO:CONSOLE(1513)] "[store.js] DEBUG: store.queries !! 'payed content updated'", source: file:///android_asset/www/plugins/cc.fovea.cordova.purchase/www/store-android.js (1513) I/chromium( 1097): [INFO:CONSOLE(1513)] "[store.js] DEBUG: store.queries !! 'paid subscription updated'", source: file:///android_asset/www/plugins/cc.fovea.cordova.purchase/www/store-android.js (1513) I/chromium( 1097): [INFO:CONSOLE(1513)] "[store.js] DEBUG: store.queries !! 'subscription updated'", source: file:///android_asset/www/plugins/cc.fovea.cordova.purchase/www/store-android.js (1513) I/chromium( 1097): [INFO:CONSOLE(1513)] "[store.js] DEBUG: store.queries !! 'updated'", source: file:///android_asset/www/plugins/cc.fovea.cordova.purchase/www/store-android.js (1513) I/chromium( 1097): [INFO:CONSOLE(1513)] "[store.js] DEBUG: store.trigger -> triggering action refreshed", source: file:///android_asset/www/plugins/cc.fovea.cordova.purchase/www/store-android.js (1513) I/chromium( 1097): [INFO:CONSOLE(1513)] "[store.js] DEBUG: queries !! 'refreshed'", source: file:///android_asset/www/plugins/cc.fovea.cordova.purchase/www/store-android.js (1513) I/chromium( 1097): [INFO:CONSOLE(2040)] "InAppBilling[js]: setup ok", source: file:///android_asset/www/plugins/cc.fovea.cordova.purchase/www/store-android.js (2040) I/chromium( 1097): [INFO:CONSOLE(2040)] "InAppBilling[js]: load ["1"]", source: file:///android_asset/www/plugins/cc.fovea.cordova.purchase/www/store-android.js (2040) I/chromium( 1097): [INFO:CONSOLE(2)] "Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.", source: file:///android_asset/www/js/jquery-1.8.2.min.js (2)

j3k0 commented 5 years ago

Not seeing any errors reported on this logcat after load is called. But you might have something on the native side. Can you send logcat output without filtering chromium? Especially things that happen after [INFO:CONSOLE(2040)] "InAppBilling[js]: load ["1"]"

K-Endo369 commented 5 years ago

Thank you for confirming the logs. And I give you row logs.

log.txt

j3k0 commented 5 years ago
E/PluginManager( 1097): android.content.res.Resources$NotFoundException: String resource ID #0x0
[...]
E/PluginManager( 1097):     at com.smartmobilesoftware.inappbilling.InAppBillingPlugin.getPublicKey(InAppBillingPlugin.java:156)

This is the code that loads the billing key.

Out of curiosity, what versions of things are you using? Can you paste the output of cordova info ?

K-Endo369 commented 5 years ago

I give you cordova information. I filtered some private information by XXXXXXXX. I use Android@6.3.0 but the latest version is Android@7.0.0. So, I try with the latest Android version and will report the result to you.

cordova-info.txt

j3k0 commented 5 years ago

Thanks.

Note that there are reported issues with cordova-android@7.2.1 (not on my machine though). In case you experience issues, cordova-android@7.1.1 will work.

Let me know!

aesculus commented 5 years ago

I am seeing this on some devices. Using Android 7.0.0 and plugin at 7.2.4. The only change I made was moving the plugin code from 7.2.1 to 7.2.4 so I am going to go back to that and see if the users don't have an issue.