jamesmontemagno / InAppBillingPlugin

Cross-platform In App Billing Plugin for .NET
MIT License
651 stars 152 forks source link

Android crash due to missing InAppBillingServiceConnection::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership) #53

Closed eliotg closed 7 years ago

eliotg commented 7 years ago

Bug Information

I'm using this plugin (and it's GREAT and I love it), but when I call the code below it crashes. Not immediately, but this is the offending code that if commented out prevents the crash. And it's pretty plain to see from the stack trace and exception details linked to below. I looked at the constructors for InAppBillingServiceConnection in src\Plugin.InAppBilling.Android\InAppBillingImplementation.cs and it wasn't immediately obvious how accepting the requested parameters would work, nor could I find a call site in the code trying to do that.

Thanks and please let me know if I can be of any help!

Version Number of Plugin: 1.1.0.35-beta Device Tested On: Samsung Galaxy S5 (Android 6.0.1) Version of VS: 14.0.25431.01 Update 3 Version of Xamarin: 4.5.0.443 Versions of other things you are using: Xamarin.Android 7.3.0.13

Steps to reproduce the Behavior

Run the code snippet below, nearly verbatim from sample docs

Expected Behavior

Less crashing, more successful execution

Actual Behavior

Unhandled exception: https://gist.github.com/eliotg/bb9d8aaeeec21875e3766d6e67d2a5b3

Code snippet

        const string DEFAULT_SUB = "default_sub";

        public enum BillingResult
        {
            LicenseActive,
            LicenseInactive,
            ConnectionError,
            ErrorPurchasing,
            Exception
        }

        public static async Task<BillingResult> IsInstallationLicenseActive()
        {
            try
            {
                if (!await CrossInAppBilling.Current.ConnectAsync())
                    return BillingResult.ConnectionError;

                //check purchases
                var purchases = await CrossInAppBilling.Current.GetPurchasesAsync(ItemType.InAppPurchase);
                if (purchases?.Any(p => p.ProductId == DEFAULT_SUB) ?? false)
                    return BillingResult.LicenseActive;
                else
                    return BillingResult.LicenseInactive;
            }
            catch (Exception ex)
            {
                return BillingResult.Exception;
            }
            finally
            {
                await CrossInAppBilling.Current.DisconnectAsync();
            }
        }
jamesmontemagno commented 7 years ago

Added additional constructors.