Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Android: targeting API level 31 makes the game freeze on Android 12

Discussion in 'Android' started by lenchez-mrg, Feb 9, 2022.

  1. lenchez-mrg

    lenchez-mrg

    Joined:
    Dec 13, 2018
    Posts:
    5
    I'm facing a weird issue with the Android Player.

    When the game is built for Android with target API Level 31 it freezes on devices running Android 12 (right after the splash screen).

    You can reproduce the problem even with a minimal project (like the one attached):

    1. Make sure you have Android SDK version 31 and Build Tools version 31 installed.
    2. Open the project.
    3. Make sure Target API Level is set to "API Level 31" in Android Player settings.
    4. Build the project for Android.
    5. Install the resulting APK to a device running Android 12 and launch it.

    Expected behaviour:
    - After the splash screen, the SampleScene is seen (a default skybox with a text overlay saying "The game works!").
    - In logcat , the output of LifecycleLogger component is seen, saying: "Awake", then "Start", then "Update 1", "Update 2" and so on.

    Actual behavior:
    - Splash screen never disappears and the game looks like an unresponsive grey rectangle.
    - In logcat, only "Awake" message is seen, meaning Start() and Update() methods never get called.

    Reproduced in Unity 2018.4.36f1, on Android 12 devices when building with Target API Level 31.
    Not reproduced in Unity 2019.4.35f1, Unity 2021.2.7f1.
    Not reproduced on devices running Android 11 or below.
    Not reproduced when building with Target API Level 30 or below.

    P.S.:
    Targeting API Level 31 is currently required by 3rd-party libraries and soon will be required by Google Play, which makes this problem a pressing matter.
    Upgrading to a newer version of Unity might seem the obvious thing to do. But it's nearly impossible for huge and mature projects we currently support. So a fix or a workaround that allows us to stay on Unity 2018 will be much appreciated.
     

    Attached Files:

    FamishedMammal likes this.
  2. dma11

    dma11

    Joined:
    Feb 7, 2021
    Posts:
    2
    Any solutions? We have the same issue here in the project. Upgrade unity is not an option for us either. Thanks
     
  3. jon_reid

    jon_reid

    Joined:
    Nov 29, 2013
    Posts:
    13
    If you've just stumbled on this post like I have after trying to update some older builds, you can try a solution that I have found that seems to work.

    On awake, try calling Permission.RequestUserPermission() with a permission that ISNT declared in your androidManifest file. This will immediately return that the permission is denied on awake and allow the game to continue running. I think whats happening is that Unity isnt pushed into the foreground correctly by the OS, but the permission check allows it to regain focus and continue running. I've tried this in builds from Unity 2018.4 LTS and Unity 2019.2 and both work fine and run when targeting android 31.

    Hope that helps!
     
  4. lidebin

    lidebin

    Joined:
    Aug 12, 2015
    Posts:
    5
    It happens to me in Unity 2019.1.9f1
     
  5. lidebin

    lidebin

    Joined:
    Aug 12, 2015
    Posts:
    5
    I have tried but can't work in Unity 2019.1.9f1
     
  6. lidebin

    lidebin

    Joined:
    Aug 12, 2015
    Posts:
    5
    Any official help?
     
  7. dev-alban

    dev-alban

    Joined:
    Jun 16, 2013
    Posts:
    9
    I have the exact same issue and the Permission.RequestUserPermission() workaround didn't work for me.
     
  8. lidebin

    lidebin

    Joined:
    Aug 12, 2015
    Posts:
    5
    me too
     
  9. tatsunog

    tatsunog

    Joined:
    Apr 15, 2020
    Posts:
    7
    Me too.
    Any official help?
     
  10. firedragon9511

    firedragon9511

    Joined:
    Nov 24, 2017
    Posts:
    13
    Any help? This is happening to me too. This is an emergency, in a few days GooglePlay will require API 31 and I need to update the ads because GooglePlay has created a new ad rule. Unity 2019.2.8f1.
     
    FamishedMammal likes this.
  11. wygsqsj

    wygsqsj

    Joined:
    Mar 3, 2022
    Posts:
    3
    Player Settings--->Other Settings-->Write Permission-->External(SDCard)
     
  12. wygsqsj

    wygsqsj

    Joined:
    Mar 3, 2022
    Posts:
    3
    The code setting has no effect, but I can open it after I enable the permission in Player Settings--->Other Settings-->Write Permission-->External(SDCard), thank you for your idea
     
  13. wygsqsj

    wygsqsj

    Joined:
    Mar 3, 2022
    Posts:
    3
    Note: Do not disable the permission request pop-up window of Unity in the exported Android project:
    Code (CSharp):
    1.         <meta-data
    2.             android:name="unityplayer.SkipPermissionsDialog"
    3.             android:value="false" />
     
  14. lidebin

    lidebin

    Joined:
    Aug 12, 2015
    Posts:
    5
    It works,Thank you!But I can't enable the permission request pop-up window because the platform will reject my apk...
     
  15. Frolky

    Frolky

    Joined:
    Feb 17, 2017
    Posts:
    8
    I have the same problem. Is there a working solution?
     
  16. okbeng

    okbeng

    Joined:
    Aug 4, 2020
    Posts:
    1
    I have the same problem, is there any official explanation?
     
  17. hishy7

    hishy7

    Joined:
    Aug 25, 2022
    Posts:
    2
    I have this problem too,Any solution? my unity version is 2017.4.27
     
  18. foolBoy

    foolBoy

    Joined:
    Mar 15, 2014
    Posts:
    2
    i try to call user permission dialog, if i did not click the "allow" or click refuse ,the game can be resume.
    but,if i click allow, restart game is still freeze.
    my game is builded with 2018.4.x, any useful solution?
     
  19. RaffaeleT

    RaffaeleT

    Joined:
    May 12, 2017
    Posts:
    2
    Same problem for me, Unity 2019.2.21f1
     
  20. Jackie0212

    Jackie0212

    Joined:
    Mar 6, 2014
    Posts:
    2
    Same problem for me, Unity 2018.4.36f1,Anyone solved the problem?
     
  21. Wux1e

    Wux1e

    Joined:
    Aug 11, 2022
    Posts:
    1
    Thank you veeeeeeeeeeeeeeeeery much , i do this ,the problem was solved.My Unity is 2018.4.10
     
    elkhattabi likes this.
  22. elkhattabi

    elkhattabi

    Joined:
    Aug 26, 2022
    Posts:
    1
    can you tell me how you did it ? i have the same problem
     
  23. JoJoJoX

    JoJoJoX

    Joined:
    Jun 23, 2022
    Posts:
    51
    We have the same issue.
    We use the `UnityWebRequest` in coroutine method, but it will never change status to `done`!
    When it will work? We find that it works well again if we granted the device `phone permissions`!
    You can try it~
    Our solution is upgrading Unity to v2021 LTS(which works well with no `phone permissions` granted) before deadline.
    Tired!
    One more thing, permission `READ_PHONE_STATE` is what we declaired in `AndroidManifest.xml`
     
    Last edited: Sep 20, 2022
  24. Mingmmmm

    Mingmmmm

    Joined:
    Sep 28, 2019
    Posts:
    7
    Unity 2018.4.7f1 LTS
    PlayerSettings -> OtherSettings -> Mute OtherAudioSources check
    This worked for me
     
    hgvt, xman800, sergioabril and 8 others like this.
  25. cradiff

    cradiff

    Joined:
    Feb 7, 2015
    Posts:
    65
    WOW, it's amazing work for my project 2019.2.21. Thanks a lot
     
    IMEdada and lumidia like this.
  26. berteodosio

    berteodosio

    Joined:
    Aug 11, 2018
    Posts:
    1
    I can confirm this solution worked for me (Unity 2018.4.36f1).

    @jon_reid it would be good if you could share with us how did you find this solution :). Was it any kind of log that led you to attempt to request a permission? Was it something else?
     
    zhimahoo233 likes this.
  27. n82khan

    n82khan

    Joined:
    Jun 22, 2021
    Posts:
    1
    I built game in unity 2020.3.16f1 and exported it to Android studio. And in Android studio, I made the needed change of 'android:export=true'. APK was successfully built, installed on my android 12 mobile, but it's not opening. The game is not opening. Name of the game is Lipsy. Error says, "failed to start several times".

    This is the video link of an error:
    https://m.youtube.com/shorts/dHOYS9Lfazc?feature=share
     
    Last edited: Oct 22, 2022
  28. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,640
    Check the logcat https://docs.unity3d.com/Packages/com.unity.mobile.android-logcat@0.1/manual/index.html for errors
     
  29. Kadir-

    Kadir-

    Joined:
    Mar 24, 2020
    Posts:
    14
    Anybody found a solution?
     
  30. tarasSh91

    tarasSh91

    Joined:
    Jan 27, 2019
    Posts:
    6
  31. lc0008

    lc0008

    Joined:
    Jun 15, 2020
    Posts:
    7
    Thank you! It work for me
     
  32. loap02

    loap02

    Joined:
    Dec 10, 2017
    Posts:
    2
    Pode explicar como fazer isso?
     
  33. loap02

    loap02

    Joined:
    Dec 10, 2017
    Posts:
    2
    Pode explicar como fazer ?
     
  34. ANTONBORODA

    ANTONBORODA

    Joined:
    Nov 16, 2017
    Posts:
    46
    Any updates on how to fix this? The "permission" fix doesn't seem to work just as External SD card one
     
  35. ANTONBORODA

    ANTONBORODA

    Joined:
    Nov 16, 2017
    Posts:
    46
    So, I'm replying to myself. After a lot of poking, the "permission" fix seems to be working, however, you can't call the C# unity method, this doesn't work. You HAVE to call native ActivityCompat.requestPermissions() in java with undisclosed permission from AndroidManifest (i.e. CALL_PHONE).
     
  36. zhimahoo233

    zhimahoo233

    Joined:
    Dec 5, 2022
    Posts:
    1

    Thank you very much.

    works for me.
    Version: 2018.4.36f1
     
    IMEdada likes this.
  37. IMEdada

    IMEdada

    Joined:
    Nov 10, 2022
    Posts:
    8
    Holy Jesus, work in 2018.4.7
     
  38. animusz_

    animusz_

    Joined:
    Nov 21, 2020
    Posts:
    1
    WOW... my master. :eek:
     
  39. allenwp

    allenwp

    Joined:
    Sep 4, 2013
    Posts:
    46
    :D:D:D Thanks for sharing this! My project uses Unity 2017.4.40f1 and I get a black screen at launch on newer versions of Android OS when I build with API level 31, 32, or 33. By simply checking off "Mute Other Audio Sources", the problem is fixed.

    Now my players no longer listen to their own music while playing the game, but it's a great stop-gap solution until we eventually upgrade our Unity version, which will be a huge effort involving lots of testing on multiple platforms.

    Thanks to everyone in this thread for sharing their experiences!
     
  40. MateenSheikh7

    MateenSheikh7

    Joined:
    Nov 16, 2020
    Posts:
    1
    Thank you for this! It works
     
  41. sergioabril

    sergioabril

    Joined:
    Jan 11, 2016
    Posts:
    33
    This just saved me. It works. Unity 2018.4 trying to build for Android SDK 33
     
  42. xman800

    xman800

    Joined:
    Feb 27, 2017
    Posts:
    25
    Wow. I don't know how in the world you discovered this obscure workaround to this fatal issue, but it seems to do the trick (Unity 2018.4.36f1). Thank you!