InsanityOnABun InsanityOnABun - 2 months ago 23
Android Question

How to provide different Android app icons for different gradle buildTypes?

I have two build types set in my gradle file:

debug
and
release
. I'd like to be able to set a different app icon for the
debug
build type. Is there any way to this just through the build type, without getting into product flavors? build.gradle file is below.

apply plugin: 'android'

//...

android {
compileSdkVersion 19
buildToolsVersion "19.0.3"

defaultConfig {
minSdkVersion 14
targetSdkVersion 19
versionCode 30
versionName "2.0"
}
buildTypes {
debug {
packageNameSuffix '.debug'
versionNameSuffix '-SNAPSHOT'
}
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}

Answer

Figured it out. What you need to do is create a separate src folder called debug that holds the different icons. For example, if your project layout is as follows, and your launcher icon is called ic_launcher.png:

[Project Root]
  -[Module]
    -src
      -main
        -res
          -drawable-*
            -ic_launcher.png

Then to add a separate icon for the debug build type, you add:

[Project Root]
  -[Module]
    -src
      -main
        -res
          -drawable-*
            -ic_launcher.png
      -debug
        -res
          -drawable-*
            -ic_launcher.png

Then, when you build under the debug build type, it will use the ic_launcher found in the debug folder.

Comments