dotnet / android

.NET for Android provides open-source bindings of the Android SDK for use with .NET managed languages such as C#
MIT License
1.92k stars 526 forks source link

`[libc] Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE)` after clearing cache and user data #8982

Open hansmbakker opened 3 months ago

hansmbakker commented 3 months ago

Android application type

.NET Android (net7.0-android, net8.0-android, etc.)

Affected platform version

VS 2022 17.11 Preview 1, .NET 8.0.300, MAUI 8.0.40

Description

This issue is split off from https://github.com/xamarin/xamarin-android/issues/8906 to discuss just the SIGABRT error that @grendello saw in the logs.

I found one way to reproduce the SIGABRT error, but please note that I do not know whether it is the only cause

Clearing user data and cache seems to delete binaries that the app needs to run when debugging from Visual Studio.

Note: If this is intended behavior, I would expect more guidance to developers that you're not supposed to clean user data / cache between debug runs.

Steps to Reproduce

  1. debug app on a device
  2. open the app info page of the app (in android, e.g. via long-press on the app icon)
  3. go to storage & data
  4. clear storage and clear cache
  5. debug the app on the device again --> SIGABRT

Did you find any workaround?

No response

Relevant log output

Start debugging Android application ...
Forwarding debugger port 8838
Detecting existing process
> am start -a "android.intent.action.MAIN" -c "android.intent.category.LAUNCHER" -n "com.anonymizeddomain.mobiledevelopment.showcase/crc64dc021777432a8733.MainActivity"
> Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.anonymizeddomain.mobiledevelopment.showcase/crc64dc021777432a8733.MainActivity }
[opment.showcas] Late-enabling -Xcheck:jni
[opment.showcas] Unknown bits set in runtime_flags: 0x8000
[LoadedApk] No resource references to update in package com.transsion.theme.icon
[opment.showcas] Starting a blocking GC Alloc
[opment.showcas] Starting a blocking GC Alloc
[debug-app-helper] Checking if libmonodroid was unpacked to /data/app/com.anonymizeddomain.mobiledevelopment.showcase-3RE_0nhlelIWMm-KTP4MFA==/lib/arm/libmonodroid.so
[debug-app-helper] Native libs extracted to /data/app/com.anonymizeddomain.mobiledevelopment.showcase-3RE_0nhlelIWMm-KTP4MFA==/lib/arm, assuming application/android:extractNativeLibs == true
[debug-app-helper] Setting up for DSO lookup in app data directories
[debug-app-helper] Added filesystem DSO lookup location: /data/app/com.anonymizeddomain.mobiledevelopment.showcase-3RE_0nhlelIWMm-KTP4MFA==/lib/arm
[debug-app-helper] Using runtime path: /data/app/com.anonymizeddomain.mobiledevelopment.showcase-3RE_0nhlelIWMm-KTP4MFA==/lib/arm
[debug-app-helper] checking directory: `/data/user/0/com.anonymizeddomain.mobiledevelopment.showcase/files/.__override__/lib`
[debug-app-helper] directory does not exist: `/data/user/0/com.anonymizeddomain.mobiledevelopment.showcase/files/.__override__/lib`
[debug-app-helper] Checking whether Mono runtime exists at: /data/user/0/com.anonymizeddomain.mobiledevelopment.showcase/files/.__override__/libmonosgen-2.0.so
[debug-app-helper] Checking whether Mono runtime exists at: /data/app/com.anonymizeddomain.mobiledevelopment.showcase-3RE_0nhlelIWMm-KTP4MFA==/lib/arm/libmonosgen-2.0.so
[debug-app-helper] Mono runtime found at: /data/app/com.anonymizeddomain.mobiledevelopment.showcase-3RE_0nhlelIWMm-KTP4MFA==/lib/arm/libmonosgen-2.0.so
[opment.showcas] Attempt to remove non-JNI local reference, dumping thread
[DOTNET] JNI_OnLoad: JNI_OnLoad in pal_jni.c
[DOTNET] GetOptionalClassGRef: optional class com/android/org/conscrypt/OpenSSLEngineImpl was not found
[monodroid] Creating public update directory: `/data/user/0/com.anonymizeddomain.mobiledevelopment.showcase/files/.__override__`
[opment.showcas] Attempt to remove non-JNI local reference, dumping thread
[monodroid-debug] Trying to initialize the debugger with options: --debugger-agent=transport=dt_socket,loglevel=0,address=127.0.0.1:8838,server=y,embedding=1,timeout=1716578797
[monodroid] No assemblies found in '/data/user/0/com.anonymizeddomain.mobiledevelopment.showcase/files/.__override__' or '<unavailable>'. Assuming this is part of Fast Deployment. Exiting...
[monodroid] Make sure that all entries in the APK directory named `assemblies/` are STORED (not compressed)
[monodroid] If Android Gradle Plugin's minification feature is enabled, it is likely all the entries in `assemblies/` are compressed
[libc] Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 9193 (opment.showcase), pid 9193 (opment.showcase)
jonpryor commented 3 months ago

The behavior you describe is By Design: When building apps in Debug configuration, Fast Deployment is used to "side load" assemblies into the application's files/.__override__ directory, avoiding the need to update, re-sign, and re-deploy the .apk whenever an assembly is changed.

Unfortunately, when you "(4) clear storage and clear cache" of the application, the files/.__override__ directory is also removed, meaning there are no assemblies:

[monodroid] No assemblies found in '/data/user/0/com.anonymizeddomain.mobiledevelopment.showcase/files/.__override__' or '<unavailable>'. Assuming this is part of Fast Deployment. Exiting...

If there are no assemblies, there is nothing to run.

If you truly need your app to be able to run after you "clear storage and clear cache", then you'll need to either build and run a Release configuration of your app, or set $(EmbedAssembliesIntoApk) to True. Please not that this will significantly impact your "inner dev loop", as deploy and launch times will increase.

grendello commented 3 months ago

This is indeed expected behavior, but I think we can do a bit better by checking whether the assemblies exist at deploy/run/debug time and re-deploy them if necessary. @dellis1972 what do you think?

dellis1972 commented 3 months ago

Hmm, the issue here is that the target _Upload is skipped because the assemblies have not changed and the apk didn't change. We might need to expand the "has the app be uninstalled" check to see if the cache is missing then force an upload.

grendello commented 3 months ago

@dellis1972 yeah, I think we probably need that check, even though it may slow things a bit :(