0

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)
  • It must be crashing , check the logs and add crash report – Manohar Jan 11 '22 at 10:04
  • @Manohar i have edit my post – Florian Martinez Jan 11 '22 at 10:29
  • @FlorianMartinez The error caused by the permissions. Have you get the permissions correctly? And as i know, when we are denied for accessing to the path, we just could not access or could not read or write the file. What do you used for with the permissions make the android app instantly close without permissions when opening it? – Wendy Zang - MSFT Jan 12 '22 at 06:41

1 Answers1

0

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

Mark Barton
  • 847
  • 6
  • 15
  • i've already enabled WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE. I've also already have`requestLegacyExternalStorage` to `true` – Florian Martinez Jan 11 '22 at 10:56
  • Are you using android 11? Did you read the SO question I linked? – Mark Barton Jan 11 '22 at 11:14
  • Actually i'm using Android 11 on emulator but my app is targeting Android 10 max. But I want to target Android 11 and this crash happen when i target Android 11 without any changes – Florian Martinez Jan 11 '22 at 15:45
  • @FlorianMartinez Have you tried asking for these permissions in runtime? Like when opening the app? – stersym Jan 12 '22 at 07:55
  • Yes that could be the issue. Comment out your code that actually accesses the file storage and add in the permissions code. If the app does not crash and you have given the app permission, it should work next time it starts up – Mark Barton Jan 12 '22 at 08:29