Search Unity

OnInitialized is NOT called on Android when app is launched again after installation

Discussion in 'Unity IAP' started by Kobald-Klaus, May 3, 2019.

  1. Kobald-Klaus

    Kobald-Klaus

    Joined:
    Jun 20, 2014
    Posts:
    127
    I have moved my project to 2019.1 from 2018.2.20 where everything worked.
    For 2019 I also updated IAP to 1.22.
    I'm basically using a modified version of IAPDemo.cs, which is attached to this thread.
    The first time the app is launched after installation OnInitialized is called which I can see in the log:
    "OnInitialized: PASS"
    Then all the products show up as intented.
    From the 2nd app launch on neighter the OnInitialized nor the OnInitializeFailed callbacks are called.
    - no exception just silence!
    Also, it does not help to delete files from the android/data folder.

    I have seen, that the new IAPdemo.cs is different a lot. But shouldn´t it be backwards compatible? It works on iOS without any problems.
    So is there anything that has to be changed?
     

    Attached Files:

  2. Kobald-Klaus

    Kobald-Klaus

    Joined:
    Jun 20, 2014
    Posts:
    127
    actually the manifest shows 2.0.6 - for whatever reason they are calling it 1.22 in the log.
    so I tried to downgrade to my working version 2.0.3 (which seems to be 1.21) and copied all code from my saved 2018.2 project.
    But the failure still exists: NO CALLBACKS are being triggered from the 2nd start of the app on!
    PLEASE HELP - I don´t wanna go back to 2018.2!
     
    Last edited: May 6, 2019
  3. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Please show the device logs as an attachment.
     
  4. Kobald-Klaus

    Kobald-Klaus

    Joined:
    Jun 20, 2014
    Posts:
    127
    I created 2 logs. The one named worked is from starting the app after installation. the "failed" is the 2nd launch.
    The difference is right at the beginning where on the 2nd launch "IAB helper created" is not there.
     

    Attached Files:

  5. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Where in your code are you calling InitializePurchasing? Are you sure you are completely exiting the app the first time, like restart your phone to confirm? Any Debug.Log statements would be expected to be in the logs, this should help with your troubleshooting. Also, what is the issue exactly?
     
  6. Kobald-Klaus

    Kobald-Klaus

    Joined:
    Jun 20, 2014
    Posts:
    127
    Your reply triggered something - I think I found the Bug:
    I am terminating my app with a button that is using Application.Quit(). It seems, that your IAP system is not shutting down correctly then. Because when I force quit the app by holding the home button and then swipe it away, it does work on next start. Yippeeeh!
    Anyhow I think you should look into this. Could it be you are running a 2nd process for that, which does not quit? The error is not happening on iOS.
    So I will remove the quit button on android for now.
     
  7. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    I have heard similar reports of Application.Quit not working as expected for IAP on Android. We are looking into it. Make sure you do not call anything else after Application.Quit.
     
  8. Kobald-Klaus

    Kobald-Klaus

    Joined:
    Jun 20, 2014
    Posts:
    127
    thx. I will remove the quit button for android.
     
  9. homenetgames-jacek

    homenetgames-jacek

    Joined:
    Jun 8, 2015
    Posts:
    15
    I've got the same problem. Recently I upgraded to 2018.4.0f1
    I've got: 2018.4.0f1, IAP plugin 1.22.0, Android 9 phone

    -> If I exit by button calling Application.Quit then on next launch neither OnInitialized or OnInitializeFailed is called. I don't call any IAP related code after Application.Quit. Some other deinitialization code might be called from various OnDestroy's.
    -> If I exit by swipe away then it works.
    -> If I exit by Application.Quit and then swipe away remaining application from tasks then it works too.
    -> I tried IAP 1.20.0 but the same happens.
    -> I tried to remove /Android/data/com.MyCompany.MyApp/files/Unity after Application.Quit but it still didn't worked on next launch.
    -> It works on old Android 4.4.4 phone, doesn't work on tester's phone with probably Android 8. It works on iOS.
    -> I tried 2018.3.14f1 but it doesn't works too.
    -> It was working on 2018.2.21f1 which I used before upgrade.

    For a now I removed exit button. Any chance for fixing Application.Quit behaviour ?

    I attached 2 logcats if it might be helpfull.
     

    Attached Files:

    Last edited: May 17, 2019
  10. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
  11. homenetgames-jacek

    homenetgames-jacek

    Joined:
    Jun 8, 2015
    Posts:
    15