-
Notifications
You must be signed in to change notification settings - Fork 498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Android crash - no non-static method CustomUnityPlayer;.hidePreservedContent() #926
Comments
I just noticed that the 'workaround' caused a bug that Unity won't stop showing away the last paused frame, even on Android 13. This confirms that the I have updated the issue above. |
Using reflection seem to fix it. (tested on Android 7 and 13). // CustomUnityplayer.kt
import java.lang.reflect.Method
// Unity 2021.3.31+ and 2022.3.10+ try to call this private function, which throws an error on Android <= 8. https://github.com/juicycleff/flutter-unity-view-widget/issues/926
fun hidePreservedContent() {
Log.i(LOG_TAG, "hidePreservedContent")
// manually call the private function using reflection.
UnityPlayer::class.java.declaredMethods
.find { it.name == "hidePreservedContent" }
?.let {
it.isAccessible = true
it.invoke(this)
}
} https://github.com/timbotimbo/flutter-unity-view-widget/tree/hide_preserved_content |
Looks like this is 'fixed' in Unity starting with 2022.3.19. |
Description
This bug was first described in a larger issue #903, I'm just splitting it into a separate issue specific to this error.
On some Unity versions, android devices on Android 8 or lower will immediately crash when Unity is started.
(See more logs at the bottom)
Breaking change
I tested multiple Unity versions to find the exact version that breaks this.
The crash starts at Unity 2021.3.31 and 2022.3.10.
Both these versions have this entry in the changelog, that seems like the culprit.
Reproduction
Possible workaround
As noted in the original issue #903:
Adding the missing function signature to
CustomUntityPlayer.kt
in the plugin prevents the crash.However this causes the last paused frame to show when closing and reopening a page with the unitywidget.
Trying to call something like
super.hidePreservedContent
results inSo we might be able to call this private function using reflection.
Versions
❌ indicates a crash.
Unity:
2021.3.21 ✔
2021.3.28 ✔
2021.3.30 ✔
2021.3.31 ❌
2021.3.34 ❌
2021.3.35 ❌
2021.3.36 ❌
2022.3.0 ✔
2022.3.9 ✔
2022.3.10 ❌
2022.3.14 ❌
2022.3.15 ❌
2022.3.18 ❌
2022.3.19 ✔
2022.3.20 ✔
Android:
Android 6 ❌
Android 7.1.2 ❌
Android 8 ❌ (reported)
Android 9 ✔
Android 13 ✔
Devices:
This seems to happen on any device on Android <= 8.
Logs
Log Unity 2021.3.31, Android 6
Log Unity 2022.3.10, Android 7
The text was updated successfully, but these errors were encountered: