Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change app name per Gradle build type

People also ask

How do I change a variant in build?

NOTE: By default, the Android Studio will generate "debug" and "release" Build Types for your project. So, to change a Build Type, all you need to do is just select your Build Type from the Build Variant and after the project sync, you are good to go.

What is the build type in Gradle?

By default, the Android plug-in for Gradle supports two different types of builds: debug and release . Both can be configured inside the buildTypes block inside of the module build file.

How do I change my app name Kotlin?

xml file the apps name would change. Go to the app > res > values > strings. xml file as shown in the below image. In this file we have a string name as app_name it is the string resource that holds the current app name which is passed in the Manifest.


If by "app name", you mean android:label on <application>, the simplest solution is to have that point at a string resource (e.g., android:label="@string/app_name"), then have a different version of that string resource in a src/debug/ sourceset.

You can see that in this sample project, where I have a replacement for app_name in src/debug/res/values/strings.xml, which will be applied for debug builds. release builds will use the version of app_name in src/main/.


You can use something like this

 buildTypes {
    debug {
        applicationIdSuffix '.debug'
        versionNameSuffix '-DEBUG'
        resValue "string", "app_name", "AppName debug"
    }
    release {
        minifyEnabled true
        shrinkResources true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.release
        zipAlignEnabled true
        resValue "string", "app_name", "AppName"
    }
}

You can use @string/app_name in AndroidManifest.xml files.

Make sure you remove app_name from values/ folder (no entry by this name).


You can do this with gradle:

android {
    buildTypes {
        release {
            manifestPlaceholders = [appName: "My Standard App Name"]
        }
        debug {
            manifestPlaceholders = [appName: "Debug"]
        }
    }
}

Then in your AndroidManifest.xml put:

<application
    android:label="${appName}"/>
    <activity
        android:label="${appName}">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

Note: it also works with productFlavors.


To support translations make this:

1. remove string "app_name"

2. add to gradle

 buildTypes {
    admin {
       resValue "string", "app_name", "@string/app_name_admin"
    }
    release {
        resValue "string", "app_name", "@string/app_name_release"
    }
    debug {
        resValue "string", "app_name", "@string/app_name_debug"
    }
}

3. Set app name in Manifest as "@string/app_name"

4. Add to strings.xml values

<string name="app_name_admin">App Admin</string>
<string name="app_name_release">App  release</string>
<string name="app_name_debug">App debug</string>

The app name is user-visible, and that's why Google encourages you to keep it in your strings.xml file. You can define a separate string resource file that contains strings that are specific to your buildTypes. It sounds like you might have a custom qa buildType. If that's not true, ignore the qa part below.

└── src
    ├── debug
    │   └── res
    │       └── buildtype_strings.xml
    ├── release
    │   └── res
    │       └── buildtype_strings.xml
    └── qa
        └── res
            └── buildtype_strings.xml

We need a solution to support app name with localization (for multi language). I have tested with @Nick Unuchek solution, but building is failed (not found @string/) . a little bit change to fix this bug: build.gradle file:

android {
    ext{
        APP_NAME = "@string/app_name_default"
        APP_NAME_DEV = "@string/app_name_dev"
    }

    productFlavors{

        prod{
            manifestPlaceholders = [ applicationLabel: APP_NAME]
        }

        dev{
            manifestPlaceholders = [ applicationLabel: APP_NAME_DEV ]
        }

    }

values\strings.xml:

<resources>
    <string name="app_name_default">AAA prod</string>
    <string name="app_name_dev">AAA dev</string>

</resources>

values-en\strings.xml:

<resources>
    <string name="app_name_default">AAA prod en</string>
    <string name="app_name_dev">AAA dev en</string>

</resources>

Manifest.xml:

<application
    android:label="${applicationLabel}" >
</application>