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. How to include C++ static libraries into the android apk of a QtApp, when building with Gradle
QtWS25 Last Chance

How to include C++ static libraries into the android apk of a QtApp, when building with Gradle

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
14 Posts 2 Posters 4.8k Views
  • 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.
  • N Offline
    N Offline
    Nelson_Piquet
    wrote on last edited by
    #1

    I am using a QtApp on android. I have a few C++ static libraries linking to my app each having a .pro file in them. I need to use gradle to build my app. The app builds fine using my build.gradle & creates an apk. But when I launch the app on device, it crashes !! Mostly, the reason is that my static libs are not getting added to the apk.

    Following is my build.gradle file

    apply plugin: 'com.android.application'
    apply plugin: 'maven'

    buildscript {
    repositories {
    maven {
    url "http://repo1.maven.org/maven2"
    }
    }
    dependencies {
    classpath 'com.android.tools.build:gradle:2.1.3'
    }
    }

    android {
    compileSdkVersion 24
    buildToolsVersion "24.0.0"

    sourceSets {
        main {
            jniLibs.srcDirs = ['libs']
        }
    }
    

    }
    The section jniLibs.srcDirs = ['libs'] nicely picks up the Qt related .so libs but it is missing my static libs as I see in the build log.

    So my question is : How can add my static libs to build.gradle so that gradle includes my static libs into the built apk?

    raven-worxR 1 Reply Last reply
    0
    • N Nelson_Piquet

      I am using a QtApp on android. I have a few C++ static libraries linking to my app each having a .pro file in them. I need to use gradle to build my app. The app builds fine using my build.gradle & creates an apk. But when I launch the app on device, it crashes !! Mostly, the reason is that my static libs are not getting added to the apk.

      Following is my build.gradle file

      apply plugin: 'com.android.application'
      apply plugin: 'maven'

      buildscript {
      repositories {
      maven {
      url "http://repo1.maven.org/maven2"
      }
      }
      dependencies {
      classpath 'com.android.tools.build:gradle:2.1.3'
      }
      }

      android {
      compileSdkVersion 24
      buildToolsVersion "24.0.0"

      sourceSets {
          main {
              jniLibs.srcDirs = ['libs']
          }
      }
      

      }
      The section jniLibs.srcDirs = ['libs'] nicely picks up the Qt related .so libs but it is missing my static libs as I see in the build log.

      So my question is : How can add my static libs to build.gradle so that gradle includes my static libs into the built apk?

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @Nelson_Piquet
      a static lib is already included into your binary at link time, otherwise you would already have an error there.
      So you should debug your crash using the debugger.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      N 2 Replies Last reply
      2
      • raven-worxR raven-worx

        @Nelson_Piquet
        a static lib is already included into your binary at link time, otherwise you would already have an error there.
        So you should debug your crash using the debugger.

        N Offline
        N Offline
        Nelson_Piquet
        wrote on last edited by
        #3

        @raven-worx Good point. I will be glad if I don't have to do anything special for the static libs. I am looking through the logcat of my android device to analyze.

        Btw, following is the apk creation step in my build-script with --gradle, Is there anything wrong you see ?

        androiddeployqt --sign mykeystore myKeyalias --storepass myPassword --gradle clean build --output android --verbose --input android-libMyQtApp.so-deployment-settings.json

        Can I add something more to correct my build ? Is there anything wrong you see ?

        1 Reply Last reply
        0
        • raven-worxR raven-worx

          @Nelson_Piquet
          a static lib is already included into your binary at link time, otherwise you would already have an error there.
          So you should debug your crash using the debugger.

          N Offline
          N Offline
          Nelson_Piquet
          wrote on last edited by Nelson_Piquet
          #4

          @raven-worx My app is running all fine when built with ant. it started to crash only after building with gradle

          raven-worxR 1 Reply Last reply
          0
          • N Nelson_Piquet

            @raven-worx My app is running all fine when built with ant. it started to crash only after building with gradle

            raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by
            #5

            @Nelson_Piquet
            check the catlog. Ther should be more info what exactly caused the crash and where.

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            N 1 Reply Last reply
            1
            • raven-worxR raven-worx

              @Nelson_Piquet
              check the catlog. Ther should be more info what exactly caused the crash and where.

              N Offline
              N Offline
              Nelson_Piquet
              wrote on last edited by
              #6

              @raven-worx Following is the crash log I am getting:

              handle_notify_event, send msg [submit:trigger=0,bugtype=2,modulename=com.mycompany.myapp,level=1,testtype=NORMAL,path=/data/log/unzip/GRA-L09_GRA-L09C432B321a_0000000000_20161014165530_crash,mode=1;]
              10-14 16:55:30.825 3199 3436 I logserver: send_to_client, send to (9) res = 188
              10-14 16:55:30.844 3443 3462 W System.err: java.lang.NullPointerException: Attempt to invoke virtual method 'int com.huawei.lcagent.client.LogCollectManager.getUserType()' on a null object reference
              10-14 16:55:30.844 3443 3462 W System.err: at com.android.server.util.ReportTools.getUserType(ReportTools.java:86)
              10-14 16:55:30.844 3443 3462 W System.err: at com.android.server.util.ReportTools.isBetaUser(ReportTools.java:73)
              10-14 16:55:30.844 3443 3462 W System.err: at com.android.server.util.ReportTools.report(ReportTools.java:58)
              10-14 16:55:30.844 3443 3462 W System.err: at com.android.server.util.HwUserBehaviourRecord.appExitRecord(HwUserBehaviourRecord.java:65)
              10-14 16:55:30.844 3443 3462 W System.err: at com.android.server.am.ActivityManagerService$UiHandler.handleMessage(ActivityManagerService.java:1521)
              10-14 16:55:30.844 3443 3462 W System.err: at android.os.Handler.dispatchMessage(Handler.java:102)
              10-14 16:55:30.844 3443 3462 W System.err: at android.os.Looper.loop(Looper.java:150)
              10-14 16:55:30.844 3443 3462 W System.err: at android.os.HandlerThread.run(HandlerThread.java:61)
              10-14 16:55:30.844 3443 3462 W System.err: at com.android.server.ServiceThread.run(ServiceThread.java:46)
              10-14 16:55:30.844 3443 3462 E ReportTools: This is not beta user build

              1 Reply Last reply
              0
              • N Offline
                N Offline
                Nelson_Piquet
                wrote on last edited by
                #7

                Checked the catlog in another android device with better logging. Following is the cause of the crash

                Caused by: java.lang.ClassNotFoundException: Didn't find class "org.qtproject.qt5.android.bindings.QtApplication" on path: DexPathList[[zip file "/data/app/com.mycompany.myapp-2/base.apk"],nativeLibraryDirectories=[/data/app/com.mycompany.myapp-2/lib/arm, /data/app/com.mycompany.myapp-2/base.apk!/lib/armeabi-v7a, /vendor/lib, /system/lib]]

                Not sure what I am doing wrong here

                raven-worxR 1 Reply Last reply
                0
                • N Nelson_Piquet

                  Checked the catlog in another android device with better logging. Following is the cause of the crash

                  Caused by: java.lang.ClassNotFoundException: Didn't find class "org.qtproject.qt5.android.bindings.QtApplication" on path: DexPathList[[zip file "/data/app/com.mycompany.myapp-2/base.apk"],nativeLibraryDirectories=[/data/app/com.mycompany.myapp-2/lib/arm, /data/app/com.mycompany.myapp-2/base.apk!/lib/armeabi-v7a, /vendor/lib, /system/lib]]

                  Not sure what I am doing wrong here

                  raven-worxR Offline
                  raven-worxR Offline
                  raven-worx
                  Moderators
                  wrote on last edited by
                  #8

                  @Nelson_Piquet
                  did you create the Android tempaltes (as described here) so that the android classes are also deployed?

                  --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                  If you have a question please use the forum so others can benefit from the solution in the future

                  1 Reply Last reply
                  0
                  • N Offline
                    N Offline
                    Nelson_Piquet
                    wrote on last edited by
                    #9

                    I have the Androidmanifest file & the res folder inside MyAppfolder/android with ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android in MyApp.pro set. However, I have to move the manifest file 6 res folder inside MyAppfolder/android/src/main for gradle to build without issues.

                    1 Reply Last reply
                    0
                    • N Offline
                      N Offline
                      Nelson_Piquet
                      wrote on last edited by
                      #10

                      by the way, I am doing this build command line using the following install step

                      androiddeployqt --sign mykeystore.keystore myAlias --storepass myPassword --gradle clean build --output android --verbose --input android-libMyApp.so-deployment-settings.json

                      raven-worxR 1 Reply Last reply
                      0
                      • N Nelson_Piquet

                        by the way, I am doing this build command line using the following install step

                        androiddeployqt --sign mykeystore.keystore myAlias --storepass myPassword --gradle clean build --output android --verbose --input android-libMyApp.so-deployment-settings.json

                        raven-worxR Offline
                        raven-worxR Offline
                        raven-worx
                        Moderators
                        wrote on last edited by
                        #11

                        @Nelson_Piquet
                        so you are not using QtCreator?

                        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                        If you have a question please use the forum so others can benefit from the solution in the future

                        N 1 Reply Last reply
                        0
                        • raven-worxR raven-worx

                          @Nelson_Piquet
                          so you are not using QtCreator?

                          N Offline
                          N Offline
                          Nelson_Piquet
                          wrote on last edited by
                          #12

                          @raven-worx In my team all use QtCreator including me as well. But, we need to make a build-script for jenkins & Continious Integration.

                          The build-script builds successfully when built with ant that comes by default with androiddeployqt We need the android part to build using gradle. Hence, I have appended this --gradle to androiddeployqt command & trying to build this with gradle.

                          Again, the reason of trying to use gradle here is for versioning. If you google how to auto-increment version number of android app, then everybody suggests to do it with gradle. I dont know why ? Everybody suggest to move on to gradle in the android community specially. May be there are other reasons as well. At the moment I am just trying to build our QtApp using gradle

                          raven-worxR 1 Reply Last reply
                          0
                          • N Nelson_Piquet

                            @raven-worx In my team all use QtCreator including me as well. But, we need to make a build-script for jenkins & Continious Integration.

                            The build-script builds successfully when built with ant that comes by default with androiddeployqt We need the android part to build using gradle. Hence, I have appended this --gradle to androiddeployqt command & trying to build this with gradle.

                            Again, the reason of trying to use gradle here is for versioning. If you google how to auto-increment version number of android app, then everybody suggests to do it with gradle. I dont know why ? Everybody suggest to move on to gradle in the android community specially. May be there are other reasons as well. At the moment I am just trying to build our QtApp using gradle

                            raven-worxR Offline
                            raven-worxR Offline
                            raven-worx
                            Moderators
                            wrote on last edited by
                            #13

                            @Nelson_Piquet
                            IIRC Qtcreator shows the build command in the console during the build

                            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                            If you have a question please use the forum so others can benefit from the solution in the future

                            N 1 Reply Last reply
                            0
                            • raven-worxR raven-worx

                              @Nelson_Piquet
                              IIRC Qtcreator shows the build command in the console during the build

                              N Offline
                              N Offline
                              Nelson_Piquet
                              wrote on last edited by
                              #14

                              @raven-worx Yeah. I got that from the compile log of qtCreator. Thats really good about Qt. The command is correctly set now otherwise the build would not succeed. I think I am missing some dependency/plugin or something in build.gradle which is causing the following error & crashing the app on launch

                              "Didn't find class "org.qtproject.qt5.android.bindings.QtApplication" on path: DexPathList[[zip file "/data/app/com.mycompany.myapp-2/base.apk"],nativeLibraryDirectories=[/data/app/com.mycompany.myapp-2/lib/arm, /data/app/com.mycompany.myapp-2/base.apk!/lib/armeabi-v7a, /vendor/lib, /system/lib]]"

                              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