Search Unity

  1. Unity 2018.1 has arrived! Read about it here
    Dismiss Notice
  2. Scriptable Render Pipeline improvements, Texture Mipmap Streaming, and more! Check out what we have in store for you in the 2018.2 Beta.
    Dismiss Notice
  3. If you couldn't join the live stream, take a peek at what you missed.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  5. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  6. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Xiaomi IAP FAQs

Discussion in 'Unity IAP' started by unityjingyao, Aug 8, 2017.

  1. unityjingyao

    unityjingyao

    Unity Technologies

    Joined:
    Feb 20, 2017
    Posts:
    104
    Unity partner page:
    https://unity3d.com/partners/xiaomi
    Xiaomi developer quick start guide:
    https://unity3d.com/partners/xiaomi/guide
    Unity IAP Xiaomi integration guide:
    https://docs.unity3d.com/Manual/UnityIAPXiaomi.html
    Unity Channel SDK and API extensions:
    https://docs.unity3d.com/Manual/UnityIAPXiaomiAPI.html


    1. How may I test Xiaomi Mi Game Pay for Unity IAP (Xiaomi IAP)?

    If you set appInfo.debug to true when initializing Xiaomi IAP, you'll be able to test Xiaomi IAP without real money.
    If you want to test real purchasing, you must set appInfo.debug to false. Please note that real purchasing requires a Xiaomi Mi Account and appropriate currency such as Chinese Yuan.
    You can create a Mi Account on a Xiaomi device or Xiaomi official page: https://account.xiaomi.com

    2. I found an "Unavailable product..." log message and OnInitializeFailed() was fired with an InitializationFailureReason.NoProductsAvailable reason.
    Xiaomi IAP needs an IAP Catalog for product metadata before purchase.
    Configure all your products in [Window > Unity IAP > IAP Catalog].
    And then export the products by clicking "App Store Export -> Xiaomi Mi Game Pay Catalog".
    This step will export all products to "Assets\Plugins\Android\assets\MiGameProductCatalog.prop" which will be read by the Xiaomi SDK.






    3. How can I see the Xiaomi IAP log?
    In Android Studio, you can filter log with "(/Unity)|(/MiGameSDK)".


    4. How to restore my products in Xiaomi store?
    Xiaomi IAP doesn't have "Restore" feature. If a user bought a non-consumable product and reinstalled your game, when he/she tries to buy again, OnPurchaseFailed() will be fired with a PurchaseFailureReason.DuplicateTransaction reason.
    More information can be found in [Assets\Plugins\UnityPurchasing\script\IAPDemo.cs].



    5. What version of Unity should I use if I want to integrate Xiaomi IAP?
    Xiaomi IAP supports 5.3+.

    6. I can't buy a product when I set appInfo.debug to true, I found a "3001" error code in logcat printed by Xiaomi SDK.

    "3001" means "product doesn't exist". Please contact with Xiaomi to check your product IDs.

    7. When should our game make the call to login into the StoreService? Just before the player makes a purchase or rather at game startup?

    (* Copied from IAPDemo.cs)
    You just need to make sure that players login successfully before you call InitiatePurchase(). So both before the player makes a purchase and game startup are OK. It's up to you.

    8. I tried to sign in with Mi Account on my device, I have an error in unityChannelLoginHandler.loginFailedAction with "User Login Failed:-400" in the log.
    Please contact with Xiaomi to confirm that your products have been configured.

    9. We need the link to redirect player to the review page of the store during the game.
    You can use "market://details?id=your package name" as an Intent to redirect player to the review page of Xiaomi store.
    The URL for your game in Xiaomi app store(website) is "http://app.mi.com/details?id=your package name".


    10. My app crashed during initialization of UnityIAP and I found this crash log.
    All of appId, appKey, clientId, clientKey are necessary for the initialization of UnityChannel. So if any of them is null or empty, an exception should be thrown.
    appId and appKey can be any value in debug mode.


    11. I can’t push my apk to Xiaomi Dev Portal. There is no “Push to Xiaomi” option on my Cloud Build dashboard.


    The "Push to Xiaomi" option is only available to the Owner of the organization.


    Other Tips

    1. Google Play services are not allowed in Xiaomi store.

    2. Xiaomi IAP needs an extra login step which other app stores don't have. Please refer to Q7.

    3. App package name must end with ".mi".

    4. The prices must follow the tiers of Xiaomi IAP. All tiers can be found in "IAP Catalog" window. [Window -> Unity IAP -> IAP Catalog]
     
    Last edited: Feb 28, 2018
    ap-unity, rpistorello and nicholasr like this.
  2. pl_ayground

    pl_ayground

    Joined:
    Dec 17, 2015
    Posts:
    56
    Is there any chance this update makes some AliPay (or Xiaomi) related code get into the Xcode project? I got my app rejected by Apple stating AliPay is being used.
     
  3. hippogames

    hippogames

    Joined:
    Feb 5, 2015
    Posts:
    26
    Hi! I've got the following error when pressing "Generate Unity Client"
    How can I get error details?
     

    Attached Files:

  4. unityjingyao

    unityjingyao

    Unity Technologies

    Joined:
    Feb 20, 2017
    Posts:
    104
  5. hippogames

    hippogames

    Joined:
    Feb 5, 2015
    Posts:
    26
    Thanks! Seems I have no some kind of access to this project, and this is producing HTTP error. Anyway, I'll request all required perissions from my game publisher.
     
  6. hippogames

    hippogames

    Joined:
    Feb 5, 2015
    Posts:
    26
    And one more question. Can I add "Xiaomi Mi Game Center" from Build Settings instead of importing plugin? Because both they are producing conflicts. Are those plugins will be equal?
     
  7. unityjingyao

    unityjingyao

    Unity Technologies

    Joined:
    Feb 20, 2017
    Posts:
    104
    Hi @hippogames
    You might get a conflict in some versions of Unity if you add both "Xiaomi Mi Game Center" from Build Settings and Unity IAP plugin. This is a known issue and we'll fix it.
    "Xiaomi Mi Game Center" is different from Unity IAP plugin.
    Xiaomi requires that your game must have Xiaomi SDK integrated.
    "Xiaomi Mi Game Center" is used for a game that doesn't have IAP and it only has Xiaomi SDK.
    Unity IAP has already integrated "Xiaomi Mi Game Center"(or Xiaomi SDK).
    So if you have IAP in your game, please use Unity IAP.
     
  8. Klamore74

    Klamore74

    Joined:
    Jun 17, 2013
    Posts:
    23
    Hi,

    I try to integrate IAP for xiaomi but I have an error

    I fill up the "AppStoreSettings" create by "Asset/Create/App Store Settings" with all data and I try the class UnityChannelSample as descrive on google document "https://docs.google.com/document/d/1VjKatN5ZAn6xZ1KT_PIvgylmAKcXvKvf4jgJqi3OuuY/edit#" but I receive the following error, I'm missing somethings?

    Code (CSharp):
    1. Exception: JNI: Init'd AndroidJavaClass with null ptr!
    2. UnityEngine.AndroidJavaClass..ctor (IntPtr jclass) (at /Users/builduser/buildslave/unity/build/Runtime/Export/AndroidJavaImpl.cs:622)
    3. UnityEngine.AndroidJavaObject.get_JavaLangClass () (at /Users/builduser/buildslave/unity/build/Runtime/Export/AndroidJavaImpl.cs:600)
    4. UnityEngine.AndroidJavaObject.FindClass (System.String name) (at /Users/builduser/buildslave/unity/build/Runtime/Export/AndroidJavaImpl.cs:591)
    5. UnityEngine.AndroidJavaClass._AndroidJavaClass (System.String className) (at /Users/builduser/buildslave/unity/build/Runtime/Export/AndroidJavaImpl.cs:611)
    6. UnityEngine.AndroidJavaClass..ctor (System.String className) (at /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/AndroidJavaBindings.gen.cs:92)
    7. UnityEngine.Store.StoreService..cctor ()
    8. Rethrow as TypeInitializationException: An exception was thrown by the type initializer for UnityEngine.Store.StoreService
    9. UnityChannelSample.Start () (at Assets/UnityChannelSample.cs:47)
     
  9. wonderkid

    wonderkid

    Joined:
    Aug 20, 2015
    Posts:
    12
    Last edited: Jan 30, 2018
  10. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    1,614
    There are scripts available at that location that you can use. Did you have a specific question on the code implementation? Are you receiving an error?
     
  11. wonderkid

    wonderkid

    Joined:
    Aug 20, 2015
    Posts:
    12
    That scripts are my problem :D I just don't know how to add "Client-side initialization" part to my code. My IAP script same as this tutorial and works with Google Play.
     
  12. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    1,614
    Can you be more specific? The code is listed on the page, have you tried placing that code into your project? Step 2 goes in your Awake method, for example, and uses the code from Step 1.
     
  13. wonderkid

    wonderkid

    Joined:
    Aug 20, 2015
    Posts:
    12
    Yes, I tried. When I added them, I get lots of errors:

    - error CS0246: The type or namespace name `AppStoreSupport' could not be found. Are you missing an assembly reference?
    - You are trying to create a MonoBehaviour using the 'new' keyword. This is not allowed (code: SampleLoginListener loginListener = new SampleLoginListener()
    - Exception: JNI: Init'd AndroidJavaClass with null ptr!

    Also where should I call Buy function (controller.InitiatePurchase(product)? I can't access other class from base class.
     
  14. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    1,614
    Taking it one step at a time, let's fix the first error. Did you import the IAP asset described previously in the document?
     
  15. unityjingyao

    unityjingyao

    Unity Technologies

    Joined:
    Feb 20, 2017
    Posts:
    104
    Hi @wonderkid ,
    That tutorial doesn't have the implement of Xiaomi IAP.
    You can find a demo script in [Assets\Plugins\UnityPurchasing\script\IAPDemo.cs] and a demo scene in [Assets\Plugins\UnityPurchasing\scenes].
     
  16. wonderkid

    wonderkid

    Joined:
    Aug 20, 2015
    Posts:
    12
    @JeffDUnity3D Do you mean importing Unity IAP from Services? If so, yes.
    @unityjingyao Does IAPDemo.cs handles Xiaomi login and AppStoreSettings? I looked it and didn't find anything.

    I just want to know how to add Client-side initialization part to my IAP code. Copying these lines just throws errors.
     
  17. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    1,614
    Understood, we are continuing to research here. I too get errors, specifically when trying

    Code (CSharp):
    1. using AppStoreSupport;
     
  18. wonderkid

    wonderkid

    Joined:
    Aug 20, 2015
    Posts:
    12
    When I change it to "using AppStoresSupport;" error goes but I am not sure thats the solution. Also IAPDemo.cs doesn't call that.
     
  19. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    1,614
    The "using" syntax is specified in the documentation, see attached.
     

    Attached Files:

    wonderkid likes this.
  20. unityjingyao

    unityjingyao

    Unity Technologies

    Joined:
    Feb 20, 2017
    Posts:
    104
    Hi @wonderkid ,
    UnityIAP offers 2 ways to set up Xiaomi settings.

    1. Use App store settings.
    You can find the documentation on this page:
    https://docs.unity3d.com/Manual/UnityIAPXiaomi.html#AppStoreSettings
    Note: The AppStoreSettings Asset is only available in Unity 5.6+.

    2. Create an "AppInfo" manually.

    AppInfo unityChannelAppInfo = new AppInfo();
    unityChannelAppInfo.appId = "app id";
    unityChannelAppInfo.appKey = "app key";
    unityChannelAppInfo.clientId = "client id";
    unityChannelAppInfo.clientKey = "client key";
    unityChannelAppInfo.debug = false;

    You can find this snippet in IAPDemo.cs.

    I guess that you were using the first method without creating AppStoreSettings Asset file.
    I'm sorry that we don't make the second method clear in our Manual.
    I'll report it to the documentation team.
     
    Last edited: Feb 1, 2018
  21. wonderkid

    wonderkid

    Joined:
    Aug 20, 2015
    Posts:
    12
    @unityjingyao Yes, I'm using first method and created AppStoreSettings Asset file. I managed the call buy function but got error that highlighted. Also still couldn't fix Client-side errors.
     

    Attached Files:

  22. unityjingyao

    unityjingyao

    Unity Technologies

    Joined:
    Feb 20, 2017
    Posts:
    104
    Hi @wonderkid ,
    Did you call StoreService.Initialize() in Unity Editor?
    At present, StoreService only supports Android platform, since it's an Android module.
    Its methods will call some Android related APIs, so if you call it in Editor it will throw an exception.
    We have some codes to bypass calling it in IAPDemo.cs.

    Code (CSharp):
    1. m_IsUnityChannelSelected = Application.platform == RuntimePlatform.Android && module.androidStore == AndroidStore.XiaomiMiPay;
    2. ...
    3. bool needExternalLogin = m_IsUnityChannelSelected;
    4. if (!needExternalLogin)
    5. {
    6.     initializeUnityIap();
    7. }
    8. else
    9. {
    10.     ...
    11. }
    If you run this codes in Editor, m_IsUnityChannelSelected and needExternalLogin will be false. initializeUnityIap() will be called directly and StoreService.Initialize will be bypassed in Editor.
    I suggest you use same or similar logic to handle this exception.
     
  23. wonderkid

    wonderkid

    Joined:
    Aug 20, 2015
    Posts:
    12
    Ok, when I use your logic on editor it works fine. Test purchase works but when I build it to android(non-Xiaomi) device it crashes on the "StoreService.Initialize()" line. What should I do?
     
  24. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    1,614
    You do not want to have your Xiaomi code executing on a non-Xiaomi device, if I understand your comment correctly. You had it working previously on Android as you stated, correct?
     
  25. wonderkid

    wonderkid

    Joined:
    Aug 20, 2015
    Posts:
    12
    It works only on editor crashes on android. If I commented "StoreService.Initialize()" line on the code it doesn't crash. But I can't test purchase of course and I don't have Xiaomi device. So, how can I know it won't crash on Xiaomi device?
     
  26. unityjingyao

    unityjingyao

    Unity Technologies

    Joined:
    Feb 20, 2017
    Posts:
    104
    Hi @wonderkid
    What's the target of UnityIAP?
    If you choose other targets, m_IsUnityChannelSelected should be false, and initializeUnityIap() should be fired directly.
    StoreService.Initialize() wouldn't be called.
     
  27. wonderkid

    wonderkid

    Joined:
    Aug 20, 2015
    Posts:
    12
    Hi @unityjingyao
    Target is Xiaomi Mi Game Play. I have done all steps on the documentation, test mode is on. Also, this part of the doc say we can test purchase on non-Xiaomi Android device. But as I said it crashes on when "StoreService.Initialize()" called. Only thing I didn't do is importing Product catalog on the Xiaomi developer portal. Do I need to import it for testing?
     
    Last edited: Feb 5, 2018
  28. unityjingyao

    unityjingyao

    Unity Technologies

    Joined:
    Feb 20, 2017
    Posts:
    104
    Hi @wonderkid ,
    That's a step to configure your IAP products on Xiaomi Dev Portal. You don't need to do it currently.
    Cloud you please send me the crash report or call stack?
    Or you can also open a ticket and send me your apk file. Thank you.
    https://analytics.cloud.unity3d.com/support/
     
  29. wonderkid

    wonderkid

    Joined:
    Aug 20, 2015
    Posts:
    12
    Thank you @unityjingyao and @JeffDUnity3D. I finally managed to test IAP on my device. Workaround is putting random string in App ID and App Key on the AppStoreSettings.
     
  30. TinyTitanAndrew

    TinyTitanAndrew

    Joined:
    Sep 11, 2017
    Posts:
    9
    Hi @unityjingyao,

    I'm currently encountering an issue where when we launch our game, we basically run into issue #2, "Unavailable product" and "InitializeFailed: NoProductsAvailable". We've tried everything from a code perspective to resolve this issue, and we keep coming up with the same problem. Our Builder shows 21 products inside of it, which is accurate. However, in ADB it shows every product as "Unavailable". Any thoughts?
     
  31. unityjingyao

    unityjingyao

    Unity Technologies

    Joined:
    Feb 20, 2017
    Posts:
    104
    Hi @TinyTitanAndrew
    Did you configure your IAP products in IAP Catalog and export them to MiGameProductCatalog.prop as issue #2 suggests?
    This is a necessary step for Xiaomi IAP.
     
  32. TinyTitanAndrew

    TinyTitanAndrew

    Joined:
    Sep 11, 2017
    Posts:
    9
    Hey @unityjingyao

    We did configure our IAP Catalog and exported them to MiGameProductCatalog.prop, from what I can tell now, it looks like every time I go to build my project, something in the SDK is overwriting my MiGameProductCatalog.prop file with an empty version.

    So what I mean by this, is that I have my MiGameProductCatalog.prop file in "Assets/Plugins/Android/assets", if I open the file with Notepad++ or Visual Studio and then start my build, within a minute or two I will see a message pop up in the program saying "This file has been modified by another program. Reload file?", if I say "Yes" it will come back with nothing but the first line (the headers), if I say "No" the file will remain the same within that program only, and the game will continue to be built with the version with just the headers in it.
     
  33. unityjingyao

    unityjingyao

    Unity Technologies

    Joined:
    Feb 20, 2017
    Posts:
    104
    Hi @TinyTitanAndrew
    Thank you for your explanation.
    Which version of Unity IAP are you using? You can find the version at the first line of "Assets\Plugins\UnityPurchasing\Changelog.md" file.
    I'm using Unity IAP 1.17.0, but I couldn't reproduce this issue.
    I was opening MiGameProductCatalog.prop file when I built an apk, and I didn't get the modification popup.