Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chap05 runs on desktop but not on mobile. #13

Closed
RoyeA opened this issue Nov 12, 2021 · 1 comment
Closed

Chap05 runs on desktop but not on mobile. #13

RoyeA opened this issue Nov 12, 2021 · 1 comment

Comments

@RoyeA
Copy link

RoyeA commented Nov 12, 2021

Love the book. It teachs me a lot.
I'm trying to run the chap05 app on an Android device. It fails to start due to the followings:

E AndroidRuntime: FATAL EXCEPTION: qtMainLoopThread
E AndroidRuntime: Process: org.qtproject.example.gallery_mobile, PID: 25728
E AndroidRuntime: java.lang.UnsatisfiedLinkError: dlopen failed: library "libgallery-core_armeabi-v7a.so" not found
E AndroidRuntime: 	at java.lang.Runtime.load0(Runtime.java:897)
E AndroidRuntime: 	at java.lang.System.load(System.java:1505)
E AndroidRuntime: 	at org.qtproject.qt5.android.QtNative$4.run(QtNative.java:505)
E AndroidRuntime: 	at org.qtproject.qt5.android.QtThread$2.run(QtThread.java:87)
E AndroidRuntime: 	at org.qtproject.qt5.android.QtThread$1.run(QtThread.java:61)
E AndroidRuntime: 	at java.lang.Thread.run(Thread.java:761)

Looking in the apk file, and listing all libs, the libgallery-core_armeabi-v7a.so is missing.
Two questions:

  1. How do I configure the build to include the core library within the apk ?
  2. When compiling the android version, the core library has a different name than just gallery-core. How do I set it up in the .pro file?

Thank you,
Roye Avidor

@GuillaumeLazar
Copy link
Collaborator

Hello Roye,
I'm glad that you like the book.

The first edition of the book was written for Qt 5.7 and the second edition wad updated for Qt 5.11. I think you encounters issues because you are using a Qt version >= 5.14.

Starting Qt version 5.14 , Qt for Android now use Android Clang Multi-Abi that generate multi ABI binaries. And the name of a library is postfix with the name of the ABI (armeabi-v7a, amr6-v8a, x86, x86_64, ...).

  • The quick and easy solution is to use the Qt version 5.11 (same that the second edition of the book) and an adapted android kit e.g "armeabi_v7a" (prior to the Android clang multi ABI feature). You will see in the apk that you get the Qt libs and your project lib "libgallery-core.so" in the APK.

  • The slow and better solution is to update the "gallery-mobile.pro" to handle the android multi abi feature and use a Qt version 5.15.2 and android kit clang multi ABI. And maybe also update the source code due to Qt changes:

  1. You have some modifications to do on the "gallery-mobile.pro". You should use the qmake variable "$$ANDROID_ABIS" that will automatically set the correct ABI name during the qmake process.
# Removed part. Qt version 5.11  (single ABI)
# LIBS += -L$$OUT_PWD/../gallery-core/ -lgallery-core
# contains(ANDROID_TARGET_ARCH,x86) {
#     ANDROID_EXTRA_LIBS = \
#         $$[QT_INSTALL_LIBS]/libQt5Sql.so
# }

# Updated part. >= Qt version 5.14  (multi ABI)
android: {
    LIBS += -L$$OUT_PWD/../gallery-core/ -lgallery-core_$$ANDROID_ABIS

    ANDROID_EXTRA_LIBS = \
        $$[QT_INSTALL_LIBS]/libQt5PrintSupport_$${ANDROID_ABIS}.so \
        $$[QT_INSTALL_LIBS]/libQt5Sql_$${ANDROID_ABIS}.so \
        $$OUT_PWD/../gallery-core/libgallery-core_$${ANDROID_ABIS}.so \
} else {
    LIBS += -L$$OUT_PWD/../gallery-core/ -lgallery-core
}
  1. Nothing should be done on the "gallery-core.pro", just check that the "libgallery-core_armeabi-v7a.so" is generated

You can now check the generated APK, you hould get the "libgallery-mobile_armeabi-v7a.so" file in the APK.

The fix above will correct your compilation issue with >=Qt 5.14 for Android. But I guess you will get others issues and it can require some time to update a source code software to Qt version to another one.

If you update it to a recent Qt version, feel free to create a PR on the second edition github repo (this first edition github is deprecated and not updated) : https://github.com/PacktPublishing/Mastering-Qt-5-Second-Editon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants