Solved Issue with mkpath on Android
-
I have an application which has been developed in C++ on Windows, but can be used on Linux (desktop and embedded) without issues. The application generates quite a number of files in a data folder. Those files are filled using std ofstreams. The files are structured in different folders. The folders are generated on the fly by QDir::mkpath.
Now on Android there seems to be an issue with the generation of the topmost data folder which is typically structured
<country code>.<company>.<application> on Android.When this folder has to be generated as well mkpath has a problem and the folder is not generated.
When folder is already available the performance of all subsequent folders is normal without an issue.
Any idea what am I missing?
-
Hi,
What root path are you using for these folders ?
At least on Android you need to use QStandardPath::AppDataLocation. But don't forget to first create the directory returned by the writablePath call the first time you want to access it. Its name is valid however it does not exist yet.
-
The data is under /storage/emulated/0/Android/data which is the internal data storage.
Thanks for the lead I am going follow this up.
-
@SGaist said in Issue with mkpath on Android:
Hi,
What root path are you using for these folders ?
At least on Android you need to use QStandardPath::AppDataLocation. But don't forget to first create the directory returned by the writablePath call the first time you want to access it. Its name is valid however it does not exist yet.
I guess you meant https://doc.qt.io/qt-5/qstandardpaths.html#writableLocation with QStandardPaths::DataLocation
At least that I got to work apparently on Android 10.
Android 9 is still less cooperative. At least the files are not written there, but must be written somewhere since the application does not crash. I can't find the files. -
@koahnig I guess the files are written under /data/user/0/<packagename>/files/
-
@KroMignon said in Issue with mkpath on Android:
@koahnig I guess the files are written under /data/user/0/<packagename>/files/
You are correct that this is the path shown with writableLocation. It is also generated under /storage/emulated/0/Android/data/<packagename>/files. However, you cannot simply this /data/user/0/<packagename>/files/ for absolute path' with ofstream under C++. These files are not generated.
I was previously wrong. The issue is the same for Android 9 and Android 10.
When using /storage/emulated/0/Android/data/<packagename>/files this might be used as basis for absolute path' generation and std::ofstream of C++.