Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

[Bug] UnityIAP 2.2.0 migration problem - Google v3 initialization

Discussion in 'Unity IAP' started by KEric, Jan 28, 2021.

Thread Status:
Not open for further replies.
  1. KEric

    KEric

    Joined:
    Jan 11, 2013
    Posts:
    62
    Hey,
    Yesterday I was pushing a new release of my game to Google Play Store via Developer Console. After successful bundle transfer I've received a warning message that I'm using an older version of an in app billing module and it is advisable to migrate to new one (exact message below). Therefore I've updated all packages/services to the newest versions (Unity: 2019.4.18f1 (64-bit), package: In App Purchasing 2.2.2, UnityIAP: 2.2.6).
    The problem I'm encountering now occur during IAP initialization process which works in an unpredictable way. Once every now and again it works just fine, resulting in a proper in app behavior - initialization as well as product's purchase works as expected. But more than often the initialization process fails with the following logcat message:
    Can anyone help me with this one, as I've already spent a whole day trying to track the issue down and knowing it worked before just adds up to the frustration.
    Thanks

    EDIT: I tried to update UnityIAP module iteratively starting from v.1.23.5 (as this was the version I was upgrading from). I was able to successfully upgrade UnityIAP to v.2.1.1. The described problem arose after upgrading to 2.2.0.
     
    Last edited: Jan 28, 2021
  2. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    We would need steps to reproduce. You indeed have a produce called "test"? Just checking. Ensure you haven't installed the Google billing library separately, including Google Play Services. Please compare to the behavior using the Sample IAP Project (specifically compare to the code in IAPManager.cs) https://forum.unity.com/threads/sample-iap-project.529555/
     
  3. KEric

    KEric

    Joined:
    Jan 11, 2013
    Posts:
    62
    Hey Jeff, thanks for a quick reply.
    This is a project that has been on the Google Store for a long time and until migration to 2.2.0 I've never had any problems with the billing module. As I've mentioned before the behavior after the upgrade to 2.2.0 is very unpredictable as from time to time IAP initialization is performed successfully, but unfortunately more than often it fails with the error message described above.
    I've already checked IAPManager.cs to see if there might've been an issue with the code, but I haven't notice anything that could possibly trigger an error. Initialization code is performed in the following way:

    Code (CSharp):
    1. public void Init()
    2. {
    3.     if (IsInitialized)
    4.         return;
    5.     var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
    6.     builder.AddProduct(Coins_1, ProductType.Consumable);
    7.     // etc...
    8.     UnityPurchasing.Initialize(this, builder);
    9. }
    10.  
    11. bool IsInitialized { get { return controller != null && extensions != null; } }
    Unity's, IAP service's and package's versions are exactly as described above.
    In order to track the issue down maybe there is a way to print out more verbose information during the initialization of IAP billing system?
     
  4. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Please refer to my initial reply. Can you confirm my questions? Please provide the device logs https://forum.unity.com/threads/how-to-capturing-device-logs-on-android.528680/ and steps to reproduce. Something is different between your tests, you'll need to determine what it is. How are you exiting the program? Does the behavior change when you first install the game vs restarting the game?
     
  5. KEric

    KEric

    Joined:
    Jan 11, 2013
    Posts:
    62
    Logcat messages after migration to IAP 2.2.6
     
  6. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Are those products defined on your Google Dashboard? I'll wait for your reply to my other statements also.
     
  7. KEric

    KEric

    Joined:
    Jan 11, 2013
    Posts:
    62
    I don't fully understand this statement. Both package and IAP Service were upgraded via Unity's IDE.

    The testcase: 1. opening the game (checking logcat messages via Android Studio); 2. opening in-game store and checking the pricing on the products (when initialization fails in 1. step I pretty much already know the IAP doesn't work)

    Via Android's platform process termination - pressing HW button on my device which results in list of processes and swiping the game's process into oblivion.

    As I've already described the occurrence of this behavior is completely random.
     
  8. KEric

    KEric

    Joined:
    Jan 11, 2013
    Posts:
    62
    Those products are defined in project's dashboard in Google Developer Console - as I've already stated it's a project that has been on the Google Store for a long long time and the billing system always worked without a flaw.
     
    Last edited: Jan 28, 2021
  9. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    So sometimes it works, and other times not? Something is clearly different between invocations. Without steps to reproduce (understood it appears randomly for you) unfortunately there isn't anything I can suggest at this point. Other than using a previous IAP version. I had asked if you were installing the Google Billing library separately, or were using Google Play Services separately. You would know as these would be explicit steps, understand the answer is no if you did not install these packages. I had asked about how you exit the app, the use of Application.Quit can cause unpredictable behavior and leave some components still in memory, but does not seem to be the case here.
     
  10. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Can you compare your behavior with Unity 2019 vs Unity 2020.1?
     
  11. KEric

    KEric

    Joined:
    Jan 11, 2013
    Posts:
    62
    Problem still exists after upgrading Unity to v.2020.1

    Testcase with failed initialization:
    Testcase with successful initialization:
     
  12. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Got it, thanks for the update. Unfortunately I don't have any additional suggestions for you. You might try with the Sample IAP Project to compare in case the other components in your project may be related. And you are using the same user account on the phone? I suspect so, but wanted to confirm. And you're not clearing the Google Play cache or any other activity between your tests? It almost sounds like a Google issue, but I've never heard of this type of behavior. I'm currently testing right now myself, and I'm not seeing any issues. I'm using the Sample project in my testing.
     
  13. KEric

    KEric

    Joined:
    Jan 11, 2013
    Posts:
    62
    1. I'm using the same account between test cases
    2. I'm not clearing cache between test cases. Clearing cache is irrelevant as it shouldn't cause any side effects

    Is there a way to get more verbose printout out of a billing IAP system? I'm pretty much out of ideas now, unless there is some weird problem on Google's side (I doubt)
     
  14. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    No there isn't any "secret" way to obtain more information. Just the device logs. Compare to the Sample IAP Project as your path forward
     
  15. KEric

    KEric

    Joined:
    Jan 11, 2013
    Posts:
    62
    I did compare the source code with the example you've pointed out as well as with several other sources available on the internet and there's nothing suspicious that could caught my eye.
    I've also tried wiping out UnityPurchases folder, reimporting modules from scratch etc. always ending up with the same problem.
    I'm attaching the source code that is used during initialization process. If there is anything else that could help with tracking the issue down please let me know as it's a second day I'm struggling with it.

    Code (csharp):
    1. using System;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Purchasing;
    5. using UnityEngine.Purchasing.Security;
    6.  
    7. public class IAPManager : MonoBehaviour, IStoreListener
    8. {
    9.     public static string Coins_1 = "coins_1";
    10.     // etc...
    11.  
    12.     private IStoreController controller; // The Unity Purchasing system
    13.     private IExtensionProvider extensions; // The store-specific Purchasing subsystems
    14.  
    15.     public void Init()
    16.     {
    17.         if (IsInitialized)
    18.             return;
    19.  
    20.         var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
    21.  
    22.         builder.AddProduct(Coins_1, ProductType.Consumable);
    23.         // etc...
    24.  
    25.         UnityPurchasing.Initialize(this, builder);
    26.     }
    27.  
    28.     private bool IsInitialized { get { return controller != null && extensions != null; } }
    29.  
    30.     // etc...
    31.  
    32.     public static IAPManager Instance
    33.     {
    34.         get
    35.         {
    36.             if (instance == null)
    37.             {
    38.                 instance = GameObject.Find("IAPManager")?.GetComponent<IAPManager>();
    39.                 if (instance == null)
    40.                     instance = new GameObject("IAPManager").AddComponent<IAPManager>();
    41.                 DontDestroyOnLoad(instance.gameObject);
    42.                 instance.Init();
    43.             }
    44.             return instance;
    45.         }
    46.     }
    47. }
     
  16. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Only what I've already mentioned, other packages, etc. I meant actually publish and test the Sample project
     
  17. KEric

    KEric

    Joined:
    Jan 11, 2013
    Posts:
    62
    I've contacted Goolge team and I got the following, @JeffDUnity3D could you help me with this one?

    "The reason i asked is the variable listed in the error shows coins_1-coins_1 which seems odd and should only be coins1 as far as I know. I am not a programmer, but that part seems odd.
    Could this be an issue with Unity implementation?"
     
  18. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Please summarize your issue, I'm not following. Your product name is defined by you, and appears to be coins_1 And you are not using the code from the Sample project, I would not be able to debug your code.
     
  19. KEric

    KEric

    Joined:
    Jan 11, 2013
    Posts:
    62
    The above quotation is a response that I've received from a googleplay-developer-support.
    The log points out to Unity's process - could you provide an information why there are two products printed out?

     
  20. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    No particular reason, we print out the product first followed by a hyphen then the product again. It's just the log output.
     
  21. KEric

    KEric

    Joined:
    Jan 11, 2013
    Posts:
    62
    Just letting know that it started to know, but I don't know why. If I'll get to the bottom of the issue I'll let you know.
    Thanks!
     
  22. KEric

    KEric

    Joined:
    Jan 11, 2013
    Posts:
    62
    The reason it failed was that my Init() function was triggered two times, practically at the same time. The portion of code that was initializing IAP looked as follows IAPManager.Instance.Init() - the problem was that my singleton Instance method was internally triggering Init() as well. Removing it from Instance method fixed the issue.

    Code (CSharp):
    1.  
    2.     public void Init()
    3.     {
    4.         if (IsInitialized)
    5.             return;
    6.  
    7.         var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
    8.  
    9.         builder.AddProduct(Coins_1, ProductType.Consumable);
    10.         // ...
    11.  
    12.         UnityPurchasing.Initialize(this, builder);
    13.     }
    14.  
    15.     public static IAPManager Instance
    16.     {
    17.         get
    18.         {
    19.             if (instance == null)
    20.             {
    21.                 instance = new GameObject("IAPManager").AddComponent<IAPManager>();
    22.                 DontDestroyOnLoad(instance.gameObject);
    23.                 Init(); // <-- removed
    24.             }
    25.             return instance;
    26.         }
    27.     }
     
    JeffDUnity3D likes this.
  23. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    FYI a one-hour test with the Sample IAP Project would have highlighted your issue also.
     
  24. KEric

    KEric

    Joined:
    Jan 11, 2013
    Posts:
    62
    A little warning message either in the IDE or logcat would've been more effective
     
  25. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Initialization is indeed logged via logcat. Locking this resolved thread
     
Thread Status:
Not open for further replies.