Results 1 to 4 of 4

Thread: Adding external library into Qt-Android project

  1. #1
    Join Date
    Aug 2015
    Posts
    1
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Adding external library into Qt-Android project

    I use mapbox-gl (https://github.com/mapbox/mapbox-gl-native).

    I built libmapbox-gl.so (arch armeabi-v7a) using make-android.

    Test app in Android Studio works correctly.

    Then in the Qt project tried to link this library in myproject.pro file:

    Qt Code:
    1. contains(ANDROID_TARGET_ARCH,armeabi-v7a)
    2. {
    3. ANDROID_EXTRA_LIBS = \
    4. $$PWD/../Desktop/mapbox-gl-native/build/android-arm-v7/Release/lib.target/libmapbox-gl.so
    5. }
    To copy to clipboard, switch view to plain text mode 

    Project builds correctly. But when I try to run app on device, app crashes. I think, app can't find this library.

    How to properly connect the library and what could be the problem?

  2. #2
    Join Date
    Nov 2012
    Location
    Russia
    Posts
    231
    Thanks
    118
    Thanked 18 Times in 10 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Adding external library into Qt-Android project

    Hi. Did you solved the problem? I try to run an app with the FMOD sound library. The build process was finished without problems and the APK file was created with these settings:

    Qt Code:
    1. INCLUDEPATH += $$PWD/libs/fmod-2.2.16/inc
    2.  
    3. contains(ANDROID_TARGET_ARCH, armeabi-v7a)
    4. {
    5. LIBS += $$PWD/libs/fmod-2.2.16/lib/armeabi-v7a/libfmod.so
    6. }
    To copy to clipboard, switch view to plain text mode 

    But when I run it on real smartphone the app was crashed. Why? What should I try?

    I built this example for Desktop before and it works without crash. Music played.


    Added after 1 7 minutes:


    I found this answer here: https://stackoverflow.com/questions/...ardware-device

    > Finally after much digging.

    > The compiler used with QtCreator generates armeabi-v7a lib files.

    > Those files are included into the /libs/ folder on the apk.

    > Our project required to use some other external libs that were also compiled for other architectures. The folder /libs/ of the generated apk contained libs for those different architecture, but the main project was available only for the armeabi-v7a.

    > Therefore the app would be started and try to find the lib to the preferred architecture and would crash right away.

    > The solution is to force using only the available architecture.

    > This is done by adding this to the build.gradle script

    Qt Code:
    1. defaultConfig {
    2. ndk {
    3. abiFilters 'armeabi-v7a'
    4. }
    5. }
    To copy to clipboard, switch view to plain text mode 
    I found where I should add it: `C:\Qt\6.2.4\android_armv7\src\android\templates\b uild.gradle`

    I add it to `build.gradle` here:

    Qt Code:
    1. defaultConfig {
    2. resConfig "en"
    3. minSdkVersion qtMinSdkVersion
    4. targetSdkVersion qtTargetSdkVersion
    5. ndk.abiFilters = qtTargetAbiList.split(",")
    6. ndk {
    7. abiFilters 'armeabi-v7a'
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 
    But it did not help. The app is crashed on real smartphone.

    I tried to rerun Qt and delete the old build to APK. But it did not help.

    But I opened a report of MIUI about errors on smartphone:

    java.lang.UnsatisfiedLinkError: dlopen failed: library "libfmod.so" not found
    at java.lang.Runtime.load0(Runtime.java: 908)
    at java.lang.System.load(System.java: 1537)
    at org.qtproject.qt.android.QtNative$4.run(QtNative.j ava:536)
    at org.qtproject.qt.android.QtThread$2.run(QtThread.j ava:87)
    at org.qtproject.qt.android.QtThread$1.run(QtThread.j ava:61)
    at java.lang.Thread.run(Thread.java:760)
    Last edited by 8Observer8; 18th August 2023 at 02:02.

  3. #3
    Join Date
    Nov 2012
    Location
    Russia
    Posts
    231
    Thanks
    118
    Thanked 18 Times in 10 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Adding external library into Qt-Android project

    I changed LIBS to ANDROID_EXTRA_LIBS like here: https://www.qtcentre.org/threads/607...120#post269120

    Since you're linking dynamically against libusb you need to deploy the library with your application. You can use ANDROID_EXTRA_LIBS to achieve that.

    Have a look at the documentation: http://qt-project.org/doc/qt-5/deployment-android.html
    Qt Code:
    1. contains(ANDROID_TARGET_ARCH, armeabi-v7a)
    2. {
    3. ANDROID_EXTRA_LIBS += $$PWD/jniLibs/armeabi-v7a/libfmod.so
    4. }
    To copy to clipboard, switch view to plain text mode 

    Now I have another errors after a crash on the real device:

    *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
    Build fingerprint: 'Xiaomi/santoni/santoni:7.1.2/N2G47H/9.6.27:user/release-keys'
    Revision: '0'
    ABI: 'arm'
    pid: 11662, tid: 11682, name: qtMainLoopThrea >>> org.qtproject.example.fmode_2d_qt6_cpp <<<
    signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
    Abort message: 'art/runtime/java_vm_ext.cc:475] JNI DETECTED ERROR IN APPLICATION: JNI NewGlobalRef called with pending exception java.lang.ClassNotFoundException: Didn't find class "org.fmod.AudioDevice" on path: DexPathList[[zip file "/data/app/org.qtproject.example.fmode_2d_qt6_cpp-1/base.apk"],nativeLibraryDirectories=[/data/app/org.qtproject.example.fmode_2d_qt6_cpp-1/lib/arm, /data/app/org.qtproject.example.fmode_2d_qt6_cpp-1/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]'
    r0 00000000 r1 00002da2 r2 00000006 r3 00000008
    r4 c7780978 r5 00000006 r6 c7780920 r7 0000010c
    r8 00000000 r9 0000000a sl 00000fbd fp da07b900
    ip 0000000b sp c777f610 lr e843f2d7 pc e8441b58 cpsr 200f0010

    backtrace:
    #00 pc 00049b58 /system/lib/libc.so (tgkill+12)
    #01 pc 000472d3 /system/lib/libc.so (pthread_kill+34)
    #02 pc 0001d575 /system/lib/libc.so (raise+10)
    #03 pc 000190c1 /system/lib/libc.so (__libc_android_abort+34)
    #04 pc 00017124 /system/lib/libc.so (abort+4)
    #05 pc 0031c3d9 /system/lib/libart.so (_ZN3art7Runtime5AbortEPKc+328)
    #06 pc 000b569d /system/lib/libart.so (_ZN3art10LogMessageD2Ev+1132)
    #07 pc 0023ab55 /system/lib/libart.so (_ZN3art9JavaVMExt8JniAbortEPKcS2_+1664)
    #08 pc 0023ad47 /system/lib/libart.so (_ZN3art9JavaVMExt9JniAbortVEPKcS2_St9__va_list+58 )
    #09 pc 000cb09b /system/lib/libart.so (_ZN3art11ScopedCheck6AbortFEPKcz+46)
    #10 pc 000cac87 /system/lib/libart.so (_ZN3art11ScopedCheck11CheckThreadEP7_JNIEnv+362)
    #11 pc 000c9c9f /system/lib/libart.so (_ZN3art11ScopedCheck22CheckPossibleHeapValueERNS_ 18ScopedObjectAccessEcNS_12JniValueTypeE+26)
    #12 pc 000c917b /system/lib/libart.so (_ZN3art11ScopedCheck5CheckERNS_18ScopedObjectAcce ssEbPKcPNS_12JniValueTypeE+802)
    #13 pc 000cbe49 /system/lib/libart.so (_ZN3art8CheckJNI6NewRefEPKcP7_JNIEnvP8_jobjectNS_ 15IndirectRefKindE+452)
    #14 pc 003382fd /system/lib/libart.so (_ZN3art6Thread22SetClassLoaderOverrideEP8_jobject +32)
    #15 pc 0023c857 /system/lib/libart.so (_ZN3art9JavaVMExt17LoadNativeLibraryEP7_JNIEnvRKN St3__112basic_stringIcNS3_11char_traitsIcEENS3_9al locatorIcEEEEP8_jobjectP8_jstringPS9_+1878)
    #16 pc 00003167 /system/lib/libopenjdkjvm.so (JVM_NativeLoad+178)
    #17 pc 00584c6d /system/framework/arm/boot.oat (offset 0x51c000) (java.lang.Runtime.nativeLoad+144)
    #18 pc 005848ad /system/framework/arm/boot.oat (offset 0x51c000) (java.lang.Runtime.doLoad+136)
    #19 pc 005859dd /system/framework/arm/boot.oat (offset 0x51c000) (java.lang.Runtime.load0+368)
    #20 pc 0059e383 /system/framework/arm/boot.oat (offset 0x51c000) (java.lang.System.load+78)
    #21 pc 000a9b41 /system/lib/libart.so (art_quick_invoke_stub_internal+64)
    #22 pc 00406ff5 /system/lib/libart.so (art_quick_invoke_static_stub+228)
    #23 pc 000b0dff /system/lib/libart.so (_ZN3art9ArtMethod6InvokeEPNS_6ThreadEPjjPNS_6JVal ueEPKc+178)
    #24 pc 001edfed /system/lib/libart.so (_ZN3art11interpreter34ArtInterpreterToCompiledCod eBridgeEPNS_6ThreadEPNS_9ArtMethodEPKNS_7DexFile8C odeItemEPNS_11ShadowFrameEPNS_6JValueE+200)
    #25 pc 001e859d /system/lib/libart.so (_ZN3art11interpreter6DoCallILb0ELb0EEEbPNS_9ArtMe thodEPNS_6ThreadERNS_11ShadowFrameEPKNS_11Instruct ionEtPNS_6JValueE+492)
    #26 pc 003ffaf9 /system/lib/libart.so (MterpInvokeStatic+236)
    #27 pc 0009cb14 /system/lib/libart.so (ExecuteMterpImpl+14612)
    #28 pc 001cb8c7 /system/lib/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadEPKNS_7D exFile8CodeItemERNS_11ShadowFrameENS_6JValueEb+286 )
    #29 pc 001d042f /system/lib/libart.so (_ZN3art11interpreter33ArtInterpreterToInterpreter BridgeEPNS_6ThreadEPKNS_7DexFile8CodeItemEPNS_11Sh adowFrameEPNS_6JValueE+114)
    #30 pc 001e8583 /system/lib/libart.so (_ZN3art11interpreter6DoCallILb0ELb0EEEbPNS_9ArtMe thodEPNS_6ThreadERNS_11ShadowFrameEPKNS_11Instruct ionEtPNS_6JValueE+466)
    #31 pc 003ff61b /system/lib/libart.so (MterpInvokeInterface+834)
    #32 pc 0009cb94 /system/lib/libart.so (ExecuteMterpImpl+14740)
    #33 pc 001cb8c7 /system/lib/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadEPKNS_7D exFile8CodeItemERNS_11ShadowFrameENS_6JValueEb+286 )
    #34 pc 001d042f /system/lib/libart.so (_ZN3art11interpreter33ArtInterpreterToInterpreter BridgeEPNS_6ThreadEPKNS_7DexFile8CodeItemEPNS_11Sh adowFrameEPNS_6JValueE+114)
    #35 pc 001e8583 /system/lib/libart.so (_ZN3art11interpreter6DoCallILb0ELb0EEEbPNS_9ArtMe thodEPNS_6ThreadERNS_11ShadowFrameEPKNS_11Instruct ionEtPNS_6JValueE+466)
    #36 pc 003ff61b /system/lib/libart.so (MterpInvokeInterface+834)
    #37 pc 0009cb94 /system/lib/libart.so (ExecuteMterpImpl+14740)
    #38 pc 001cb8c7 /system/lib/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadEPKNS_7D exFile8CodeItemERNS_11ShadowFrameENS_6JValueEb+286 )
    #39 pc 001d0399 /system/lib/libart.so (_ZN3art11interpreter30EnterInterpreterFromEntryPo intEPNS_6ThreadEPKNS_7DexFile8CodeItemEPNS_11Shado wFrameE+92)
    #40 pc 003f63e7 /system/lib/libart.so (artQuickToInterpreterBridge+706)
    #41 pc 000ae593 /system/lib/libart.so (art_quick_to_interpreter_bridge+34)
    #42 pc 005a22e9 /system/framework/arm/boot.oat (offset 0x51c000) (java.lang.Thread.run+52)
    #43 pc 000a9b41 /system/lib/libart.so (art_quick_invoke_stub_internal+64)
    #44 pc 00406eed /system/lib/libart.so (art_quick_invoke_stub+232)
    #45 pc 000b0dd5 /system/lib/libart.so (_ZN3art9ArtMethod6InvokeEPNS_6ThreadEPjjPNS_6JVal ueEPKc+136)
    #46 pc 00317349 /system/lib/libart.so (_ZN3artL18InvokeWithArgArrayERKNS_33ScopedObjectA ccessAlreadyRunnableEPNS_9ArtMethodEPNS_8ArgArrayE PNS_6JValueEPKc+56)
    #47 pc 00318115 /system/lib/libart.so (_ZN3art35InvokeVirtualOrInterfaceWithJValuesERKNS _33ScopedObjectAccessAlreadyRunnableEP8_jobjectP10 _jmethodIDP6jvalue+256)
    #48 pc 0032f29d /system/lib/libart.so (_ZN3art6Thread14CreateCallbackEPv+848)
    #49 pc 00046da3 /system/lib/libc.so (_ZL15__pthread_startPv+22)
    #50 pc 00019b0d /system/lib/libc.so (__start_thread+6)

  4. #4
    Join Date
    Nov 2012
    Location
    Russia
    Posts
    231
    Thanks
    118
    Thanked 18 Times in 10 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Adding external library into Qt-Android project

    I think I need to load `fmod.jar` like is written in the documentation: https://www.fmod.com/docs/2.01/api/p...roid.html#java

    FMOD is primarily a native C/C++ library implementation but does have a Java component that is invoked from native code. To ensure the Java component is properly operating please make sure you reference the *fmod.jar* in your project. This means telling the IDE or build system where to find the *fmod.jar* file so it's included in the application.
    I need to find how to load jar-files and how to call Java code from Qt C++.

Similar Threads

  1. Replies: 1
    Last Post: 12th June 2015, 14:33
  2. adding external library
    By anh5kor in forum Qt Programming
    Replies: 1
    Last Post: 10th November 2014, 16:32
  3. Replies: 1
    Last Post: 7th February 2013, 09:51
  4. Qt Creator How to add an external .a library in Qt Creator project via GUI?
    By DIMEDROLL in forum Qt Tools
    Replies: 1
    Last Post: 7th January 2012, 08:11
  5. Adding an external Library
    By afflictedd2 in forum Qt Programming
    Replies: 1
    Last Post: 13th December 2008, 06:51

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.