Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[Solved] [Android,2018.3.13] UnityPurchasing don't initialize after Application.Quit

Discussion in 'Unity IAP' started by MohHeader, Apr 21, 2019.

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

    spotavi

    Joined:
    Aug 30, 2014
    Posts:
    31
  2. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
  3. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Can you test with 2019.3? Granted it's an early release, but should allow you to test.
     
  4. spotavi

    spotavi

    Joined:
    Aug 30, 2014
    Posts:
    31
    Does not quit. But does alow the play services etc to work . Also when user kills the game from Android, prefs save has no issue.
     
  5. spotavi

    spotavi

    Joined:
    Aug 30, 2014
    Posts:
    31
    We have our game on 2018.x . Is there a chance it will get pushed to this too ?

    Moving to 2019 might break a lot of stuff for us
     
  6. CybIam

    CybIam

    Joined:
    Nov 6, 2016
    Posts:
    57
    I am searching for solution for a while now. And during tryouts I've heavily patched googleplay.aar classes. Long story short for every bind method I call unbind and for every registerReceiver method I call unregisterReceiver and log every state of UnityPlayerActivity and GooglePlayPurchasing yet anyhow when app quit I still get service leaked error message. Since my store logic implemented as singleton I've noticed that plugin instance is created only once, so as temporary solution I've patched GooglePlayPurchasing static method instance and remove check against null value. With a tester account it seems to work fine either with quit method or moving app to background. Meanwhile still looking for a better robust solution ...
     
  7. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    This is still happening when you test with Unity 2019.3?
     
  8. CybIam

    CybIam

    Joined:
    Nov 6, 2016
    Posts:
    57
    I am on 2018.4. Never tested with 2019
     
  9. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    That would be expected in that case, please see the previous mention of 2019. I was asking if anyone can confirm it's working in 2019.3 Alpha, if possible. Hopefully back ported soon.
     
  10. CybIam

    CybIam

    Joined:
    Nov 6, 2016
    Posts:
    57
    @JeffDUnity3D,
    hmm I must be misunderstood previous messages about 2019.
    I will test my app on Alpha
     
  11. CybIam

    CybIam

    Joined:
    Nov 6, 2016
    Posts:
    57
    I was able to install Unity Hub, Unity 2019.3a and AndroidPlayback for it.
    I was unable to open existing project or just to create a new one. Editor always crashed.

    ps
    Win7 64 Ult SP1
     
    spotavi likes this.
  12. UDN_7a2eceda-93d6-4468-b982-388651c336e0

    UDN_7a2eceda-93d6-4468-b982-388651c336e0

    Joined:
    Jul 25, 2016
    Posts:
    14
    When it is fixed, please note for us. I'm still waiting for it.
     
  13. pep_dj

    pep_dj

    Joined:
    Nov 7, 2014
    Posts:
    179
    Instead of using a native plugin, we can just use this line in order to run System.exit(0):
    Code (CSharp):
    1. new AndroidJavaClass("java.lang.System").CallStatic("exit", 0);
    I think the best (temporary) solution would be to execute such line of code at the very end when closing the game, so player prefs are saved, and everything is disposed. This is what I did:
    • I created an empty GameObject at the root of the hierarchy
    • I added to it the script you can find below
    • I modified script execution order in project settings so such script is executed after the others
    Player preferences seems to be saved in my case. Would be nice if anybody in this forum could try this and confirm it.

    This is the script:
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class IapApplicationQuitTempFix : MonoBehaviour {
    4.     private static IapApplicationQuitTempFix instance;
    5.  
    6.     void Awake() {
    7.         if (instance == null) {
    8.             instance = this;
    9.             DontDestroyOnLoad(gameObject);
    10.         } else if (instance != this) {
    11.             Destroy(gameObject);
    12.         }
    13.     }
    14.  
    15.     void OnDestroy() {
    16.         if (instance == this && Application.platform == RuntimePlatform.Android) {
    17.             new AndroidJavaClass("java.lang.System").CallStatic("exit", 0);
    18.         }
    19.     }
    20. }
    21.  
     
    Last edited: Jul 31, 2019
  14. vigoAtWork

    vigoAtWork

    Joined:
    Apr 25, 2016
    Posts:
    12
    It works, at least with a "stripped down" version, for (essentially) a single-scene app:

    Code (CSharp):
    1. public sealed class IapFinishFixer : MonoBehaviour {
    2.     void OnDestroy() {
    3.         if (Application.platform == RuntimePlatform.Android) {
    4.             new AndroidJavaClass("java.lang.System").CallStatic("exit", 0);
    5.         }
    6.     }
    7. }
    It's a pretty hacky workaround, of course, as this essentially interrupts Unity's broken cleanup routine at an arbitrary point of time, so the system can take over.


    Edit: the below is true for one of our games, but I can't reproduce it as a minimalistic testcase.

    For Unity 2018.4.5f1 at least, simply building with "mono" instead of "il2cpp" fixes the issue : the IntentReceivers registered by *.SharedUnityPlayerActivity are no longer leaked.

    Sadly, that doesn't really help, since "mono" doesn't support ARM64, and Google won't accept your app any longer, starting... tomorrow. Great.
     
    Last edited: Jul 31, 2019
    giggioz and pep_dj like this.
  15. ALL-CAPS

    ALL-CAPS

    Joined:
    Jun 23, 2014
    Posts:
    9
    Writing to confirm this approach also solved our problem.

    We're however experiencing problems if you quickly relaunch the app after Application.Quit(), but I suspect that's a whole other issue. If you wait 3-5 seconds, it works as expected.
     
    pep_dj likes this.
  16. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,875
    Fix will be available in 2018.4.6f1
     
  17. pep_dj

    pep_dj

    Joined:
    Nov 7, 2014
    Posts:
    179
    Great news! Will also be fixed in 2019.1?
     
  18. francismoy

    francismoy

    Joined:
    Jul 5, 2017
    Posts:
    46
    I mentioned in a previous comment that the error didn't occur in 2019.1, but I must correct myself now after testing in more devices. The fix I'm using and which seems to work (haven't tested PlayerPrefs though) is the one proposed by @Duke_Hwang . It still would be awesome if it was fixed on 2019.1...
     
  19. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,875
    Yes, the fix will come there as well, there's just a slight delay, I'll try to keep you posted
     
  20. CybIam

    CybIam

    Joined:
    Nov 6, 2016
    Posts:
    57
    I've tested my upcoming project with Alpha 11 and with IAP 1.22 it seems to work fine(at least with tester google account).
     
  21. Asse1

    Asse1

    Joined:
    Jan 9, 2013
    Posts:
    89
    Still getting the error with Unity 2019.2.0f1.

    08-02 16:45:41.948: E/ActivityThread(17839): Activity com.unity3d.player.UnityPlayerActivity has leaked IntentReceiver com.ironsource.sdk.controller.IronSourceWebView$13@7481769 that was originally registered here. Are you missing a call to unregisterReceiver()?
     
    nickeron and andreas_P like this.
  22. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Is this after calling Application.Quit? If so, then would likely be expected in the version of Unity that you are using (unfortunately)
     
  23. Asse1

    Asse1

    Joined:
    Jan 9, 2013
    Posts:
    89
    Yes, that happens after Application.Quit().

    I hoped it was fixed in the released version 2019.2 which says
    • Android: Fixed an issue where custom Android libraries would not be initialized after launching an app after previously exiting the app via Application.Quit. (1116123)
     
  24. wowipop

    wowipop

    Joined:
    Aug 12, 2014
    Posts:
    2
    nope it doesn't fix that
     
  25. wowipop

    wowipop

    Joined:
    Aug 12, 2014
    Posts:
    2
    confirmed works on Unity 2019.3.0a11
     
  26. rahulnaik9010

    rahulnaik9010

    Joined:
    Jan 2, 2019
    Posts:
    19
    Can you please tell the tentative release date for 2018.4.6f1 ?
     
  27. ThisGuise

    ThisGuise

    Joined:
    Oct 20, 2015
    Posts:
    9
    Releases usually happen around the 10th and 26th every month. So would expect this in about 4 days.
     
    rahulnaik9010 likes this.
  28. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,875
    Fixed in 2019.2.2f1 as well now
     
    xman800 likes this.
  29. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,875
    That's correct, if everything is fine, most likely 2018.4.6f1 will be released this week.
     
    xman800 likes this.
  30. almaz85

    almaz85

    Joined:
    May 12, 2019
    Posts:
    2
  31. Fronne

    Fronne

    Joined:
    Sep 25, 2014
    Posts:
    112
    From the LTS Release 2018.4.6f1 Release Notes:

    Android: Fixed Application.Quit not correctly quitting the application process, previously it would only destroy Unity runtime, keeping activity alive, that lead to incorrect application resume. (1171368, 1172044)

    Does this mean the problems with IAP are solved too?
     
  32. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,875
    Not sure which problem you're referring to, but if you were calling Application.Quit in your project, it should fix any service reinitialization now.
     
    Fronne likes this.
  33. rahulnaik9010

    rahulnaik9010

    Joined:
    Jan 2, 2019
    Posts:
    19
    Yaay...issue fixed..i checked it
     
    Fronne likes this.
  34. Fronne

    Fronne

    Joined:
    Sep 25, 2014
    Posts:
    112
    Hint: The title of this thread is [Android,2018.3.13] UnityPurchasing don't initialize after Application.Quit ;)
     
  35. Fronne

    Fronne

    Joined:
    Sep 25, 2014
    Posts:
    112
    Thnx! Time for some App Update()s...
     
    Last edited: Aug 10, 2019
  36. nickeron

    nickeron

    Joined:
    Jun 20, 2018
    Posts:
    3
  37. BlackBindy

    BlackBindy

    Joined:
    May 9, 2015
    Posts:
    4
    I just tested on 2018.4.6f1 and it seems working well.
    Thanks for your hard work :)
     
    DungDajHjep and Fronne like this.
Thread Status:
Not open for further replies.