Get gradle build type in product taste

I need to create different application names depending on the taste of the product used.

Although it was easy, just setting the string resource, I can no longer do this, because when the application is loaded into hockeyapp, the application name is set to "@ string / app_name" instead of the value of app_name.

I made some progress by setting the label in the manifest as '$ {applicationName}' and setting the value with

manifestPlaceholders = [ applicationName : appName ];

in the taste block of the product, so that the value will be set at compile time.

The problem occurs when I try to add an assembly type to the application name. I cannot find a way to find out what type of assembly is currently used in the product.

This is a stripped down version of the assembly for readability.

android {
    buildVersionName "1.0.0

    buildTypes {
        release {
            ... nothing special
        }
        uat {
            signingConfig signingConfigs.debug
            buildType = "uat"
            applicationIdSuffix = "." + buildType
        }
        debug {
            signingConfig signingConfigs.debug
            buildType = "uat"
            applicationIdSuffix = "." + buildType
        }
    }
    productFlavors{
        flavor1{
            def appName = "app name " + buildType;
            manifestPlaceholders = [ applicationName : appName ];
            applicationId [id]
            def clientIteration = [client iteration]
            versionName buildVersionName + clientIteration
            versionCode [version code]
        }
        flavor2{
            ... same as above with different app name
        }
        flavor3{
            ... same as above with different app name
        }
    }
}

, , 'buildType' buildtype ( debug), , .

, , - .

+4
3

, , , - :

  productFlavors{
    flavour 1 {
        applicationId "your_app_id"
        resValue "string", "app_name", "Flavour 1 app name"
        .......
    }

    flavour 2 {
        applicationId "your_app_id"
        resValue "string", "app_name", "Flavour 2 app name"
        .......

    }
}

AndroidManifest.xml:

    android:label="@string/app_name"

, .

+3

,

   android {

    productFlavors {
        Foo {
             applicationId "com.myexample.foo"
             manifestPlaceholders = [ appName:"Foo"]
        }

        Bar {
             applicationId "com.myexample.bar"
             manifestPlaceholders = [ appName:"Bar"]
        }
    }

    buildTypes {
        release {
            manifestPlaceholders = [ appNameSuffix:""]
        }

        debug {
            manifestPlaceholders = [ appNameSuffix:".Debug"]
            applicationIdSuffix ".debug"
        }
    }
}

<application
        android:label="${appName}${appNameSuffix}"
        ...
 </application>

, :

buildTypes {
    debug{
        buildConfigField "String", "Your_string_key", '"yourkeydebugvalue"'
        buildConfigField "String", "SOCKET_URL", '"some text"'
        buildConfigField "Boolean", "LOG", 'true'
    }
    release {
        buildConfigField "String", "Your_string_key", '"yourkeyreleasevalue"'
        buildConfigField "String", "SOCKET_URL", '"release text"'
        buildConfigField "Boolean", "LOG", 'false'

    }
}

:

 if(!BuildConfig.LOG)
      // do something with the boolean value

view.setText(BuildConfig.yourkeyvalue);
+3

http://inaka.net/blog/2014/12/22/create-separate-production-and-staging-builds-in-android/ .

productFlavors (, )

:

//SRC//RES//strings.xml

<resources>
    <string name="root_url">http://production.service.com/api</string>
</resources>

//SRC//RES//strings.xml

<resources>
    <string name="root_url">http://staging.service.com/api</string>
</resources>

{}:

productFlavors {

    production {
        applicationId "com.inaka.app.production"
    }

    staging {
        applicationId "com.inaka.app.staging"
    }

}

productFlavors, .

0

All Articles