Search Unity

[Android 12] Android App Crash

Discussion in 'Android' started by vcamargo9, Sep 11, 2021.

  1. vcamargo9

    vcamargo9

    Joined:
    May 21, 2020
    Posts:
    2
    Hi,

    I'm not able to run an exported Unity game apk on Android 12, as I get the following crash :

    Code (CSharp):
    1. 2021-09-11 19:40:55.335 1252-1302/? E/AndroidRuntime: FATAL EXCEPTION: pool-13-thread-1
    2.     Process:  PID: 1252
    3.     java.lang.IllegalArgumentException: : Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
    4.     Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
    5.         at android.app.PendingIntent.checkFlags(PendingIntent.java:375)
    6.         at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:645)
    7.         at android.app.PendingIntent.getBroadcast(PendingIntent.java:632)
    8.         at androidx.work.impl.utils.ForceStopRunnable.getPendingIntent(ForceStopRunnable.java:174)
    9.         at androidx.work.impl.utils.ForceStopRunnable.isForceStopped(ForceStopRunnable.java:108)
    10.         at androidx.work.impl.utils.ForceStopRunnable.run(ForceStopRunnable.java:86)
    11.         at androidx.work.impl.utils.SerialExecutor$Task.run(SerialExecutor.java:75)
    12.         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
    13.         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
    14.         at java.lang.Thread.run(Thread.java:920)
    Is there a fix for this issue under development?

    Unity editor: 2020.3.18f1
     
  2. JuliusM

    JuliusM

    Unity Technologies

    Joined:
    Apr 17, 2013
    Posts:
    835
    I am not sure if this is a bug in Unity. From the log it's hard to know for certain, however I don't think we create any intents in core Unity. Does your project have plugins? Is the issue reproducible if you don't use them?
    If you think that this is a bug in Unity, feel free to submit a bug report https://unity3d.com/unity/qa/bug-reporting
     
  3. Plejader

    Plejader

    Joined:
    Oct 28, 2020
    Posts:
    1
    Is any solution to fix it?
     
  4. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,963
    Are you using any notification feature? Is this crash at launch?
     
  5. FunCrafter_

    FunCrafter_

    Joined:
    Dec 18, 2016
    Posts:
    4
    Hello,
    I get the same error on Android 12. I am using Unity Mobile Notifications in my Project.
    A User of our App has told us that they could not install the app from the Google Play Store. Right after the Download finished it just opens an Error Message saying that something went wrong. I tried using Googles Android Emulator tools and after trying to install the App on the Emulator it gave me the exact same Error.
     
  6. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,963
    FLAG_IMMUTABLE is a required flag when creating PendingIntent from Android 12.
    If you are using any of the plugins using native features (Alarms/Notifications etc which usually need Pending Intent), contact the publisher and get it fixed.

    If its mobile notifications package, check if there is any update for Android 12.
     
  7. Guambo1

    Guambo1

    Joined:
    Jun 24, 2018
    Posts:
    9
    Found the official release notes to fix this issue if anyone happens to stumble upon this thread:
    https://developers.google.com/admob/android/rel-notes

    Basically, in unity you need to edit the mainTemplate.gradle file to include the dependencies mentioned in the above link.

    1. In Unity, set the following checkbox to true to create a custom main gradle template file called mainTemplate.gradle: ProjectSettings>PlayerSettings>PublishingSettings>Build>Custom Main Gradle Template
    2. In mainTemplate.gradle go to the dependencies section and change it to this:

    Code (CSharp):
    1. dependencies {
    2.   implementation 'com.google.android.gms:play-services-ads:20.4.0'
    3.  
    4.   // For apps targeting Android 12, add WorkManager dependency.
    5.   constraints {
    6.     implementation('androidx.work:work-runtime:2.7.0') {
    7.       because '''androidx.work:work-runtime:2.1.0 pulled from
    8.      play-services-ads has a bug using PendingIntent without
    9.      FLAG_IMMUTABLE or FLAG_MUTABLE and will fail in Apps
    10.      targeting S+.'''
    11.     }
    12.   }
    13. }
    Found this out looking through this forum here: https://groups.google.com/g/google-admob-ads-sdk/c/uCQkZcqOVtE
     
    pojinlee and dior_chris like this.
  8. dior_chris

    dior_chris

    Joined:
    Apr 8, 2020
    Posts:
    4
    My Unity game crashes a lot on samsung galaxy S21.
     
    Last edited: Jan 29, 2022
  9. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,963
    Is it a launch crash?
     
  10. dior_chris

    dior_chris

    Joined:
    Apr 8, 2020
    Posts:
    4
    Dear,
    NOT crash on launch, issue happen when the user interacts with the game.
    This is the Logs I collected from those crashes:

    Report (Android 12 SDK 31, Device: Samsung Galaxy S21 FE)
    Code (CSharp):
    1. "---------------------Exception Error-------------------
    2. UnityEngine.WillRenderCanvases:Invoke()
    3. "
     
    Last edited: Jan 29, 2022
  11. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,900
    Please see this thread - https://forum.unity.com/threads/android-11-arm64-native-heap-allocator-issues.1047170/
     
    dior_chris likes this.
  12. dior_chris

    dior_chris

    Joined:
    Apr 8, 2020
    Posts:
    4
    Last edited: Jan 29, 2022
  13. youloftunityAdsLXY

    youloftunityAdsLXY

    Joined:
    Mar 30, 2022
    Posts:
    1
    My Unity game crashes a lot on my Samsung Android 12 phone. It is a launch crash.
     
  14. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,963
    You need to share complete logcat log to see what could be the issue. If its related to exported flag issue, you may need to pass me an empty apk or merged android manifest file to look into the source of the issue.
     
  15. NahuelLelouche

    NahuelLelouche

    Joined:
    Oct 19, 2021
    Posts:
    10

    Hi there!!
    Im ussing the UTNotifications Plugin, and im having thiss same issue... Any hints on how to fix this? Sadly i cant update the plugin version, nor unity version, our game is pretty big and i need a hotfix fast.

    Any hints on this would be really appreciated!
    Thanks in advance!
     
  16. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,963
    I'm not aware of the plugin but if its open source available on git, can help you out. It needs a change at the code level to accommodate the fix.
     
    Last edited: Apr 8, 2022