Search Unity

  1. All Pro and Enterprise subscribers: find helpful & inspiring creative, tech, and business know-how in the new Unity Success Hub. Sign in to stay up to date.
    Dismiss Notice
  2. Dismiss Notice

Bug Problem with Initialize Callbacks after Repacking

Discussion in 'Unity Distribution Portal (UDP)' started by kromenak, Oct 15, 2020.

  1. kromenak

    kromenak

    Joined:
    Feb 9, 2011
    Posts:
    259
    I've been testing my app using the UDP sandbox for a couple weeks. I call "
    StoreService.Initialize(this)", which triggers the UDP test account login page. If I log in with a valid test account, I get the OnInitialized callback. If I cancel/back out of the login page, I get OnInitializeFailed.

    After repacking my game for Huawei AppGallery, I tried testing out purchases in the repacked version. Unfortunately, I found that no IAP items were appearing in the game at all!

    After reviewing the logs between the unpacked vs. repacked versions of the game, I noticed that the initialization callbacks were not being called in the repacked version of the game. This is a problem b/c I use the OnInitialized callback to signal that "hey, IAP system works, it's OK to query products and make purchases"

    Is this expected behavior, or is there something buggy here? I attached the code I'm using for this (only init functions included; query and purchase functions omitted). Basically I see "UDP: Initialization succeeded" in the log for the unpacked version, but it never appears in the log for the repacked version.

    If it is expected that the initialize callbacks don't fire after repacking, I guess my only choice is to assume that initialization succeeded after calling StoreService.Initialize?
     

    Attached Files:

  2. kromenak

    kromenak

    Joined:
    Feb 9, 2011
    Posts:
    259
    As a quick follow up, if I call StoreService.Initialize on the repacked APK, assume it succeeds (because I do not get any callback), and then query the inventory, I get the OnQueryInventoryFailed failed callback with the message "Please initialize first".

    So, it would seem that after repacking, something is causing UDP to not initialize correctly, but I am not getting any failure callback with a failure reason.

    Looking at the Android logs, I see this during initialization:
     
    Last edited: Oct 15, 2020
  3. kromenak

    kromenak

    Joined:
    Feb 9, 2011
    Posts:
    259
    Ah, so by decompiling the APK, I could see that the code was hanging when it tried to create an AGConnectServiceConfig object. I then had a hunch that this object might somehow be getting stripped from the build.

    Sure enough, adding "-keep class com.huawei.agconnect.**{ *; }" to the proguard file fixed the issue.
     
    FlyingSquirrels likes this.
  4. studiolumiere_unity

    studiolumiere_unity

    Joined:
    Apr 24, 2020
    Posts:
    14
    [One Store] An incident similar to this problem occurred. I need a workaround.
     
  5. karyll

    karyll

    Joined:
    Apr 4, 2017
    Posts:
    38
    For Huawei Store:
    From my experience and understanding, this happens if you only repacked the game but did not submit to store.

    The sandbox version (pre-repack) IAP works because they are dummy IAP items. If you repack, then the apk will work with the real IAP items from the corresponding store. If the game is not submitted to the store, the IAP items are not defined in the store and then iap will fail to initialize.

    I have no experience with One store, but It could be the same. Samsung works similar to Huawei, IAP will only work on the repacked after you have submitted the game.
     
  6. kromenak

    kromenak

    Joined:
    Feb 9, 2011
    Posts:
    259
    In my case, IAP items were defined in UDP and had also been populated in Huawei. The problem was 100% a minify issue related to Proguard.

    One way to test this is to go to your Player Settings and disable Minify temporarily. If you repack a build and it works, then you'll need to add the appropriate lines to your Proguard file before it will work while minified. Determining the correct Proguard lines...is a bit of an adventure and varies from store to store, unfortunately.
     
    FlyingSquirrels likes this.
unityunity