Why does my android app instantly close when opening it?

677 views Asked by At

I'm using Xamarin in VS 2022 to create an android app. I'm main target is Android 10, but I'm targeting Android 8 for minimal and Android 11 for maximal. When i launch this app on an android emulator using Android 11, my application quits instantly without an error message.

Thank you for your help

EDIT :

In log i've found this error two times, is this because the permissions handler is different between Android 10 and Android 11 ?

android.runtime.JavaProxyThrowable: System.UnauthorizedAccessException: Access to the path '/storage/emulated/0/TBV/log/' is denied. ---> System.IO.IOException: Operation not permitted
   --- End of inner exception stack trace ---
  at System.IO.FileSystem.CreateDirectory (System.String fullPath) [0x00191] in <2615c4eaf97e4dd59aa46c819840e5a3>:0 
  at System.IO.Directory.CreateDirectory (System.String path) [0x0002c] in <2615c4eaf97e4dd59aa46c819840e5a3>:0 
  at TBV.TbvApp.writeError (System.Exception ex, System.String erreur) [0x0002a] in <6f35ba81f5be4c248d54abc0fc5cebb6>:0 
  at TBV.Login.VerifVersionAPK () [0x00306] in <6f35ba81f5be4c248d54abc0fc5cebb6>:0 
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) [0x00000] in <2615c4eaf97e4dd59aa46c819840e5a3>:0 
  at Android.App.SyncContext+<>c__DisplayClass2_0.<Post>b__0 () [0x00000] in <9bc33e0337de495f9ddcd5fdf4e98819>:0 
  at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <9bc33e0337de495f9ddcd5fdf4e98819>:0 
  at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00008] in <9bc33e0337de495f9ddcd5fdf4e98819>:0 
  at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.25(intptr,intptr)
    at mono.java.lang.RunnableImplementor.n_run(Native Method)
    at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:30)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:223)
    at android.app.ActivityThread.main(ActivityThread.java:7656)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
1

There are 1 answers

5
Mark Barton On

You haven't enabled the correct permissions in the Android Manifest. You need to enable WRITE_EXTERNAL_STORAGE, READ_EXTERNAL_STORAGE, and MANAGE_EXTERNAL_STORAGE.

HOWEVER, this may not work for Android version 11;

https://developer.android.com/about/versions/11/privacy/storage

This topic is covered in this SO question: Android 11 Scoped storage permissions