jamesmontemagno / InAppBillingPlugin

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

Can not compile on Android after updating from version 2 to version 4 #359

Closed Hobbit7 closed 3 years ago

Hobbit7 commented 3 years ago

I have changed the Target Android version in AndroidManifest.xml to Android 10.0 (API level 29). But I still get a few error messages after updating from version 2 to version 4.

protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); Xamarin.Essentials.Platform.Init(this, bundle); Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity = this; }

Error CS0234: The type or namespace name 'CurrentActivity' does not exist in the namespace 'Plugin' (are you missing an assembly reference?)

Should I remove the line Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity = this;? Is this line not needed in version 4?

protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { base.OnActivityResult(requestCode, resultCode, data); InAppBillingImplementation.HandleActivityResult(requestCode, resultCode, data); }

Error CS0117: 'InAppBillingImplementation' does not contain a definition for 'HandleActivityResult'

I have not understand if I only should delete the line InAppBillingImplementation.HandleActivityResult(requestCode, resultCode, data); or if I should delete the entire code block void OnActivityResult?

In addition, I get two error messages when I want to purchase an item: ` if (CrossInAppBilling.IsSupported == true) { var billing = CrossInAppBilling.Current; try { var connected = await billing.ConnectAsync(ItemType.InAppPurchase); if (connected == true) { var verify = DependencyService.Get();

                    var purchase = await billing.PurchaseAsync(productId, ItemType.InAppPurchase, payload, verify);`

Error CS1503: Argument 1: cannot convert from 'Plugin.InAppBilling.ItemType' to 'bool' Error CS1501: No overload for method 'PurchaseAsync' takes 4 arguments

What is wrong with the purchase code? What should I change?

I read this here on github: `Version 3+ Linker Settings

For linking if you are setting Link All you may need to add:

Android:

Plugin.InAppBilling;Xamarin.Android.Google.BillingClient; iOS:

--linkskip=Plugin.InAppBilling`

Is it necessary that I change something after I updated from version 2 to version 4 or is this for version 3 only?

jamesmontemagno commented 3 years ago

See -> https://github.com/jamesmontemagno/InAppBillingPlugin#version-4-major-update---android

Meekohi commented 3 years ago
var context = Platform.AppContext;
var activity = Platform.CurrentActivity;

I don't understand where this goes? What is Platform here? It isn't valid code in my MainActivity (AppContext is a type).

Meekohi commented 3 years ago

Needed to be

            var context = Xamarin.Essentials.Platform.AppContext;
            var activity = Xamarin.Essentials.Platform.CurrentActivity;

Also see https://github.com/jamesmontemagno/InAppBillingPlugin/issues/364