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

Hello ,

So the issue goes like that.
On Android start an application built with Unity 2018.3.13 and initialize the Purchasing as follow

UnityPurchasing.Initialize(this, builder);

it would work just normally and the OnInitialized method would be called normally

void OnInitialized(IStoreController controller, IExtensionProvider extensions)

now Quit the app using Application.Quit or natively through Android Java code as follow :

//Author @digitalmoka
using (AndroidJavaClass javaClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
using (AndroidJavaObject javaActivity = javaClass.GetStatic<AndroidJavaObject>("currentActivity"))
{
            javaActivity.Call<bool>("moveTaskToBack", true);
            javaActivity.Call("finish");
}

Start app again, and neither OnInitialized nor OnInitializeFailed, will be called.

To make it work again as normal, kill the app ( from the Android Apps Menu ), then start the app and it would just work normal again.

through the logs ( adb logcat ) I don’t see anything unusual !

IAP version : 1.22.0

Thanks

2 Likes

@digitalmoka had the same issue, but was solved - as he stated - through using the java code listed before.
he is the original poster of that code BTW.

1 Like

I had the same issue too with 2018.3.12 and with 2018.3.13. It runs once without problems but when you exit and restart the App, IAP is not initialized. No problems with 2018.3.11 and before…

The fix from digitalmoka worked for me but not for everone…

See thread 1 (last posts) for more information about this subject…
See thread 2 for Error: called non-existent method System.Boolean UnityEngine.VR.VRSettings::get_enabled…
See thread 3 for not working solution (in my case)…

The API Updater doesn't run automaticly with 2019.1.0, I have to trigger it myself with some deprecated code. I followed all steps to delete and import the folders several times but I was NOT able to get IAP running, I get the thread 2 Error all the time...

I’m using Easy Mobile Pro for Ads and IAP, everything works fine with 2018.3.11 and before. I noticed (on iOS) when a restore event was triggered, a purchase completed event is triggered after the restore event too wich triggers an Error. Android doesn’t need to Restore so restore is disabled on Android…

I solved this issue with a simple bool (canPurchase) to disable purchasing after a restore event and than IAP works without a problem, I just tell this to be complete…

Upgrading a project with IAP to a new Unity version should be simple and should always work, we depend on good functionallity for Ads and IAP, that should never cause so many problems, just my $0,02…

Cheers!
Franco Palmieri - Fronne

2 Likes

this one worked for me, as it don’t quit the app it just send it back to the background.
I think this is a very good temp solution, until we got a fix

Thanks @toberr

1 Like

Thanks @Fronne for the follow-up, hope we have a fix soon.

1 Like

We are looking into this.

1 Like

We’ve been able to reproduce the problem.

A temporary solution would be to call

System.Diagnostics.Process.GetCurrentProcess().Kill();

Before

Application.Quit();

Whereby

void OnInitialized(IStoreController controller, IExtensionProvider extensions)

Will trigger when you reboot the app.

Be sure to test before publishing. Hopefully, we can get a fix deployed in the next release.

2 Likes

This doesn’t work, the App doesn’t Quit and I had a crash on startutp after a new install…

Managed Stack Trace:

System.Diagnostics.Process.GetProcessHandle (System.Int32 access, System.Boolean throwIfExited) (at <00000000000000000000000000000000>:0)
System.Diagnostics.Process.Kill () (at <00000000000000000000000000000000>:0)
SettingsManager+d__30.MoveNext () (at <00000000000000000000000000000000>:0)
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at <00000000000000000000000000000000>:0)

Before I Quit, I run a Coroutine to save some Data to my DataBase, perhaps the Coroutine is Killed before it’s finished, causing a crash…

Cheers!
Franco Palmieri - Fronne

Perhaps - you could always create a callback function for when the database has finished - you can then process your Application.Quit(); ?

This works perfect with Mono…

    IEnumerator QuitFamory ()
    {
        yield return new WaitForSeconds (0.25f);
        settingsPanel.GetComponent<Animation>().Play ("ClosePanel");
        while (settingsPanel.GetComponent<Animation>().isPlaying) {
            yield return false;
        }
 
       // More Irrelevant Code...
 
        yield return WebManager.instance.AddInteger ("_Stats", "totalPlayTime", Fronne.sessionTime, Fronne.device);

        #if UNITY_ANDROID && !UNITY_EDITOR
        Invoke ("QuitAndroid", 0.25f); // Kill and Quit outside this Coroutine for Android...
        #else
        Application.Quit ();
        #endif
    }
 
    void QuitAndroid ()
    {
        // Unity Fix -> https://discussions.unity.com/t/740418/7
        System.Diagnostics.Process.GetCurrentProcess().Kill();
        Application.Quit ();
    }

