Qt Android set package name through Gradle or .pro file?
-
wrote on 18 Oct 2021, 11:56 last edited by
Hey there :D
I am trying to split our Android app project into two builds: one for the Google Play Store and one for Huawei App Gallery (because AG needs a .huawei package name ending for apps).
Because I wasn't able to find a good documented way on best practices for this (and didn't manage to get product Flavours working) I started fiddling around within Gradle:
I am able to specify a variable in Gradle:
project.ext.androidStore = "Huawei" // or "Google"
to be able to set the application id and specify plugin applications on the bottom:
if (androidStore == "Huawei") { //applicationIdSuffix ".huawei" applicationId "com.company.app.huawei" } else { applicationId "com.company.app" } ... // apply platform provider plugin, should be at the bottom if (androidStore == "Huawei") { apply plugin: 'com.huawei.agconnect' } else { apply plugin: 'com.google.gms.google-services' }
During runtime I am able to request the compiled store version by checking the package name:
public String getStorePlatform() { // if ends with huawei -> Huawei, else Google if (Application.getContext().getPackageName().endsWith("huawei")) { return "Huawei"; } return "Google"; }
But this way, I have to specify my "build target" in 3 files,
-
the build.gradle,
-
the .pro file where I set the BUNDLE ids (don't know if all other the values as necessary):
QMAKE_TARGET_BUNDLE_PREFIX = com.company QMAKE_BUNDLE = app VERSION = 1.0 BUILD = 1000 # change bundle id here, in build.gradle and AndroidManifest.xml #BUNDLE_ID = com.company.app BUNDLE_ID = com.company.app.huawei # Make the variable APP_VERSION and APP_BUILD available in C++ DEFINES += APP_VERSION=$$VERSION \ APP_BUILD=$$BUILD \ APP_BUNDLE=$$BUNDLE_ID \
- and in the android manifest:
<?xml version="1.0"?> <!-- change bundle id here, in build.gradle and .pro file --> <manifest package="com.company.app.huawei" xmlns:android...> <!-- <manifest package="com.company.app" xmlns:android...> -->
My Question is, is there any way to provide the app and package identifier from only one source (either through Gradle or Qt Project file) ?
-
-
wrote on 18 Oct 2021, 14:19 last edited by
We are using CMake for our Android project and have two different packages using Gradle:
// Example ... defaultConfig { applicationId 'com.domain.host' ... applicationIdSuffix '.suffix' ... }
And one default value which isn't changed in manifest:
<manifest package="com.domain.host" xmlns:android...
So, both applications can be installed at same device.
-
wrote on 18 Oct 2021, 15:42 last edited by
Thanks for your reply @IntruderExcluder :D
just specify the package name and applying a suffix through Gradle seems to work!
Maybe you (or anyone else) can provide some info on how the order of values is, regarding the Qt Project file, Gradle and AndroidManifest?
Is the AndroidManifest generated with values specified in the .pro file and than used and updated/merged per Gradle? -
wrote on 25 Oct 2021, 12:45 last edited by
The only problem, I encountered so far, is that if I have two apps (the same build, but one with an additional applicationIdSuffix) installed on the device and try to deploy and run from within Qt Creator, the one without the suffix is started. If there is only the suffix-app installed, deploy and run does nothing :/
Is there any way to specify which app to start from the Qt settings?
best regards
Michael
1/4