How to get the version number of android app?
-
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 ?
-
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?
-
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 ?
-
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.
-
@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).
-
That's right. You can take a look a QCoreApplication sources to see how you can to that pretty easily.
-
@mzimmers wouldn't applicationVersion do what you need automatically ?
-
@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.
-
@mzimmers if using qmake, the VERSION variable would do what you want.
-
@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?
-
@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. -
@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 ;-)