How to provide a different launch icon for a product

I have a project defined by build.gradle

buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.5.6' } } apply plugin: 'android' dependencies { compile fileTree(dir: 'libs', include: '*.jar') } android { compileSdkVersion 17 buildToolsVersion "17.0.0" sourceSets { main { manifest.srcFile 'AndroidManifest.xml' java.srcDirs = ['src'] resources.srcDirs = ['resources'] aidl.srcDirs = ['src'] renderscript.srcDirs = ['src'] res.srcDirs = ['res'] assets.srcDirs = ['assets'] } instrumentTest.setRoot('tests') } defaultConfig { ... } signingConfigs { debug { storeFile file("debug.keystore") } release { ... } } buildTypes { debug { debuggable true jniDebugBuild true signingConfig signingConfigs.debug packageNameSuffix ".debug" versionNameSuffix ".debug" } release { debuggable false jniDebugBuild false signingConfig signingConfigs.release } } flavorGroups "version", "market" productFlavors { amazon { flavorGroup "market" buildConfig "public static final int COMPILATION = 1;" } google { flavorGroup "market" buildConfig "public static final int COMPILATION = 0;" } lite { flavorGroup "version" packageName = "package.name.lite" } full { flavorGroup "version" packageName = "package.name.full" } } android.sourceSets.amazon { res { srcDir "amazon" } manifest { srcFile "amazon/AndroidManifest.xml" } } android.sourceSets.google { res { srcDir "google" } } android.sourceSets.full { res { srcDir "full" } } android.sourceSets.lite { res { srcDir "lite" } } } 

It works great, but now I want to provide specific launch icons for each product. I tried to add an extra manifest file for Amazon, but that didn't work. I got the error message "Duplicate files copied to AndroidManifest.xml APK". What could be wrong?

+21
android android-gradle gradle android-icons
Aug 27 '13 at 8:01
source share
1 answer

You have several options:

  • Switch to the new android studio / gradle studio layout and create folders for your product

    src/main/ - Common code / resources for all tastes
    src/amazon - src/amazon custom code / resources for all tastes
    src/google - src/google code or resources matching all tastes

    So, in your main manifest ( src/main/AndroidManifest.xml ), if your android:icon is @drawable/icon , you will have the corresponding icon located in src/amazon/res/drawable-*/icon.png , and also for the rest of your products. >

  • Save the existing layout (and build.gradle) and add the resource directory to res.srcDirs :

So, for your Amazonian sources:

 android.sourceSets.amazon { res.srcDirs = ['res', '/path/to/amazon/res/dir'] } 

And then in your /path/to/amazon/res/dir/drawable-* you will have your launcher icon.

+21
Aug 27 '13 at 18:33
source share



All Articles