Search Issue Tracker

Fixed in 2022.2.X

Fixed in 2020.3.X, 2021.3.X



Found in





Issue ID




[Android] Crash when using UnityPlayer(getApplicationContext(), this); on exported Andoid projects



Reproduction steps:
1. Create a new project
2. Change Target Platform to Android
3. Export project (Build Settings > check the "Export Project" checkbox > Export)
4. Open the exported project in Android Studio
5. Open unityLibrary/java/com.unity3d.player/
6. Change line 41 from "mUnityPlayer = new UnityPlayer(this, this);" to "UnityPlayer(getApplicationContext(), this);"
7. Click Run

Expected result: The app doesn't crash
Actual result: The app crashes and an error is printed in Logcat:
2022-04-14 10:36:35.775 2704-2755/com.DefaultCompany.UaalProj E/AndroidRuntime: FATAL EXCEPTION: UnityMain
Process: com.DefaultCompany.UaalProj, PID: 2704
java.lang.ClassCastException: cannot be cast to
at com.unity3d.player.UnityPlayer.isUaaLUseCase(Unknown Source:2)
at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
at com.unity3d.player.UnityPlayer.access$300(Unknown Source:0)
at com.unity3d.player.UnityPlayer$e$1.handleMessage(Unknown Source:95)
at android.os.Handler.dispatchMessage(
at android.os.Looper.loop(
at com.unity3d.player.UnityPlayer$ Source:20)

Reproducible with: 2019.4.35f1, 2019.4.38f1, 2020.3.33f1, 2021.2.19f1
Not reproducible with: 2019.4.34f1
Couldn't test with: 2022.1.0b16, 2022.2.0a10 (Getting compilation errors in Android Studio: "'UnityPlayer(, com.unity3d.player.IUnityPlayerLifecycleEvents)' in 'com.unity3d.player.UnityPlayer' cannot be applied to '(android.content.Context, com.unity3d.player.UnityPlayerActivity)'")

Reproducible on these devices:
VLNQA00331 - HUAWEI P20 lite (ANE-LX1), CPU: HiSilicon Kirin 659, GPU: Mali-T830, OS: 9
VLNQA00285 - Samsung Galaxy J4 Core (SM-J410F), CPU: Snapdragon 425 MSM8917, GPU: Adreno 308, OS: 8.1.0
VLNQA00122 - Samsung Galaxy S9 (SM-G960F), CPU: Exynos 9 Series 9810, GPU: Mali-G72, OS: 10.0.0
VLNQA00414 - Galaxy Note10+ 5G (SM-N976V), CPU: Snapdragon 855 SM8150, GPU: Adreno 640, OS: 9
VLNQA00321 - Xiaomi MI 9 (MI 9), CPU: Snapdragon 855 SM8150, GPU: Adreno 640, OS: 10.0.0

  1. Resolution Note (fix version 2022.2):

    Fixed in 2022.2.0a15

  2. Resolution Note (fix version 2021.3):

    Fixed in 2021.3.7f1

  3. Resolution Note (fix version 2020.3):

    Fixed in 2020.3.40f1

Comments (1)

  1. unity_495C755032C6BC769EE4

    Jul 06, 2024 18:43

    This issue is not resolved in unity 6 preview

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.