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. Java compilation on Android
Forum Updated to NodeBB v4.3 + New Features

Java compilation on Android

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
8 Posts 4 Posters 801 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.
  • S Offline
    S Offline
    sandro4912
    wrote on last edited by
    #1

    I want to understand what happens when I compile a QT/QML Application for Android.

    From what I get from this site in the docs:

    https://doc.qt.io/qt-5/deployment-android.html#java-code

    So does the Javacode call the C++ functions?

    Or

    Does all the application get compiled into Java?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Does all the application get compiled into Java?

      No.

      Your c++ code is compiled using a normal c++ compiler (clang) into binary form. Same as on all other platforms.

      So does the Javacode call the C++ functions?

      Android system runs the Qt5Application which is a Java "wrapper" for Qt:

      • it creates Android Activity
      • it creates a surface to draw on

      Then Qt code (c++) uses that surface to draw your QtWidgets or QML UI into a texture - which is then drawn in the Android activity.

      So the Java code contained in Qt templates is just a thin interface between Qt platform abstractions and what Android OS expects to see.

      In your apps, you can use C++ to write your app, and if you need to access some "deeper" native functions, you can call Java through JNI.

      (Z(:^

      S 1 Reply Last reply
      4
      • sierdzioS sierdzio

        Does all the application get compiled into Java?

        No.

        Your c++ code is compiled using a normal c++ compiler (clang) into binary form. Same as on all other platforms.

        So does the Javacode call the C++ functions?

        Android system runs the Qt5Application which is a Java "wrapper" for Qt:

        • it creates Android Activity
        • it creates a surface to draw on

        Then Qt code (c++) uses that surface to draw your QtWidgets or QML UI into a texture - which is then drawn in the Android activity.

        So the Java code contained in Qt templates is just a thin interface between Qt platform abstractions and what Android OS expects to see.

        In your apps, you can use C++ to write your app, and if you need to access some "deeper" native functions, you can call Java through JNI.

        S Offline
        S Offline
        sandro4912
        wrote on last edited by
        #3

        @sierdzio Thanks for the explanation.

        What is JNI ?

        jsulmJ 1 Reply Last reply
        0
        • S sandro4912

          @sierdzio Thanks for the explanation.

          What is JNI ?

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

          @sandro4912 Easy to find with Google: https://en.wikipedia.org/wiki/Java_Native_Interface

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

          1 Reply Last reply
          3
          • sierdzioS Offline
            sierdzioS Offline
            sierdzio
            Moderators
            wrote on last edited by
            #5

            And Qt has a short tutorial on how to use it, too: https://doc.qt.io/qt-5/qandroidjniobject.html

            (Z(:^

            1 Reply Last reply
            2
            • S Offline
              S Offline
              sandro4912
              wrote on last edited by
              #6

              Sorry to ask more questions but I really have to be sure.

              Does it mean that technically the app runs as an Java app on a JVM which calls the C++ part as a library?

              And what about the QML Files how are they interpreted to Java?

              raven-worxR sierdzioS 2 Replies Last reply
              0
              • S sandro4912

                Sorry to ask more questions but I really have to be sure.

                Does it mean that technically the app runs as an Java app on a JVM which calls the C++ part as a library?

                And what about the QML Files how are they interpreted to Java?

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

                @sandro4912
                since ANdroid is a Linux derivat (if you want so) your app runs like a normal C++ app. And JAVA interfaces with native (C/C++) via JNI. Your Android App is not 100% JAVA in the end.

                --- 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
                2
                • S sandro4912

                  Sorry to ask more questions but I really have to be sure.

                  Does it mean that technically the app runs as an Java app on a JVM which calls the C++ part as a library?

                  And what about the QML Files how are they interpreted to Java?

                  sierdzioS Offline
                  sierdzioS Offline
                  sierdzio
                  Moderators
                  wrote on last edited by
                  #8

                  @sandro4912 said in Java compilation on Android:

                  And what about the QML Files how are they interpreted to Java?

                  Java does not know about QML, that is handled only by C++.

                  (Z(:^

                  1 Reply Last reply
                  1

                  • Login

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