Search Issue Tracker
By Design
By Design in 2023.2.X
Votes
0
Found in
2022.2.9f1
2023.1.0b5
2023.2.0a4
Issue ID
UUM-30598
Regression
Yes
AndroidJNI.FindClass() always returns IntPtr.Zero when called inside class destructor or finalizer
Reproduction steps:
1. Open the attached project "AndroidJNITests"
2. Build And Run on an Android device
3. Press the “Alloc DummyObject” button
4. Press “Collect GC to trigger DummyObject Finalizer”
5. See the returned output of AndroidJNI.FindClass()
Expected result: Returned value is non-zero
Actual result: Returned value is zero
Reproducible with: 2022.2.0a12, 2022.2.9f1, 2023.1.0b5, 2023.2.0a4
Not reproducible with: 2020.3.46f1, 2021.3.20f1, 2022.2.0a11
Reproducible with devices:
VLNQA00332, Samsung Galaxy XCover4 (SM-G390F), Android 9, CPU: Exynos 7 Quad 7570, GPU: Mali-T720
VLNQA00325, Samsung Galaxy Note10 (SM-N970F), Android 12, CPU: NOT FOUND, GPU: Mali-G76
VLNQA00318, Oneplus OnePlus 7 Pro (GM1913), Android 11, CPU: Snapdragon 855 SM8150, GPU: Adreno (TM) 640
VLNQA00231, Samsung Galaxy A5(2017) (SM-A520F), Android 8.0.0, CPU: Exynos 7 Octa 7880, GPU: Mali-T830
VLNQA00231, Huawei HUAWEI Mate 20 Pro (LYA-L29), Android 9, CPU: HiSilicon Kirin 980, GPU: Mali-G76
iPhone 13 Pro (iOS 15.6.1)
Reproducible on: Windows 10 Enterprise 21H2
Notes:
- AndroidJNI.FindClass() method in the object's destructor/finalizer always returns an IntPtr.Zero (note that the Java class exists).
It is expected that this method returns the Java class ID
- This works in any other context but in the object's destructor/finalizer
- This bug occurs on Release and Development build
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Project Auditor suggests to update package to a lower version than installed when the recommended package version is not the latest version
- Low performance when multiple meshes using BlendShape are rendered on screen
- TMP Dropdown visually corrupts or disappears when its own GameObject is assigned to "Caption Image" or "Placeholder" elements
- Usymtool tries to upload GameAssembly.pdb when it doesn't exist after building with Mono backend
- “NullReferenceException” error thrown in the Console when running HDRP Wizard “Fix All” in URP project after installing HDRP Package
Resolution Note:
AndroidJNI.FindClass can only be called from a thread that is attached to Java, otherwise it will return null. Call AndroidJNI.AttachCurrentThread to attach thread.
Resolution Note (2023.2.X):
AndroidJNI.FindClass can only be called from a thread that is attached to Java, otherwise it will return null. Call AndroidJNI.AttachCurrentThread to attach thread.