Skip to content
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

Unable to activate instance of type Android.Util.SparseArray #4795

Closed
wuhuangjia opened this issue Jun 9, 2020 · 10 comments
Closed

Unable to activate instance of type Android.Util.SparseArray #4795

wuhuangjia opened this issue Jun 9, 2020 · 10 comments
Assignees
Labels
Area: App Runtime Issues in `libmonodroid.so`. regression

Comments

@wuhuangjia
Copy link

wuhuangjia commented Jun 9, 2020

Steps to Reproduce

  1. Use Xamarin.Forms V4.6.0.847, Xamarin.Android V10.3.1.4, Xamarin.GooglePlayServices.Vision V71.1702.2
  2. Build a QRCode Scan function, and scan
  3. when invoking ReceiveDetections, the event argument Detector.Detections DetectedItems will show error message "System.NotSupportedException: 'Unable to activate instance of type Android.Util.SparseArray`"
  4. Downgrade to Xamarin.Android to V10.2.xx, everything just works fine

VS bug #1140617

@brendanzagaeski
Copy link
Contributor

Cross-referencing note for the Xamarin team

There is a matching Developer Community item reported against Xamarin.Android 10.3.99.259 (d16-7) in Visual Studio 2019 version 16.7 Preview 2: https://developercommunity.visualstudio.com/content/problem/1071004/vs-1670-preview-2-sparcearray-notsupportedexceptio.html

@brendanzagaeski brendanzagaeski added this to the Under Consideration milestone Jun 10, 2020
@grendello grendello added the need-info Issues that need more information from the author. label Jun 10, 2020
@grendello
Copy link
Contributor

@wuhuangjia can you attach a simple project which triggers the problem for you? Thanks!

@wuhuangjia
Copy link
Author

@wuhuangjia can you attach a simple project which triggers the problem for you? Thanks!

ok, will try to make a sample, thanks a lot

@JimmyPun610
Copy link

@brendanzagaeski
Copy link
Contributor

Thanks for the note about the BarcodeScanner.XF sample app! I was able to reproduce the problem with that sample using the following steps:

  1. Fetch https://github.com/JimmyPun610/BarcodeScanner.XF, and checkout commit f9c7e12e94f9747ee9f6babdd215d8fdad385328.
  2. msbuild -restore -t:Install SampleApp\SampleApp.Android\SampleApp.Android.csproj
  3. Ensure the device is connected to Wi-Fi so the necessary module can be downloaded from Google.
  4. Tap the icon on the device to launch it.
  5. Tap START SCANNING ON CLICK in the app.
  6. Allow camera permissions when prompted.

Result:

Shortly after the the new view opens and the screen starts showing an image from the camera, the app encounters the unhandled exception:

System.NotSupportedException: Unable to activate instance of type Android.Util.SparseArray`1[E] from native handle 0x19 (key_handle 0x547ad98). ---> System.MissingMethodException: No constructor found for Android.Util.SparseArray`1::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership) ---> Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown.
    --- End of inner exception stack trace ---
   at Java.Interop.TypeManager.CreateProxy (System.Type type, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x000b5] in <43cddc76fe22432dbdbcea2397b6fcd7>:0
   at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x00111] in <43cddc76fe22432dbdbcea2397b6fcd7>:0
    --- End of inner exception stack trace ---
   at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x0017e] in <43cddc76fe22432dbdbcea2397b6fcd7>:0
   at Java.Lang.Object.GetObject (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type type) [0x00023] in <43cddc76fe22432dbdbcea2397b6fcd7>:0
   at Java.Lang.Object._GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00017] in <43cddc76fe22432dbdbcea2397b6fcd7>:0
   at Java.Lang.Object.GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00000] in <43cddc76fe22432dbdbcea2397b6fcd7>:0
   at Android.Gms.Vision.Detector+Detections.get_DetectedItems () [0x0001f] in <ef7fc227a7e44020bc62e1ade21588fd>:0
   at GoogleVisionBarCodeScanner.Droid.CameraPreview+DetectorProcessor.ReceiveDetections (Android.Gms.Vision.Detector+Detections detections) [0x00001] in <41132494451344bebfd47921df020acc>:0
   at Android.Gms.Vision.Detector+IProcessorInvoker.n_ReceiveDetections_Lcom_google_android_gms_vision_Detector_Detections_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_detections) [0x0000f] in <ef7fc227a7e44020bc62e1ade21588fd>:0
   at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.63(intptr,intptr,intptr)

