I am using Unity 2018.4.28.1, Unity IAP 2.0.8, Google Play Billing 3.2.0 and I start getting following non fatal errors in Crashalitics:
at UnityEngine.Purchasing.ReflectionUtils.HasMethodInInterface(UnityEngine.Purchasing.ReflectionUtils)
at UnityEngine.Purchasing.GoogleFetchPurchases.OnFetchedPurchase(UnityEngine.Purchasing.GoogleFetchPurchases)
at UnityEngine.Purchasing.Extension.UnityUtil.OnApplicationPause(UnityEngine.Purchasing.Extension.UnityUtil)```
I found [this topic](https://discussions.unity.com/t/828212) but unfrotunately it's closed and the topic starter did not share the solution =(
According to the logs, it happens when app first loses focus and then gets it back in 30-60sec. Here is the [screenshot](https://i.imgur.com/DHgR95G.png) (the notifications are scheduled when app loses focus). In few cases the app just started, minimized, get active again and the exception happens ([screenshot](https://i.imgur.com/C7gT3md.png)).
I was attempting to get rid of ANR which was caused by
**com.android.billingclient.api.BillingClientStateListener.onBillingServiceDisconnected** and
**com.android.billingclient.api.BillingClientStateListener.onBillingSetupFinished**. So I followed suggestion [here ](https://github.com/google/play-unity-plugins/issues/29)and applied [this](https://github.com/google/play-unity-plugins/compare/master...PerBlue:reconnect_clear_receiver) change to **GooglePlayStoreImpl.cs** class. The ANR seems to be gone but the error above appeared =)
As for now there is just 80+ cases and only 10 users are affected but iapp was released only to 10% of the users, so number should increase by tomorrow. Do you have any suggestion how to fix or debug this excetpion?
Thanks for any hints
p.s. I implemented IAP by my own, I am trying to initialize it on app's start up, in case of failure, I am waiting for a minute and trying again. The IAP was working fine and I do not have reasons to think it stopped working with last release.
My doubt come true: 200+ cases and 50+ affected users and still counting. Should I search issue in my code or is ti issue of Unity IAP? When “HasMethodInInterface” method is called an what it is looking for? Thanks
You might want to compare to the Sample IAP Project v2 here, we have not heard of this error (but it’s possible!) Do not mix the recommendations from Google vs Unity and is likely the issue Sample IAP Project
Thanks for your attention @JeffDUnity3D . I saw your suggestion in another post and despited I compared the code before creating this topic, I did it again (you can always miss something little but important). So the initialization logic looks the same but I need to verify:
MyIAPManager.cs: on line 32 the initialization is started only if only m_StoreController is null, but on line 46 we use IsInitialized() method which checks both m_StoreController and m_StoreExtensionProvider. Does it mean that if we do auto initialization then we should do this only if m_StoreController is null because there is a chance that it will not be null while m_StoreExtensionProvider will be null? (probably in the middle of previous initialization) or that’s just typo?
The solution provided in Sample IAP Project v2 assumes that we should NOT retry initialization in case of failure (in our case it’s every 60 sec)?
To be honest, I like the logic: instead of trying to initialize IAP every N second, we can try to do it at app’s start and then when store window will be openned or whatever pre purchase user action will occure. At least, this should reduce the chance that initialization will be in the middle, when app will be sent to background and the issue mentioned in inital post will arise.
Taking in an account that this non fatal issue appeared only after applying this few lines. Do not Unity team plan to investigate the case, as it was reported on GitHub on Nov 14, 2020?
I also noticed one extra line: SetDeferredPurchaseListener(OnPurchaseDeferred) and according to this topic , seems like blank listenere must be set. Could you please confirm?
The github case you linked to is a Google issue. The deferred listener is optional (won’t cause errors without it) but is necessary to properly handle deferred purchases. But you may be correct about your particular issue, it should be ok to attempt to initialize multiple times (but only successfully initialize once). Could you provide specific steps to reproduce by making the minimum necessary changes to the Sample IAP Project?
The problem is that we cannot reproduce this error on our since it’s rare. Currently we can see 1.1k cases and 240 users affected. 45% of devices are Samsung and 35% are Android 11 and 34% are Android 10. It means we need to somehow debug it on production. We can add additonal logs to see if IStoreController and IExtensionProvider are not null when this error appears, as well as the log when OnInitialized method is called. What I can say for sure is that internetReachability is not NotReachable, since we made that extra check before attempting to initialize. The code which we use for intialization is pritty simple:
As you may notice, once IAP gets initialized, we are going through list of available products which is stored in public property productRecordList, unlike how controller.products.all is used in sample project. Can this be a reason of null reference? @JeffDUnity3D , since the game object which holds IAP manager script is marked as DontDestroyOnLoad, we assumed it can never be null due to parent destruction.
What else we can add to logs to narrow the searching scope? If the code which I linked is Google’s issue then we can do nothing… unless debug Google’s native plugin (I am not even sure that we have sources to that). Seems like we need to better undestand what applied patch is destroying.
What “applied patch” are you referring to? Unfortunately without steps to reproduce there isn’t much we can do. We would also need repro steps to test any potential fix. Keep in mind that checking for an internet connection is tricky. A mobile device might have a valid connection to your home router and have a valid IP address, but the router may not have a connection to the Internet. I might suggest to not check the internet at all, but it’s up to you, and test similarly.
I understand @JeffDUnity3D that we need steps to reproduce the issue. The good news is that I personally somehow managed to generate it 4 times (accidently) but I am not sure in exact steps. I will keep searching.
Question 1: in package manager IAP package is 2.0.6 but when we click Window > Unity IAP > IAP Updaes, it’s telling that we have 2.3.0 version. Are those two different components but with similar name?
Also, since we know it’s IAP issue, we tried to downgrade back to last stable version and noticed that com.google.play.billing-3.2.0 package is dependent on com.unity.purchasing-2.1.1 while we had 2.0.3 installed. So now we decided to downgrade to com.google.play.billing-3.0.2 which depends on com.unity.purchasing-2.0.6 and update com.unity.purchasing to verified 2.0.6 version.
Question 2: how everything was working for more than a year if we were using com.google.play.billing which was dependedn on com.unity.purchasing -2.0.6 while we had com.unity.purchasing -2.0.3 installed and why we see no warning from Unity about that?
2.0.6 was associated with the IAP version that used Google Play Billing v2. Google requires v3 now, which is included in 2.3.0 (Asset version) and 3.2.3 (Package Manager version). The Asset version will no longer be updated, so you’ll want to upgrade to the 3.x (and 4.x) version of IAP soon. And I don’t quite follow the patch conversation, are you using the Google plugin? We would not support this configuration if you are referring to Use the Google Play Billing Library with Unity | Google Play's billing system | Android Developers. Are you installing or configuring anything separately other than the Unity IAP package?
I have an assumption, that if we install In App Purchasing 2.0.6 and then import UnityIAP package which is located in Assets\Plugins\UnityPurchasing folder, then we no longer need to import Google Play Plugins by our own and UnityIAP package will handle it for us?
Thanks in advance for your time and waiting for your reply
p.s. I just understood that In App Purchasing and UnityIAP ar two diffrent packages =)
UPD: My assumption was right. Even more, I rechecked Simple IAP project and noticed that we no longer need to use target dependent ConfigurationBuilder. Instead, we use StandardPurchasingModule and set target via UnityIAP package. We will make partial release tomorrow and check if that will resolve ANRs as good as the patch.
We would not be able to support this configuration. In App Purchasing and UnityIAP are one in the same. Previously we required both an Asset package and a Package Manager package, but the 3.x versions now consolidate everything into a Package Manager package. We already include Google Play Billing Library v3, there is no need to import the Google plugin. The latest (and final) Asset store package is 2.3.0 which corresponds to Package Manager version 3.2.3. Earlier versions of Unity (pre 2019.4) may require the 2.3.0 Asset package, more recent versions of Unity should use 3.2.3 from Package Manager.
Thank you for your confirmation @JeffDUnity3D . We are able to see In App Purchasing 2.2.2 (screenshot) in Pachage Manager (Unity 2018.4). We are currently using 2.0.6 as it has verified tag and also because it uses Google Billing 3.0.3 (which we know was working fine).
Should we update project to Unity 2019.4 or 2020 to see In App Purchasing 3.*?
Will I be right if I say that In App Purchasing 3.* will install UnityIAP automatically?
We have couple of confirmations that after we removing Google Play Plugins and using new UnityIAP impelmentation, the app crash is gone. Currently we are waiting for ANR reports.
In App Purchasing is the same as Unity IAP, as mentioned. You can install multiple versions of Unity with the Hub, use the version that works best for you. Unity IAP 2.0.6 does not use Google Billing v3, it uses v2. Unless you install the Google Unity plugin separately, which we don’t support. I should add, make a full backup of your project before any major upgrade.
Oh… I got it! We were using three different sources (UnityIAP, IAP and Google Plugins). So yesterday we removed Google Plugins but we are still using too much. We can get rid of IAP or UnityIAP. UnityIAP was imported via Services. So currrently we have two options:
Remove UnityIAP and use IAP 2.0.6 from Package Manager
Remove IAP from Package Manger and use UnityIAP 2.3.0 from services
If I am right then I want to clarify, If we remove UnityIAP then how can we target Google Play? We can see such option in menu (created by UnityIAP) but IAP just adds UnityPurchasing to Plugins folder.
Thank you! I am sure, this topic will be very useful to others who may reach it via Google search.
UPD: When we tried to remove UnityPurchasing from Plugin folder (IAP is still installed via Package Manger), we start getting error about missing StandardPurchasingModule. Should we implement purchasing in different way if IAP from Package Manager is used?
Don’t use the Service window or Import anything, the Service window will be going away eventually. Ignore any “Import” buttons or messages. Remove everything under /Assets/Plugins/UnityPurchasing. Only install IAP from Package Manager. Compare to a new project.
Thank you. I believe we are very close to solution. So we followed your suggestion and removed /Assets/Plugins/UnityPurchasing folder. Then removed IAP from Package Manager (just in case). Restarted Unity and then installed IAP from Package Manager. All compilation errors gone with exception of one:
error CS0103: The name 'StandardPurchasingModule' does not exist in the current context
ConfigurationBuilder builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
Do we need to add antyhing besides using UnityEngine.Purchasing?
I should also mention that after installing IAP via Package Manager, nothing was added to /Assets/Plugins and /Packages folders. However, /Packages/manifest.json contains “com.unity.purchasing”: “2.0.6”, line.
UPD: We found com.unity.purchasing in /Library/PackageCache/ and in %LOCALAPPDATA%/Unity/cache. However in both cases there are only Tests and Editor folder. There is missing Runtime folder with classes (which exist if we import IAP via Services).
Your project may be corrupt from the previous Google plugin. Compare to a new project, and compare to the Sample IAP Project v2 here Sample IAP Project . You can always delete the /Library and cache folders, they will be regenerated. Sample IAP Project
@JeffDUnity3D We compared our project with sample one and they use the same code:
var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
We tried to delete both /Library and %LOCALAPPDATA%/Unity/cache folders but problem remained. Please pay attention that if we remove IAP 2.0.6 then we see lot of IAP related errors. When we install it back, all errors gone except missing StandardPurchasingModule. We also tried to create new project and it has the same problem.
The sample project is using IAP 3.0.1 which is not available via Package Manager in Unity 2018.4. The highest version we can see is 2.2.2. I believe Package Manager version of IAP 2.0.6 is still requires to use UnityIAP isntalled from Services.
@andrew_pearce As mentioned, don’t ADD the code from the Sample project to yours. Actually get the Sample IAP Project working and published to test! Don’t use Unity 2018.4, please upgrade to Unity 2020+ if you can. Then apply lessons learned to your project. As I mentioned, the Google Unity Plugin may have corrupted your project unfortunately, I would not know how to back out their changes.
@JeffDUnity3D the thing is that with Unity 2020.3 Sample IAP Project is working (IAP 3.2.2) but we do not think it’s wise to migrate from Unity 2018 to 2020 only for the benefit of having just IAP installed, instead of IAP + UnityIAP.
Any update = new crashes, ANRs and time wasting for debugging instead of developing new features. The current update is a good example: it will take a month to recover from it =)
I was hoping we can make just IAP work with Unity 2018 but if that’s not possible, we will keep using IAP + UnityIAP pair. Without Google Play Plugins everything seems to be working, no more complains from users. Unfortuantely, Google Play Console stopped updating ANRs since 21st of July but Chrashalitics data is very promising.