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. Qt Android set package name through Gradle or .pro file?
Forum Update on Monday, May 27th 2025

Qt Android set package name through Gradle or .pro file?

Scheduled Pinned Locked Moved Solved Mobile and Embedded
4 Posts 2 Posters 1.3k 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.
  • SyntaXS Offline
    SyntaXS Offline
    SyntaX
    wrote on last edited by
    #1

    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) ?

    1 Reply Last reply
    0
    • IntruderExcluderI Offline
      IntruderExcluderI Offline
      IntruderExcluder
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      1
      • SyntaXS Offline
        SyntaXS Offline
        SyntaX
        wrote on last edited by
        #3

        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?

        1 Reply Last reply
        0
        • SyntaXS Offline
          SyntaXS Offline
          SyntaX
          wrote on last edited by
          #4

          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 Reply Last reply
          0

          • Login

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