Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. [Solved][Qt][Android]How can i add my own (librarys)*.so files into apk and use them?
Forum Updated to NodeBB v4.3 + New Features

[Solved][Qt][Android]How can i add my own (librarys)*.so files into apk and use them?

Scheduled Pinned Locked Moved Mobile and Embedded
10 Posts 4 Posters 21.2k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    erikalxq
    wrote on last edited by
    #1

    Hi, guys:

    When i using Qt for Android to deploy an apk, I want to use my own librarys in the application, so I copy the *.so files into the folder "android\libs\armeabi-v7a". After deployment, I did find the so files in apk,but when i use QLibrary::load to load the librarys, it failed. anybody can help?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Moster
      wrote on last edited by
      #2

      Actually this is exactly how it works. Copy the file into that folder. Im using opencv with Qt on android and needed the native camera lib in the apk. So I copied it there and now its in the apk/libs
      Maybe you didnt check "Bundle Qt Libraries in APK" (Qt 5.1.1)

      1 Reply Last reply
      0
      • E Offline
        E Offline
        erikalxq
        wrote on last edited by
        #3

        So where can i find this check "Bundle Qt Libraries in APK"?

        1 Reply Last reply
        0
        • M Offline
          M Offline
          Moster
          wrote on last edited by
          #4

          You need Qt5.1.1 for android, then go to your project's settings -> Run -> Deploy configurations -> Bundle Qt Libraries in APK

          1 Reply Last reply
          0
          • E Offline
            E Offline
            erikalxq
            wrote on last edited by
            #5

            I use Qt 5.1.0 for android, it don't have that kind of check. But I don't think this is the way to solve my problem.
            here is the details:
            1、I use the default c++ library project created by the QtCreator as my lib;
            2、I use the Qt Quick2 Application created by Creator as my mainApp;
            3、I use QLibrary::Load in my mainApp to dynamic load the c++ library;
            4、I copy the library to the folder "android/libs/armeabi-v7a";
            5、Deploy the mainApp(now the library in the apk/libs/armeabi-v7a);
            6、Install the mainApp in phone 、run it, and fail to load the library;

            1 Reply Last reply
            0
            • M Offline
              M Offline
              Moster
              wrote on last edited by
              #6

              Maybe this can help you: http://qt-project.org/forums/viewthread/29592

              1 Reply Last reply
              0
              • E Offline
                E Offline
                erikalxq
                wrote on last edited by
                #7

                Thanks moster, I will have a try

                1 Reply Last reply
                0
                • E Offline
                  E Offline
                  erikalxq
                  wrote on last edited by
                  #8

                  The method http://qt-project.org/forums/viewthread/29592 provided did works!
                  Here is my conclusion:
                  To add your own library into android application with Qt for Android:
                  1、Copy your libraries into the folder "android/libs"

                  2、If your application implicit dependent on the libraries, u have to modify the pro file, add " LIBS += -L"path of the lib" -llibname "

                  3、Modify "android/res/values/libs.xml".
                  Add the following:
                  @<array name="any_name_you_want">
                  <item>yourlibName</item>
                  </array>@

                  4、Modify "androidManifest.xml"
                  replace the lines:
                  @<meta-data android:name="android.app.bundled_libs_resource_id" android:resource="@array/bundled_libs"/>@
                  with
                  @<meta-data android:name="android.app.bundled_libs_resource_id" android:resource="@array/any_name_you_want"/>@

                  The reason why we don't use bundled_libs to add our libraries is everytime we deploy the app, Qt will replace the bundled_libs in libs.xml with its own data, I don't know if this is a bug or something else.

                  5、Now it should be ok to load your libraries in app.

                  zappy.mansZ 1 Reply Last reply
                  0
                  • E erikalxq

                    The method http://qt-project.org/forums/viewthread/29592 provided did works!
                    Here is my conclusion:
                    To add your own library into android application with Qt for Android:
                    1、Copy your libraries into the folder "android/libs"

                    2、If your application implicit dependent on the libraries, u have to modify the pro file, add " LIBS += -L"path of the lib" -llibname "

                    3、Modify "android/res/values/libs.xml".
                    Add the following:
                    @<array name="any_name_you_want">
                    <item>yourlibName</item>
                    </array>@

                    4、Modify "androidManifest.xml"
                    replace the lines:
                    @<meta-data android:name="android.app.bundled_libs_resource_id" android:resource="@array/bundled_libs"/>@
                    with
                    @<meta-data android:name="android.app.bundled_libs_resource_id" android:resource="@array/any_name_you_want"/>@

                    The reason why we don't use bundled_libs to add our libraries is everytime we deploy the app, Qt will replace the bundled_libs in libs.xml with its own data, I don't know if this is a bug or something else.

                    5、Now it should be ok to load your libraries in app.

                    zappy.mansZ Offline
                    zappy.mansZ Offline
                    zappy.mans
                    wrote on last edited by
                    #9

                    @erikalxq Where to place the header file (*.h) ?

                    jsulmJ 1 Reply Last reply
                    0
                    • zappy.mansZ zappy.mans

                      @erikalxq Where to place the header file (*.h) ?

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @zappy-mans said in [Solved][Qt][Android]How can i add my own (librarys)*.so files into apk and use them?:

                      Where to place the header file (*.h) ?

                      Where you like.
                      Then use https://doc.qt.io/qt-6/qmake-variable-reference.html#includepath variable in your pro file to tell qmake where to find them.

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved