Search Issue Tracker
Fixed in 2021.2.X
There is no way to have 2 instances of AndroidJavaObject with different references
1 AndroidJavaObject needs to be passed to multiple independent bodies of code -- each which have their own independent duration for holding onto the AndroidJavaObject.
One returns an AndroidJavaObject from an AndroidJavaProxy method then AndroidJavaProxy automatically calls Dispose() on that AndroidJavaObject outside the developer's visibility or control while other code may need to continue using that AndroidJavaObject.
public static AndroidJavaObject NewAndroidJavaObject(AndroidJavaObject androidJavaObject)
if (androidJavaObject == null)
AndroidJavaClass objectsClass = AndroidUtilities.objectsClass;
if (objectsClass == null)
AndroidUtilities.objectsClass = objectsClass = new AndroidJavaClass("java.util.Objects");
return objectsClass.CallStatic<AndroidJavaObject>("requireNonNull", androidJavaObject);
Related forum thread: https://forum.unity.com/threads/androidjavaobject-any-way-to-clone-for-separate-dispose-management.967609/
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
- The Editor becomes unresponsive and memory allocation errors are spammed in the Console when Generating Lightning
- Crash on BatchApplyPropertiesFromSourceAssetDB when opening a specific project
- Scene view Camera cannot be moved with WASD/QE keys when the Right Mouse Button is held down and the Mouse is not moved
- Crash when calling default interface method from virtual method with same name
- [Android] Unity does not include the ".aab" extension for an AppBundle when it is built via script with the buildPlayerOptions.locationPathName = "AppName.apk" and EditorUserBuildSettings.buildAppBundle = true