Using the GUI library based on the Android app
-
I need to integrate a native-lib library into the native Android application (Kotlin), which is written in Qt and calls another library (next-lib shared library) that uses Qt5Gui and Qt5Xml internally. I can't do that. The program crashes when loading the native-lib library. The next-lib library is supposed to parse XML and draw images into the bitmap of the android application. This library next-lib is already done and stabel (in other sysem environment) - I just need to be able to integrate it on Android.
If next-lib does not use any Qt library calls, everything works fine.
I followed :
https://developer.android.com/studio/projects/configure-cmake.htmlI first created another Qt program (for ARM64-v8a) that calls next-lib library. From the distribution of this program I have copied all Qt libraries and put them in the Android studio project (app / src / main / jniLibs / arm64-v8a). The program has been translated and using APK analyzer I have verified that all of them are also in APK.
I added libraries to CMakeList.txt as follows:
add_library SHARED IMPORTED
set_target_properties (qt_paint_img PROPERTIES IMPORTED_LOCATION C: /TMP/android_attempts/NativeTest3/app/src/main/jniLibs/arm64-v8a/libnext-lib.so)add_library (Qt5Gui SHARED IMPORTED)
set_target_properties (Qt5Gui PROPERTIES IMPORTED_LOCATION)
C: /TMP/android_attempts/NativeTest3/app/src/main/jniLibs/arm64-v8a/libQt5Gui.so)
….target_link_libraries (# Specifies the target library.
native-lib
next-lib
Qt5Gui
…….
-ljnigraphics
$ {log-lib}
)Environment:
Android Studio 3.4.1
• Qt 5.12.2
• Tablet with ARM64 processor
The native-lib library is translated in the Android studio
The next-lib library is translated in QtCreator in ARM64-v8aWhen you run the program, it crashes when you call:
companion object {// Used to load the 'native-lib' library on application startup. init { System.loadLibrary ("native-lib")}
}
This will show up:
java.lang.UnsatisfiedLinkError: JNI_ERR returned from JNI_OnLoad in "/data/app/en.cdis.nativetest-qNQx9aJhzVNQyvmUP65MzQ==/lib/arm64/libnative-lib.so"
at java.lang.Runtime.loadLibrary0 (Runtime.java:1016)
at java.lang.System.loadLibrary (System.java:1657)
at cz.cdis.nativetest.MainActivity. <clinit> (MainActivity.kt: 81)
at java.lang.Class.newInstance (Native Method)
at android.app.Instrumentation.newActivity (Instrumentation.java:1175)
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2672)
at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2859)
at android.app.ActivityThread.-wrap11 (Unknown Source: 0)
at android.app.ActivityThread $ H.handleMessage (ActivityThread.java:1592)
at android.os.Handler.dispatchMessage (Handler.java:106)
at android.os.Looper.loop (Looper.java:164)
at android.app.ActivityThread.main (ActivityThread.java:6518)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.RuntimeInit $ MethodAndArgsCaller.run (RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:807)Have anyone an example of how to integrate Qt libraries into native Android applications?
-
@jiri.kochanek
It is solved, but only partially.Ignore exception caused loading Qt5Core is enough.
val Lib0 = "native-lib"; try { System.loadLibrary(Lib0); } catch (e: UnsatisfiedLinkError) { System.err.println(Lib0 + " code library failed to load\n" + e) }
!!!! But - in this application is possible parsing XML, draw images ...., but there is not possible use working with fonts, because database of fonts is baser somewhere in QGuiApplication, but unfortunatelly it is not possible call inside of Android application.
For this problem I will create next session.