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

App crashes invoking method in package #9798

Open
corradolab opened this issue Feb 14, 2025 · 4 comments
Open

App crashes invoking method in package #9798

corradolab opened this issue Feb 14, 2025 · 4 comments
Assignees
Labels
Area: App Runtime Issues in `libmonodroid.so`.

Comments

@corradolab
Copy link

Android framework version

net9.0-android

Affected platform version

VS 2022 17.13.0

Description

Application uses an external library.
When the library is referenced from the main project eveythong works.
When the library is used as package a runtime error occurs

Steps to Reproduce

BarcodeDemo.zip

The attached demo project contains a BarcodeDemo app, which reference a ZXing.Mobile package. The package is served from the local directory LocalLibs.
The app has a single activity with a single button "Scan", which should bring up a scanning activity. The scanning activity use the device camera to read a barcode and decode it using ZXing.Net. The library is my porting to Net 9 of the no-longer mantained https://github.com/Redth/ZXing.Net.Mobile

If you run the app on an Android 5 or 6, pressing the "Scan" button throws an unhandled exception at row 60 of ZxingActivity.cs. Row 60 was recently added to handle edge-to-edge as required by Android 15.

Image

Did you find any workaround?

The app works correctly if:

  1. Executed on Android > 6, or
  2. Executed referencing directly the library from the main project instead of using a package

Working configuration

Image

Failing configuration

Image

Relevant log output

@corradolab corradolab added Area: App Runtime Issues in `libmonodroid.so`. needs-triage Issues that need to be assigned. labels Feb 14, 2025
@jpobst jpobst removed the needs-triage Issues that need to be assigned. label Feb 14, 2025
@jpobst
Copy link
Contributor

jpobst commented Feb 14, 2025

Can you post the logcat containing the crash information?

$ adb logcat -c
# Start the application, wait for it to crash, then wait 5s and:
$ adb logcat -d > log.txt

@jpobst jpobst added the need-info Issues that need more information from the author. label Feb 14, 2025
@corradolab
Copy link
Author

Hi Jonathan, below the requested log.

log.txt

Crash reported at line 581.
The app is the test app I submitted, running in debug from Visual Studio on an Android 6 emulator.

@dotnet-policy-service dotnet-policy-service bot added need-attention A xamarin-android contributor needs to review and removed need-info Issues that need more information from the author. labels Feb 17, 2025
@jpobst
Copy link
Contributor

jpobst commented Feb 18, 2025

02-17 12:07:07.390 15008 15008 F mono-rt : [ERROR] FATAL UNHANDLED EXCEPTION: Android.Util.AndroidRuntimeException: requestFeature() must be called before adding content
02-17 12:07:07.390 15008 15008 F mono-rt :    at Java.Interop.JniEnvironment.InstanceMethods.CallNonvirtualBooleanMethod(JniObjectReference instance, JniObjectReference type, JniMethodInfo method, JniArgumentValue* args) in /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/obj/Release/net8.0/JniEnvironment.g.cs:line 20464
02-17 12:07:07.390 15008 15008 F mono-rt :    at Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeNonvirtualBooleanMethod(String encodedMember, IJavaPeerable self, JniArgumentValue* parameters) in /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods_Invoke.cs:line 182
02-17 12:07:07.390 15008 15008 F mono-rt :    at Android.App.Activity.RequestWindowFeature(WindowFeatures featureId) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net9.0/android-35/mcw/Android.App.Activity.cs:line 6440
02-17 12:07:07.390 15008 15008 F mono-rt :    at ZXing.Mobile.ZxingActivity.OnCreate(Bundle bundle)
02-17 12:07:07.390 15008 15008 F mono-rt :    at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_(IntPtr jnienv, IntPtr native__this, IntPtr native_savedInstanceState) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net9.0/android-35/mcw/Android.App.Activity.cs:line 3196
02-17 12:07:07.390 15008 15008 F mono-rt :    at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPL_V(_JniMarshal_PPL_V callback, IntPtr jnienv, IntPtr klazz, IntPtr p0) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:line 121

This message:

requestFeature() must be called before adding content

sounds like you are not using the library properly and you need to ensure you are doing what it requires.

I would suggest searching for the error message for guidance, like:
https://stackoverflow.com/questions/4250149/requestfeature-must-be-called-before-adding-content

@jpobst jpobst removed the need-attention A xamarin-android contributor needs to review label Feb 18, 2025
@corradolab
Copy link
Author

I was aware of the "requestFeature() must be called before adding content" error.
To fix it, I moved RequestWindowFeature() before base.OnCreate().

Image

The fix works when the library is referenced as project, but it doesn't when the library is referenced as package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: App Runtime Issues in `libmonodroid.so`.
Projects
None yet
Development

No branches or pull requests

3 participants