"QSqlDatabase: QSQLITE driver not loaded" error in deploying a Qt-Android project using JNI with Android studio
-
I would run 'ldd' on the shell if there is any but yes, basically you can try to load them with QLibrary and see what the error is (if there is any)
-
@Christian-Ehrlicher After running ldd, this error appears:
not a dynamic executable
Using QLibrary, show this error:
Trying... "/storage/emulated/0/plugins/libqsqlite.so" Trying... "/storage/emulated/0/plugins/libqsqlite.so.so" Trying... "/storage/emulated/0/plugins/liblibqsqlite.so" Trying... "/storage/emulated/0/plugins/liblibqsqlite.so.so" "libqsqlite.so" not found Library load error: "The shared library was not found."
Don't forget I build and deploy this application using android studio on my Android device.
It seems that the library path can not be identified. I am confused. How can I load that? -
@morteza-ali-ahmadi said in "QSqlDatabase: QSQLITE driver not loaded" error in deploying a Qt-Android project using JNI with Android studio:
After running ldd, this error appears:
This is what I expected - 'I would run 'ldd' on the shell if there is any' - you can't run ldd on the target so running it on the build system will not help at all.
I would take a look with QFile/QFileInfo to see where the library is.
-
@Christian-Ehrlicher Finally in loading libqsqlite.so, this error appears:
library "/storage/emulated/0/plugins/sqldrivers/libqsqlite.so" ("/storage/emulated/0/plugins/sqldrivers/libqsqlite.so") needed or dlopened by "/data/app/com.horizon.polarislib-1/lib/arm64/libQt5Core.so" is not accessible for the namespace: [name="classloader-namespace", ld_library_paths="", default_library_paths="/data/app/com.horizon.polarislib-1/lib/arm64:/data/app/com.horizon.polarislib-1/base.apk!/lib/arm64-v8a", permitted_paths="/data:/mnt/expand:/data/data/com.horizon.polarislib"]
Can this error help?
-
Hi,
You can't put plugins anywhere you'd like. Qt follows a well defined structure and will search plugins in specific paths. You have to put the database related plugins under "plugins/sqldrivers".
Edit: while the plugins have specific subfolders, it seems deployment have them in different places. See here
-
@SGaist Thanks, yes of course. I have put my libqsqlit.so in /mnt/sdcard/plugins/sqldrivers/ and added /mnt/sdcard/plugins/ in library path using:
QCoreApplication::addLibraryPath("/mnt/sdcard/plugins"); QApplication::addLibraryPath("/mnt/sdcard/plugins");
But this lib-plugin can not be identified.
-
Are you sure that this path can be accessed as is by your application ?
By the way, why use such an external path ?
-
Are you sure that this path can be accessed as is by your application ?
I have set permission to storage and I can create, read and write a simple text file in this address.
By the way, why use such an external path ?
Because when I deploy my app with android studio, I can see all libs like libQt5Core.so and libqsqlite.so in a specific folder and the structure of .../plugins/sqldrivers/libqsqlite.so does not exist. So, I have copied libqsqlite.so to a folder in sdcard by this structure /plugins/sqldrivers/
-
It has been brought to my attention that my memory may have failed me. See here.
One thing that you can do is build one of Qt's database example and then inspect the content of the archive generated to see what does mismatch with yours.
-
I can solve the problem. First, I created folder sqldrivers including libqsqlite.so in the app directory (e.x. /data/user/0/com.example.polarislib) and I set permission by chmod 777 to sqldrivers folder and libqsqlite.so file and finally I used the following code in my source where the connection to Sqlite is needed:
QCoreApplication::addLibraryPath("/data/user/0/com.example.polarislib");