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. Android library with java code
QtWS25 Last Chance

Android library with java code

Scheduled Pinned Locked Moved Solved Mobile and Embedded
android libraryjava
5 Posts 2 Posters 2.9k 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.
  • F Offline
    F Offline
    Ferni
    wrote on 11 May 2017, 13:30 last edited by Ferni 5 Nov 2017, 13:31
    #1

    Hi guys!

    I have a simple question that I couldn't be able yet to figure it out. I have my Android application and I want to create many library for specific functions (GPS, Network, etc). I'd like to modularize these modules into .so libraries but I'm not sure how to include my java code in a library project. Is this even possible?

    I took QtNotifier as example and had no problem to add my file and make calls from C++ to Java and from Java to C++. Therefore, my question is only about .pro configuration.

    I set ANDROID_PACKAGE_SOURCE_DIR and DISTFILES but there is no trace in Compile Output of my java file :/
    I added some errors to this file and QtCreator doesn't even notice that the file will not compile.

    Could someone guide me with this problem? Am I taking a good decision about architecture of my Android application?

    Thanks in advance,
    Fernando

    1 Reply Last reply
    0
    • B Offline
      B Offline
      benlau
      Qt Champions 2016
      wrote on 11 May 2017, 14:00 last edited by
      #2

      Unless you write your Android function in JNI completely, it is not possible to bundle native Java source within .so file. Or you may build a .jar file together with .so .

      1 Reply Last reply
      0
      • F Offline
        F Offline
        Ferni
        wrote on 11 May 2017, 14:15 last edited by
        #3

        @benlau thanks for the reply!!

        I'm thinking about having a common folder for Java sources and include it from my application. Will the java code be accessible from all the C++ modules? I mean, can I use the methods from Java classes in my libraries?

        1 Reply Last reply
        0
        • B Offline
          B Offline
          benlau
          Qt Champions 2016
          wrote on 11 May 2017, 14:24 last edited by
          #4

          You need to tell where is your Java files by configure your build.gradle .

          For example, you may add your Java file path to java.srcDirs in build.gradle

              sourceSets {
                  main {
                      manifest.srcFile 'AndroidManifest.xml'
                      java.srcDirs = [qt5AndroidDir + '/src', 'src', 'java']
                      aidl.srcDirs = [qt5AndroidDir + '/src', 'src', 'aidl']
                      res.srcDirs = [qt5AndroidDir + '/res', 'res']
                      resources.srcDirs = ['src']
                      renderscript.srcDirs = ['src']
                      assets.srcDirs = ['assets']
                      jniLibs.srcDirs = ['libs']
                 }
          
          1 Reply Last reply
          1
          • F Offline
            F Offline
            Ferni
            wrote on 11 May 2017, 15:09 last edited by
            #5

            @benlau

            Thanks for answering my question!!! I could solve it :D

            1 Reply Last reply
            0

            1/5

            11 May 2017, 13:30

            • Login

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