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?
Forum Updated to NodeBB v4.3 + New Features

How to get the version number of android app?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
14 Posts 4 Posters 5.7k Views 3 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.
  • SGaistS SGaist

    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 last edited by Dmitriano
    #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
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on 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
      0
      • SGaistS SGaist

        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 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
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on 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

          mzimmersM 1 Reply Last reply
          0
          • SGaistS SGaist

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

            mzimmersM Offline
            mzimmersM Offline
            mzimmers
            wrote on 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.

            SGaistS 1 Reply Last reply
            0
            • mzimmersM mzimmers

              @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.

              SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on 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

              mzimmersM 1 Reply Last reply
              0
              • SGaistS SGaist

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

                mzimmersM Offline
                mzimmersM Offline
                mzimmers
                wrote on 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.

                SGaistS 1 Reply Last reply
                0
                • mzimmersM mzimmers

                  @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.

                  SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 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

                  mzimmersM 1 Reply Last reply
                  0
                  • SGaistS SGaist

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

                    mzimmersM Offline
                    mzimmersM Offline
                    mzimmers
                    wrote on 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
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 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
                      • mzimmersM mzimmers

                        @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 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.9 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