…but with IL2CPP it results in a crash:

Managed Stack Trace:

System.Diagnostics.Process.GetProcessHandle (System.Int32 access, System.Boolean throwIfExited) (at <00000000000000000000000000000000>:0)
System.Diagnostics.Process.Kill () (at <00000000000000000000000000000000>:0)
SettingsManager.QuitAndroid () (at <00000000000000000000000000000000>:0)

System.Diagnostics.Process.GetCurrentProcess().Kill(); and Application.Quit(); are placed outside the Coroutine, because I think the Coroutine is Killed before or during Apllication.Quit(); is executed (Stack Trace Previous Post)…

Mono is not a durable option, [read the details here](https://android-developers.googleblog.com/2019/01/get-your-apps-ready-for-64-bit.html)...

Unity 2018.4.0f1
Cheers!
Franco Palmieri - Fronne

i have the same problem, with unity 2018.3.13 and 2019.1.2
The only thing for me works is killing the process from java overriding the main activity with a extension of unityplayeractivity and onDestroy of the activity put this

protected void onDestroy(){
  super.onDestroy();
  android.os.Process.killProcess(android.os.Process.myPid());
}

now unity close and java call this an close the process before it shows the leaking serviceconnection and we i start the game again the iap and google play games is working.

1 Like

We just tried a build with the new Unity version (2018.4.1f1) and the problem seems to still be there. Any new timeframe on a fix for this issue?

No timeframe yet. You would be advised to try the mentioned workarounds in the meantime.

I solved it by making a native plugin( .aar ) which just executes exit(0) in Java.
It works pretty well but I’m just worried that Playerpref wont work out since it saves user data when Application.Quit is executed.

http://lancekun.com/blog/wp-content/uploads/2019/05/quit_helper.zip
After you extract this zip file, just locate aar file into Assets/Plugins/Android/
then use below code instead using Application.Quit()

public static void Quit()
{
    AndroidJavaClass ajc = new AndroidJavaClass("com.lancekun.quit_helper.AN_QuitHelper");
    AndroidJavaObject UnityInstance = ajc.CallStatic<AndroidJavaObject>("Instance");
    UnityInstance.Call("AN_Exit");
}

I tested this solution in below build environment.
Unity3d 2018.3.14f / Android Gradle / IL2CPP ( all architectures )
also tested on devices below
Samsung Galaxy S4, 5, 7, Note 5, 9

I wrote the article regards this issue, but sadly it’s written in Korean

@MohHeader I hope this solution can help your problem.

12 Likes

I have the same problem. ADB displays message: ā€œScripting proxy object was destroyed, because Unity player was unloadedā€. How to fix?

Unfortunately, there’s no official fix as of yet. However, Duke_Hwang appears to have found a temporary solution.

If Korean isn’t your native language - open the link in Chrome right click > translate to English.

Wow, that bug is really annoying and it’s known for two month already…

Could we please get an update about the current process on Unitys’ side?

2 Likes

We will try to get this into the next release, no ETA at this time however.

1 Like

Wait whattttt??? I’m having this issue, it took me a whole day to find out it was Unity’s bug.
And I cant use
ā€œSystem.Diagnostics.Process.GetCurrentProcess().Kill()ā€
Throwing this Exception:

System.ComponentModel.Win32Exception (0x80004005): Success
06-14 20:58:45.173 15192 15234 E Unity : at System.Diagnostics.Process.GetProcessHandle (System.Int32 access, System.Boolean throwIfExited) [0x00000] in <00000000000000000000000000000000>:0
06-14 20:58:45.173 15192 15234 E Unity : at System.Diagnostics.Process.Kill () [0x00000] in <00000000000000000000000000000000>:0
06-14 20:58:45.173 15192 15234 E Unity : at Exit.Quit () [0x00000] in <00000000000000000000000000000000>:0
06-14 20:58:45.173 15192 15234 E Unity : at UnityEngine.Events.UnityAction.Invoke () [0x00000] in <00000000000000000000000000000000>:0
06-14 20:58:45.173 15192 15234 E Unity : at UnityEngine.Events.UnityEvent.Invoke () [0x00000] in <00000000000000000000000000000000>:0
06-14 20:58:45.173 15192 15234 E Unity : at UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1].Invoke (T1 handler, UnityEngine.EventSystems.BaseEventData eventData) [0x00000] in <00000000000000000000000000000000>:0
06-14 20:58:45.173 15192 15234 E Unity : at UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) [0x00000] in <00000000000000000000000000000000>:0
06-14 20:58:45.173 15192 15234 E Unity : at UnityEngine.E

4647292--436378--upload_2019-6-14_21-16-18.png

Great thanks, worked for us!