6

I use the following build.gradle to generate .apk files, the result will be MagnifyingGlass-V1.01-free-release.apk for free edition and MagnifyingGlass-V1.01-pro-release.apk for pro edition. -free-release or -pro-release is added to filename as suffix automatically by Android Studio 3.4.2.

I try to use the same build.gradle to generate .aab files, I find the result is MagnifyingGlass-V1.01 for free and MagnifyingGlass-V1.01 for pro, there are same, why? -free-release or -pro-release isn't added to filename as suffix automatically by Android Studio 3.4.2.

Added content:

I generated different edition .apk and .aab using Android Studio just like Image 1.

build.gradle

android {
    compileSdkVersion 28
    flavorDimensions "default"

    defaultConfig {
        applicationId "info.dodata.magnifyingglass"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 2
        versionName "1.02"
        archivesBaseName = "MagnifyingGlass-V" + versionName
    }

    productFlavors {
        free {
            applicationId "info.dodata.magnifyingglass"
        }

        pro {
            applicationId "info.dodata.magnifyingglass.pro"
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            buildConfigField "boolean", "IsDebugMode", "false"
        }

        debug {
            buildConfigField "boolean", "IsDebugMode", "true"
        }
    }

}

Image 1 enter image description here

HelloCW
  • 843
  • 22
  • 125
  • 310

2 Answers2

2

This is because the name of the bundle is being rigidly applied (there might be a relevant ticket available on the issue-tracker). Once left a workaround here: How to change the generated filename for App Bundles with Gradle?

This approach can also be used to finalize these flavors, based upon their final task's name. Another optimization would be, to use the Apache Ant integration on the generated bundle. For some reason (unknown to me), Gradle does not support move (rename) operations out-of-the-box.

This configuration appears pretty useless (and there might be other configurations missing):

buildConfigField "boolean", "IsDebugMode", "true"

because in Java that is known as BuildConfig.DEBUG; better replace that with configuration applicationIdSuffix ".debug" - and also add the corresponding applicationIdSuffix ".release" (which rather sounds alike the intended outcome); for example:

buildTypes {
    release {
        applicationIdSuffix ".release"
        ...
    }

    debug {
        applicationIdSuffix ".debug"
        ...
    }
}
Martin Zeitler
  • 1
  • 19
  • 155
  • 216
  • Thanks! Could you show some code? I only publish release edition for both free and pro. – HelloCW Jul 22 '19 at 01:13
  • The problem I met is : Android Studio can automatically add -free-release or -pro-release suffix for free or pro edition when I generate .apk file, but Android Studio doesn't add -free-release or -pro-release suffix for free or pro edition when I generate .aab file – HelloCW Jul 22 '19 at 01:17
  • And more, I test your code, the 4 filenames (MagnifyingGlass-V1.01-free-release.apk, MagnifyingGlass-V1.01-pro-release.apk , MagnifyingGlass-V1.01,MagnifyingGlass-V1.01) haven't any change. – HelloCW Jul 22 '19 at 02:11
  • @HelloCW this does not affect the `.aab` the least and I won't copy and paste my own answer. The configuration above at least fixes the filenames for the `.apk`. The first line reads: *the name of the bundle is being rigidly applied*. Your so called "debug" build doesn't even have configuration `debuggable true`. I'd suggest to first make it working for debug/release mode and the add the flavors - not the other way around. Yesterday seen a bug on the issue tracker, that building `.aab` even removes other files in the output directory, which could interfere - unless moving the files elsewhere. – Martin Zeitler Jul 22 '19 at 12:21
  • Thanks! you are right, I will remove `buildConfigField "boolean", "IsDebugMode", "true"` because `BuildConfig.DEBUG` can return correct result. – HelloCW Jul 22 '19 at 13:20
  • And more, what I need to get different `.aab` filename when Android Studio generate free edition and pro edition under release buildTypes. Do you mean that it's a bug of gradle? – HelloCW Jul 22 '19 at 13:24
  • [How to change the generated filename for App Bundles with Gradle?](https://stackoverflow.com/questions/52508720/how-to-change-the-generated-filename-for-app-bundles-with-gradle/52521936#52521936) only generate different filename for Release and Debug buildType, what I need to get different filename for Free and Pro edition under Release buildType. – HelloCW Jul 22 '19 at 13:36
  • @HelloCW I've already explain this above and I won't spoon you. as the question is written, with these mis-configured build-types, this is even barely reproducible and I'm probably too lazy to support your laziness. With the information provided, this shouldn't be too difficult. – Martin Zeitler Jul 22 '19 at 13:38
  • Thanks! Sorry for poor English, I hope to confirm whether that is a bug all filenames are same when generate .`aab` files. – HelloCW Jul 23 '19 at 00:46
1

This is now available in gradle version 3.5.2 where the product flavor suffix is applied automatically.

shubhamgarg1
  • 1,619
  • 1
  • 15
  • 20