Crash in Android In-App Purchase native code

Hi there. Can someone help me to set IAP for android? I’m getting crash while getting products information.

        if (InAppPurchases::getInstance()->isInAppPurchasesSupported())
            StringArray identifiers;
            identifiers.add ("MyCoolProduct");

I see that GetProductsInformationJob is running fine and callback is called, but suddenly got crash while deleting one of jstring references in this line

I’ve just started to learn how things work in Android-Juce bridge. So probably I don’t know something significant about jstring object lifetime. I’ve tried to declare global const StringArray identifiers = {"MyCoolProduct"} but without luck

Thanks for your help

Well, the problem is still confusing me. The crash appears when GetProductsInformationJob object is destroyed inside Juce IAP classes. Please someone can confirm that IAP working well on Android?

Ok the problem is in the lifetime of LocalRef<jstring> packageNameToUse. LocalRef created by getPackageName() and passed to new job here (juce_android_InAppPurchases.cpp, line 120)
threadPool->addJob (new GetProductsInformationJob (*this, getPackageName(), productIdentifiers, callback), true);

is deleted before the job finished of course. So SIGABRT appears.

E.g. this doesn’t crash:
static auto packageName = getPackageName(); threadPool->addJob (new GetProductsInformationJob (*this, packageName, productIdentifiers, callback), true);

I believe there is normal solution: like using GlobalRef. Can anyone help me to figure it out? thanks

Thanks for looking into this. I’ve pushed a couple of commits that should fix the issue:

Please let us know if this fixes the problem for you.

1 Like

Works perfect. Thanks for fix!