Search Unity

[Solved] IAP : ArgumentException thrown at Initialize on Android

Discussion in 'Unity IAP' started by AlexIndeegoGames, Dec 15, 2015.

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

    AlexIndeegoGames

    Joined:
    Sep 7, 2015
    Posts:
    2
    Hi guys,

    The purchasing system seems to throw an ArgumentException "An element with the same key already exists in the dictionary" at initialization. I tested with 2 different devices (both on Android) with no success. But it works fine on editor.
    Anyway, beginning of my code is :
    Code (CSharp):
    1. void Start()
    2.     {
    3.         if (m_StoreController == null)
    4.         {
    5.             InitializePurchasing();
    6.         }
    7.     }
    8.  
    9.     void InitializePurchasing()
    10.     {
    11.         if (IsInitialized())
    12.         {
    13.             return;
    14.         }
    15.  
    16.         // Create a builder, first passing in a suite of Unity provided stores.
    17.         var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
    18.  
    19.         // Add a product to sell / restore by way of its identifier, associating the general identifier with its store-specific identifiers.
    20.         builder.AddProduct(kProductID0, ProductType.Consumable, new IDs() { { kProductNameAppleConsumable, AppleAppStore.Name }, { kProductNameGooglePlayConsumable, GooglePlay.Name } });
    21.         builder.AddProduct(kProductID1, ProductType.Consumable, new IDs() { { kProductNameAppleConsumable, AppleAppStore.Name }, { kProductNameGooglePlayConsumable, GooglePlay.Name } });
    22.         builder.AddProduct(kProductID2, ProductType.Consumable, new IDs() { { kProductNameAppleConsumable, AppleAppStore.Name }, { kProductNameGooglePlayConsumable, GooglePlay.Name } });
    23.         builder.AddProduct(kProductID3, ProductType.Consumable, new IDs() { { kProductNameAppleConsumable, AppleAppStore.Name }, { kProductNameGooglePlayConsumable, GooglePlay.Name } });
    24.         builder.AddProduct(kProductID4, ProductType.NonConsumable, new IDs() { { kProductNameAppleNonConsumable, AppleAppStore.Name }, { kProductNameGooglePlayNonConsumable, GooglePlay.Name } });
    25.         Debug.Log("Trying to initialize");
    26.         UnityPurchasing.Initialize(this, builder);
    27.     }
    28.  
    29.       bool IsInitialized()
    30.      {
    31.         return m_StoreController != null && m_StoreExtensionProvider != null;
    32.      }
    I can't even get a OnInitializedFailed callback. The only piece of information I have on my console is :

    Of course, all my keys are different strings.
    Help !!
     
  2. AlexIndeegoGames

    AlexIndeegoGames

    Joined:
    Sep 7, 2015
    Posts:
    2
    Okay, I think I had misunderstood something with the builder.AddProduct instruction. To do
    Code (CSharp):
    1. builder.AddProduct(kProductID0, ProductType.Consumable, new IDs() { { kProductNameAppleConsumable, AppleAppStore.Name }, { kProductNameGooglePlayConsumable, GooglePlay.Name } });
    2.         builder.AddProduct(kProductID1, ProductType.Consumable, new IDs() { { kProductNameAppleConsumable, AppleAppStore.Name }, { kProductNameGooglePlayConsumable, GooglePlay.Name } });
    is actually a mistake, right ? The "IDs" parameter is to specify the key on one store specifically. But if the key is the same on all stores, I can simply call
    Code (CSharp):
    1. builder.AddProduct(kProductID0, ProductType.Consumable);
    Am I right, now ?
     
  3. mpinol

    mpinol

    Joined:
    Jul 29, 2015
    Posts:
    317
Thread Status:
Not open for further replies.