1

I am working on making a large project modular. I have separated the code and layout files and everything is working fine except one issue.

I needed to create 3 build types in the module namely, beta, stage and live (for a reason mentioned later). Now there is one thing I couldn't understand.

  • When running from Android Studio directly I can select which build variant of the library module to use while building. but
  • When generating a signed apk, it doesn't ask for the build type of the library.

There must be some

  • defaults which could be set in order to configure this. I am looking for those config options which can be used and
  • Which build type of the library is by default selected when generating signed apk ?

The reason I created build variants within the library module is that I am using Content Provider in the module and I was CONTENT_PROVIDER_AUTHORITY_CONFLICT error on installing multiple build types simultaneously in the same device.

So in order to install beta, stage and live builds simultaneously I added the Content Authority as a string resource in the build.gradle

apply plugin: 'com.android.library'
android {
compileSdkVersion Integer.parseInt(project.COMPILE_SDK_VERSION)
buildToolsVersion project.BUILD_TOOLS_VERSION
defaultConfig {
    minSdkVersion Integer.parseInt(project.MIN_SDK_VERSION)
    targetSdkVersion Integer.parseInt(project.TARGET_SDK_VERSION)
    vectorDrawables.useSupportLibrary true
}
buildTypes {
beta {
        minifyEnabled false
        resValue("string", "account_type", "com.****.****.dev")
        resValue("string", "_authority", "com.****.****.dev.syncadapter.finance")
        buildConfigField "String", "FinanceContentProvider", "\"com.****.****.dev.syncadapter.finance\""
    }
    staging {
        minifyEnabled false
        resValue("string", "account_type", "com.****.****.stage")
        resValue("string", "_authority", "com.****.****.stage.syncadapter.finance")
        buildConfigField "String", "FinanceContentProvider", "\"com.****.****.stage.syncadapter.finance\""
    }
    live {
        minifyEnabled false
        resValue("string", "account_type", "com.****.****.live")
        resValue("string", "_authority", "com.****.****.live.syncadapter.finance")
        buildConfigField "String", "FinanceContentProvider", "\"com.****.****.syncadapter.finance\""
SMagic
  • 317
  • 2
  • 10

1 Answers1

0

You need to use this below build types:

flavorDimensions 'tier'
    productFlavors {

        beta {
            buildConfigField("Your_field", "Data", "Data")
        }
        staging {
              buildConfigField("Your_field", "Data", "Data")
        }
        live {
              buildConfigField("Your_field", "Data", "Data")
              }

        android.applicationVariants.all { variant ->
            variant.outputs.all {
                outputFileName = "AppName_${variant.productFlavors[0].name}-${buildType.name}-${defaultConfig.versionCode}.apk"
            }
        }

    }

Hope this helps.