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 get the version number of android app?

How to get the version number of android app?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
14 Posts 4 Posters 5.5k 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.
  • D Dmitriano
    3 Sept 2017, 14:00

    I have QT 5.8 QML application with the standard Android manifest containing the app version number that I edit in QtCreator. Is there a way to access this app version version from C++ or should I use JNI with Java code provided here, for example: https://stackoverflow.com/questions/4616095/how-to-get-the-build-version-number-of-your-android-application ?

    D Offline
    D Offline
    Dmitriano
    wrote on 3 Sept 2017, 14:18 last edited by Dmitriano 9 Mar 2017, 20:41
    #2

    In QT 5.9 (see https://bugreports.qt.io/browse/QTBUG-57715) the function

    QCoreApplication::applicationVersion()
    

    returns only the version name that is 1.0, but I need full version with version code that is 1.0.11. So the question is how to access the version code?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 3 Sept 2017, 22:18 last edited by
      #3

      Hi,

      Might be a silly question but did you check the content of your AndroidManifest.xml file ?

      Also, where are you setting this version number ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      D 1 Reply Last reply 4 Sept 2017, 09:31
      0
      • S SGaist
        3 Sept 2017, 22:18

        Hi,

        Might be a silly question but did you check the content of your AndroidManifest.xml file ?

        Also, where are you setting this version number ?

        D Offline
        D Offline
        Dmitriano
        wrote on 4 Sept 2017, 09:31 last edited by Dmitriano 9 Apr 2017, 09:31
        #4

        Hi @SGaist !
        the manifest contains this:

        <manifest package="..." xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.0" android:versionCode="11" android:installLocation="auto">
        
        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 4 Sept 2017, 10:02 last edited by
          #5

          Then what Qt returns is correct. If you want to have "1.0.11" then you have to modify the versionName value.

          versionCode is not the "patch number" of your version string. It's some sort of "build number" and it's internal. It allows google play to know that you are publishing a new version of your application and it's independent of the versionName.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          D 1 Reply Last reply 4 Sept 2017, 11:54
          0
          • S SGaist
            4 Sept 2017, 10:02

            Then what Qt returns is correct. If you want to have "1.0.11" then you have to modify the versionName value.

            versionCode is not the "patch number" of your version string. It's some sort of "build number" and it's internal. It allows google play to know that you are publishing a new version of your application and it's independent of the versionName.

            D Offline
            D Offline
            Dmitriano
            wrote on 4 Sept 2017, 11:54 last edited by
            #6

            @SGaist yes that all is correct, but whatever the version code is, I need it to show in app About dialog, even if it is the build number. So looks like JNI is the only option, right? Assuming that I do not know the version code in C++ and can not call setApplicationVersion("1.10.11"), but I should get the version name and version code from the manifest and then call setApplicationVersion(myver).

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 4 Sept 2017, 12:09 last edited by
              #7

              That's right. You can take a look a QCoreApplication sources to see how you can to that pretty easily.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              M 1 Reply Last reply 14 Feb 2023, 22:36
              0
              • S SGaist
                4 Sept 2017, 12:09

                That's right. You can take a look a QCoreApplication sources to see how you can to that pretty easily.

                M Offline
                M Offline
                mzimmers
                wrote on 14 Feb 2023, 22:36 last edited by
                #8

                @SGaist I know this thread is ancient, but the app I'm building runs on Android and desktop. Is there a way to retrieve the version name in the manifest when built for desktop? Other than opening the file and parsing it, of course.

                S 1 Reply Last reply 15 Feb 2023, 20:17
                0
                • M mzimmers
                  14 Feb 2023, 22:36

                  @SGaist I know this thread is ancient, but the app I'm building runs on Android and desktop. Is there a way to retrieve the version name in the manifest when built for desktop? Other than opening the file and parsing it, of course.

                  S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 15 Feb 2023, 20:17 last edited by
                  #9

                  @mzimmers wouldn't applicationVersion do what you need automatically ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  M 1 Reply Last reply 15 Feb 2023, 20:19
                  0
                  • S SGaist
                    15 Feb 2023, 20:17

                    @mzimmers wouldn't applicationVersion do what you need automatically ?

                    M Offline
                    M Offline
                    mzimmers
                    wrote on 15 Feb 2023, 20:19 last edited by
                    #10

                    @SGaist not exactly, at least not according to my (brief) test results. When built for desktop, it seems to ignore the contents of the Android manifest file (logical enough) so it doesn't pick up the version from there.

                    The goal would be to have a single place for the version number, irrespective of which platform I'm building for.

                    S 1 Reply Last reply 15 Feb 2023, 20:22
                    0
                    • M mzimmers
                      15 Feb 2023, 20:19

                      @SGaist not exactly, at least not according to my (brief) test results. When built for desktop, it seems to ignore the contents of the Android manifest file (logical enough) so it doesn't pick up the version from there.

                      The goal would be to have a single place for the version number, irrespective of which platform I'm building for.

                      S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 15 Feb 2023, 20:22 last edited by
                      #11

                      @mzimmers if using qmake, the VERSION variable would do what you want.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      M 1 Reply Last reply 15 Feb 2023, 20:23
                      0
                      • S SGaist
                        15 Feb 2023, 20:22

                        @mzimmers if using qmake, the VERSION variable would do what you want.

                        M Offline
                        M Offline
                        mzimmers
                        wrote on 15 Feb 2023, 20:23 last edited by
                        #12

                        @SGaist I'm using CMake.

                        Maybe this isn't really a good idea anyway. This is the first app I've built for multiple platforms. Do people generally keep the version numbers the same between platforms, or are they permitted to change individually?

                        ekkescornerE 1 Reply Last reply 17 Feb 2023, 15:30
                        0
                        • S Offline
                          S Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on 15 Feb 2023, 20:36 last edited by
                          #13

                          @mzimmers it will depend on several factors.
                          For example you could have a project with a set of core libraries and one application per platform as it could contain some customization pertaining to the mobile world. That would justify a different version number as they would develop at a different pace. If you have one single application then keep one version number.
                          I do not know whether the current cmake support allows to set the version once but I would guess it should. If that value must be manually adjusted for some reason, I would write a small helper script that automates this process.

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          0
                          • M mzimmers
                            15 Feb 2023, 20:23

                            @SGaist I'm using CMake.

                            Maybe this isn't really a good idea anyway. This is the first app I've built for multiple platforms. Do people generally keep the version numbers the same between platforms, or are they permitted to change individually?

                            ekkescornerE Offline
                            ekkescornerE Offline
                            ekkescorner
                            Qt Champions 2016
                            wrote on 17 Feb 2023, 15:30 last edited by
                            #14

                            @mzimmers I'm always using variables in Android Manifest:

                            android:versionName="-- %%INSERT_VERSION_NAME%% --" android:versionCode="-- %%INSERT_VERSION_CODE%% --"
                            

                            in my qmake .pro:

                            ANDROID_VERSION_NAME = ...
                            ANDROID_VERSION_CODE = ...
                            

                            I'm sure something similar should exist for cmake
                            ask me again in some weeks, when I ported my apps to Qt 6.5 and then switch to cmake. Or probably I'll ask here ;-)

                            ekke ... Qt Champion 2016 | 2024 ... mobile business apps
                            5.15 --> 6.8 https://t1p.de/ekkeChecklist
                            QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

                            1 Reply Last reply
                            2

                            • Login

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