Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Android 11 QDir::mkDir() does not always work



  • My app generates a folder on "/storage/emulated/0/Android/data" following the common rules of "<country code>.<company>.<app name>". Upto including Android 10 this worked without an issue.

    QDir cur = QDir::current();
    cur.mkdir ("zz.yyyyyyyy.xxx");
    

    With Android 11 this does not create the folder reliably anymore. Sometimes it worked but on other occations it does not.

    Basically the app shall create a data folder accessible for other applications in order to transfer the output anywhere.

    I guess this is due to the new rules of storage management for Android 11.

    Any suggestions how to get around this?


  • Moderators

    @koahnig are you aware of
    https://www.qt.io/blog/2017/12/01/sharing-files-android-ios-qt-app

    the external folder for sharing works, afaik, still on all android versions

    Or at least, I based ma classes on it, and I have yet to hear from someone where it does not work



  • @J-Hilk

    Thanks for reminder. Yes, I am aware of this.
    So far the other method was much easier.


  • Moderators

    @koahnig said in Android 11 QDir::mkDir() does not always work:

    So far the other method was much easier.

    nothing good is ever easy :P

    that said, there is also android:requestLegacyExternalStorage="true"
    https://forum.qt.io/topic/121837/cannot-open-device-s-image-after-targeting-api-29-on-android-x-device/3

    Maybe thats enough for your case?


  • Moderators

    @J-Hilk said in Android 11 QDir::mkDir() does not always work:

    there is also android:requestLegacyExternalStorage="true"
    https://forum.qt.io/topic/121837/cannot-open-device-s-image-after-targeting-api-29-on-android-x-device/3

    Maybe thats enough for your case?

    requestLegacyExternalStorage works on Android 10 but is no longer supported on Android 11 and newer, unfortunately: https://lists.qt-project.org/pipermail/interest/2021-May/037085.html

    I don't know what the full fix is in Qt, but the app needs to use Scoped Storage somehow: https://source.android.com/devices/storage/scoped



  • @JKSH said in Android 11 QDir::mkDir() does not always work:

    @J-Hilk said in Android 11 QDir::mkDir() does not always work:

    there is also android:requestLegacyExternalStorage="true"
    https://forum.qt.io/topic/121837/cannot-open-device-s-image-after-targeting-api-29-on-android-x-device/3

    Maybe thats enough for your case?

    requestLegacyExternalStorage works on Android 10 but is no longer supported on Android 11 and newer, unfortunately: https://lists.qt-project.org/pipermail/interest/2021-May/037085.html

    I don't know what the full fix is in Qt, but the app needs to use Scoped Storage somehow: https://source.android.com/devices/storage/scoped

    I have tried that but it does not work on Android 11.

    Unfortnately, the example of https://www.qt.io/blog/2017/12/01/sharing-files-android-ios-qt-app does not work either with Qt5.15.2.
    I remember that I got it to work a year ago, but it doesn't with the new version anymore. Got stuck after starting. Also debugging does not work. Great start for today :(


  • Qt Champions 2016

    @koahnig said in Android 11 QDir::mkDir() does not always work:

    Unfortnately, the example of https://www.qt.io/blog/2017/12/01/sharing-files-android-ios-qt-app does not work either with Qt5.15.2.

    mea culpa - I have used Qt 5.13.2 on macOS Mojave for Android / iOS all the time and much work on 5 customer projects, so I didn't want to change a running system. But now I must upgrade - need XCode12 to upload to app store ;-)
    will take some time until all my projects are up and running using Qt 5.15
    then I'll take a look at sharing and also HowTo deal with scoped files - one customer will need this



  • @ekkescorner

    No problem.

    I tried to go back Qt5.14.2 but that will not help. AFAIK going back Qt5.13 will not help either.

    Some of the gradle has been adjusted. I can start the app, but there are display issues. The welcome to "Welcome to ekke's Share Example App" does not show.

    After release compilation and starting the app the application output in creator shows:

    I Perf    : Connecting to perf service.
    I FeatureParser: can't find cepheus.xml in assets/device_features/,it may be in /system/etc/device_features
    E libc    : Access denied finding property "ro.vendor.df.effect.conflict"
    E Perf    : Fail to get file list lib
    E Perf    : getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
    E Perf    : Fail to get file list debug-socket
    E Perf    : getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
    E Perf    : Fail to get file list org.ekkescorner.examples.sharex
    E Perf    : getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
    E Perf    : Fail to get file list org.ekkescorner.examples.sharex
    E Perf    : getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
    E examples.share: Invalid ID 0x00000000.
    E Qt      : Can't create main activity
    E Qt      : android.content.res.Resources$NotFoundException: String array resource ID #0x0
    E Qt      : 	at android.content.res.Resources.getStringArray(Resources.java:618)
    E Qt      : 	at android.content.res.MiuiResources.getStringArray(MiuiResources.java:160)
    E Qt      : 	at org.qtproject.qt5.android.bindings.QtLoader.startApp(QtLoader.java:423)
    E Qt      : 	at org.qtproject.qt5.android.bindings.QtActivityLoader.onCreate(QtActivityLoader.java:166)
    E Qt      : 	at org.qtproject.qt5.android.bindings.QtActivity.onCreateHook(QtActivity.java:267)
    E Qt      : 	at org.qtproject.qt5.android.bindings.QtActivity.onCreate(QtActivity.java:274)
    E Qt      : 	at org.ekkescorner.examples.sharex.QShareActivity.onCreate(QShareActivity.java:61)
    E Qt      : 	at android.app.Activity.performCreate(Activity.java:7894)
    E Qt      : 	at android.app.Activity.performCreate(Activity.java:7881)
    E Qt      : 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
    E Qt      : 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3283)
    E Qt      : 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3457)
    E Qt      : 	at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
    E Qt      : 	at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
    E Qt      : 	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
    E Qt      : 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2044)
    E Qt      : 	at android.os.Handler.dispatchMessage(Handler.java:107)
    E Qt      : 	at android.os.Looper.loop(Looper.java:224)
    E Qt      : 	at android.app.ActivityThread.main(ActivityThread.java:7560)
    E Qt      : 	at java.lang.reflect.Method.invoke(Native Method)
    E Qt      : 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
    E Qt      : 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
    D ekkescorner: onCreate QShareActivity
    D View    : org.ekkescorner.examples.sharex initForcedUseForceDark: 1
    I AdrenoGLES: QUALCOMM build                   : 4d7a98b, Ic1977df6c2
    I AdrenoGLES: Build Date                       : 09/16/20
    I AdrenoGLES: OpenGL ES Shader Compiler Version: EV031.27.05.01
    I AdrenoGLES: Local Branch                     :
    I AdrenoGLES: Remote Branch                    : refs/tags/AU_LINUX_ANDROID_LA.UM.8.1.R1.09.00.00.529.087
    I AdrenoGLES: Remote Branch                    : NONE
    I AdrenoGLES: Reconstruct Branch               : NOTHING
    I AdrenoGLES: Build Config                     : S P 8.0.11 AArch64
    I AdrenoGLES: PFP: 0x016ee187, ME: 0x00000000
    W AdrenoUtils: <ReadGpuID_from_sysfs:194>: Failed to open /sys/class/kgsl/kgsl-3d0/gpu_model
    W AdrenoUtils: <ReadGpuID:218>: Failed to read chip ID from gpu_model. Fallback to use the GSL path
    W Gralloc3: mapper 3.x is not supported
    I examples.share: ProcessProfilingInfo new_methods=41 is saved saved_to_disk=1 resolve_classes_delay=8000
    

    Compiled and started in debug mode

    killall: gdbserver: No such process
    
    18:58:35: Debugging starts
    I examples.share: Late-enabling -Xcheck:jni
    E examples.share: Unknown bits set in runtime_flags: 0x8000
    W ActivityThread: Application org.ekkescorner.examples.sharex is waiting for the debugger on port 8100...
    I System.out: Sending WAIT chunk
    I System.out: Debugger has connected
    I System.out: waiting for debugger to settle...
    I System.out: waiting for debugger to settle...
    I System.out: waiting for debugger to settle...
    Could not load shared library symbols for 277 libraries, e.g. /system/lib64/libandroid_runtime.so.
    Use the "info sharedlibrary" command to see the complete listing.
    Do you need "set solib-search-path" or "set sysroot"?I System.out: debugger has settled (1829)
    I Perf    : Connecting to perf service.
    I FeatureParser: can't find cepheus.xml in assets/device_features/,it may be in /system/etc/device_features
    E libc    : Access denied finding property "ro.vendor.df.effect.conflict"
    W examples.sharex: type=1400 audit(0.0:35376): avc: denied { read } for name="u:object_r:vendor_displayfeature_prop:s0" dev="tmpfs" ino=17377 scontext=u:r:untrusted_app_27:s0:c84,c257,c512,c768 tcontext=u:object_r:vendor_displayfeature_prop:s0 tclass=file permissive=0
    E Perf    : Fail to get file list lib
    E Perf    : getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
    E Perf    : Fail to get file list debug-socket
    E Perf    : getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
    E Perf    : Fail to get file list org.ekkescorner.examples.sharex
    E Perf    : getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
    E Perf    : Fail to get file list org.ekkescorner.examples.sharex
    E Perf    : getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
    W Looper  : Slow Looper main: Long Msg: seq=2 plan=18:58:34.576  late=0ms wall=2903ms running=408ms runnable=3ms io=3ms h=android.app.ActivityThread$H w=110
    E examples.share: Invalid ID 0x00000000.
    E Qt      : Can't create main activity
    E Qt      : android.content.res.Resources$NotFoundException: String array resource ID #0x0
    E Qt      : 	at android.content.res.Resources.getStringArray(Resources.java:618)
    E Qt      : 	at android.content.res.MiuiResources.getStringArray(MiuiResources.java:160)
    E Qt      : 	at org.qtproject.qt5.android.bindings.QtLoader.startApp(QtLoader.java:423)
    E Qt      : 	at org.qtproject.qt5.android.bindings.QtActivityLoader.onCreate(QtActivityLoader.java:166)
    E Qt      : 	at org.qtproject.qt5.android.bindings.QtActivity.onCreateHook(QtActivity.java:267)
    E Qt      : 	at org.qtproject.qt5.android.bindings.QtActivity.onCreate(QtActivity.java:274)
    E Qt      : 	at org.ekkescorner.examples.sharex.QShareActivity.onCreate(QShareActivity.java:61)
    E Qt      : 	at android.app.Activity.performCreate(Activity.java:7894)
    E Qt      : 	at android.app.Activity.performCreate(Activity.java:7881)
    E Qt      : 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
    E Qt      : 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3283)
    E Qt      : 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3457)
    E Qt      : 	at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
    E Qt      : 	at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
    E Qt      : 	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
    E Qt      : 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2044)
    E Qt      : 	at android.os.Handler.dispatchMessage(Handler.java:107)
    E Qt      : 	at android.os.Looper.loop(Looper.java:224)
    E Qt      : 	at android.app.ActivityThread.main(ActivityThread.java:7560)
    E Qt      : 	at java.lang.reflect.Method.invoke(Native Method)
    E Qt      : 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
    E Qt      : 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
    D ekkescorner: onCreate QShareActivity
    D View    : org.ekkescorner.examples.sharex initForcedUseForceDark: 1
    W Looper  : Slow Looper main: Activity org.ekkescorner.examples.sharex/.QShareActivity is 2821ms late (wall=244ms running=219ms ClientTransaction{ callbacks=[android.app.servertransaction.LaunchActivityItem] lifecycleRequest=android.app.servertransaction.ResumeActivityItem }) because of 1 msg, msg 1 took 2903ms (seq=2 running=408ms runnable=3ms io=3ms h=android.app.ActivityThread$H w=110)
    W Looper  : Slow Looper main: Activity org.ekkescorner.examples.sharex/.QShareActivity is 3066ms late (wall=1ms running=0ms ClientTransaction{ callbacks=[android.app.servertransaction.TopResumedActivityChangeItem] }) because of 2 msg, msg 1 took 2903ms (seq=2 running=408ms runnable=3ms io=3ms h=android.app.ActivityThread$H w=110), msg 2 took 244ms (seq=3 running=219ms runnable=6ms io=5ms late=2821ms h=android.app.ActivityThread$H w=159)
    I AdrenoGLES: QUALCOMM build                   : 4d7a98b, Ic1977df6c2
    I AdrenoGLES: Build Date                       : 09/16/20
    I AdrenoGLES: OpenGL ES Shader Compiler Version: EV031.27.05.01
    I AdrenoGLES: Local Branch                     :
    I AdrenoGLES: Remote Branch                    : refs/tags/AU_LINUX_ANDROID_LA.UM.8.1.R1.09.00.00.529.087
    I AdrenoGLES: Remote Branch                    : NONE
    I AdrenoGLES: Reconstruct Branch               : NOTHING
    I AdrenoGLES: Build Config                     : S P 8.0.11 AArch64
    Could not load shared library symbols for /vendor/lib64/hw/gralloc.msmnile.so.
    Do you need "set solib-search-path" or "set sysroot"?I AdrenoGLES: PFP: 0x016ee187, ME: 0x00000000
    W AdrenoUtils: <ReadGpuID_from_sysfs:194>: Failed to open /sys/class/kgsl/kgsl-3d0/gpu_model
    W AdrenoUtils: <ReadGpuID:218>: Failed to read chip ID from gpu_model. Fallback to use the GSL path
    W RenderThread: type=1400 audit(0.0:35377): avc: denied { search } for name="kgsl" dev="sysfs" ino=55589 scontext=u:r:untrusted_app_27:s0:c84,c257,c512,c768 tcontext=u:object_r:sysfs_kgsl:s0 tclass=dir permissive=0
    W Gralloc3: mapper 3.x is not supported
    Could not load shared library symbols for /system/lib64/libboost.so.
    Do you need "set solib-search-path" or "set sysroot"?I examples.share: ProcessProfilingInfo new_methods=41 is saved saved_to_disk=1 resolve_classes_delay=8000
    

    Both are compiled for arm64-v8a.

    This is a screenshot of what is shown on the screen. Same thing on Android 9, 10 and 11.

    signal-2021-06-01-190045.jpeg



  • There is already an update available on Git from @HomDX (presumably).

    https://github.com/homdx/ekkesSHAREexample/tree/feature/Qt-5.15.0

    That fix is compilable for Qt5.15.2 on Windows and it does work.

    The issue has been marked as solved, because following the route of @J-Hilk seems to be the best option.


Log in to reply