Notes:

As JimmyPun610 found, this problem is fairly dependent on the particular set of assemblies and versions of assemblies used in an app, so in some cases, changing the target framework version of the app or updating NuGet packages might help avoid the issue, but it looks like this issue will need a fix in Xamarin.Android.

Cross-referencing note for the Xamarin team:

This issue might have same underlying cause as #4809.

Version information:

  • Xamarin.Android SDK 10.3.1.4 (d16-6/3a10de9)
    • Mono: 165f4b0
    • Java.Interop: xamarin/java.interop/d16-6@2cab35c

The issue also occurs with Visual Studio 2019 version 16.7 Preview 2:

  • Xamarin.Android SDK 10.3.99.259 (d16-7/feabf52)
    • Mono: 075c3f0
    • Java.Interop: xamarin/java.interop/d16-7@d6024f1

Testing device: arm64-v8a Android 9.0 Pie (API level 28) Google Pixel 3

@brendanzagaeski brendanzagaeski removed the need-info Issues that need more information from the author. label Jun 12, 2020
@brendanzagaeski
Copy link
Contributor

One other result I should mention to be thorough is that like
in #4809, I was only able to reproduce the exception for Android.Util.SparseArray`1[E] in the Debug configuration, which uses the debug version of libmonodroid.so and a different approach to typemaps than the Release configuration.

Although this additional result isn't especially helpful for the development scenario, it means there is a margin of safety for the final app publication scenario in the Release configuration.

@brendanzagaeski
Copy link
Contributor

Status update

A candidate fix for this issue has been added to the xamarin-android/d16-7 development branch in bb0f7eb. This change is not yet available in a published version. I will update this item again when a published version is available that includes the fix.

Fix verification

Fix verified. Using a development build that includes the fix, I retested the steps to reproduce from before. I verified that I could no longer reproduce the problem with the development version and confirmed that the problem reappeared if I switched back the current published versions of Xamarin.Android.

Development build tested: Xamarin.Android SDK version 11.0.0.1 (d16-7@17cc49e)

@diegosasw
Copy link

diegosasw commented Jul 14, 2020

This problem happens to me ONLY after using a splash screen and moving Xamarin initializations to Splash activity, but disappeared when setting Linker Properties Linking to Sdk Assemblies Only

@brendanzagaeski
Copy link
Contributor

Release status update

A new Preview version of Xamarin.Android has now been published that includes the fix for this item. The fix is not yet included in a Release version. I will update this again when a Release version is available that includes the fix.

Fix included in Xamarin.Android 11.0.0.3.

Fix included on Windows in Visual Studio 2019 version 16.7 Preview 4. To try the Preview version that includes the fix, check for the latest updates in Visual Studio Preview.

Fix included on macOS in Visual Studio 2019 for Mac version 8.7 Preview 4. To try the Preview version that includes the fix, check for the latest updates on the Preview updater channel.

@brendanzagaeski
Copy link
Contributor

Release status update

A new Release version of Xamarin.Android has now been published that includes the fix for this issue.

Fix included in Xamarin.Android SDK version 11.0.0.3.

Fix included on Windows in Visual Studio 2019 version 16.7. To get the new version that includes the fix, check for the latest updates or install the most recent release from https://visualstudio.microsoft.com/downloads/.

Fix included on macOS in Visual Studio 2019 for Mac version 8.7. To get the new version that includes the fix, check for the latest updates on the Stable updater channel.

@ghost ghost locked as resolved and limited conversation to collaborators Jun 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Area: App Runtime Issues in `libmonodroid.so`. regression
Projects
None yet
Development

No branches or pull requests

5 participants