如何提供每个产品的风味不同的启动器图标 [英] How to provide different launcher icon per product flavour
问题描述
我得build.gradle文件中定义的项目
I have a project defined by build.gradle file
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"
}
}
}
它工作正常,但现在我想提供具体的启动图标,每一个产品的味道。我试图把多余的清单文件的亚马逊,但没有奏效。我得到一个错误,在APK AndroidManifest.xml中复制重复的文件。什么地方出错了?
It works fine but now i want to provide specific launcher icons for every product flavor. I tried to put extra Manifest file for Amazon but it didn't work. I got an error "Duplicates files copied in APK AndroidManifest.xml". What could be wrong?
推荐答案
您有几个选项:
-
切换到新的Android工作室/摇篮布局和创建文件夹为您productFlavors:
Switch to the new android studio/gradle layout and create folders for your productFlavors:
的src /主/
- 共享code /所有口味的资源
的src /亚马逊
- 亚马逊特定code /所有口味的资源
的src /谷歌
- 谷歌具体的code /资源进行的跨所有风格
src/main/
- Shared code/resources across all flavors
src/amazon
- Amazon specific code/resources across all flavors
src/google
- Google specific code/resources accross all flavors
所以,在你的主清单(的src /主/ AndroidManifest.xml中
)如果你的安卓图标
是 @绘制/图标
,你就必须位于的src /亚马逊/ RES /绘制 - * / icon.png在
同样地为您productFlavors的其余部分。
So in your main manifest (src/main/AndroidManifest.xml
) if your android:icon
is @drawable/icon
, you would have the appropriate icon located in src/amazon/res/drawable-*/icon.png
and likewise for the rest of your productFlavors.
请您现有的布局(与build.gradle)和追加资源目录的 res.srcDirs
:
Keep your existing layout (and build.gradle) and append a resource directory to the res.srcDirs
:
因此,对于您的Amazon sourceset:
So, for your amazon sourceset:
android.sourceSets.amazon {
res.srcDirs = ['res', '/path/to/amazon/res/dir']
}
,然后在 /路径/要/亚马逊/ RES / DIR /绘制 - *
你将有你的发射器图标
And then in your /path/to/amazon/res/dir/drawable-*
you would have your launcher icon.
这篇关于如何提供每个产品的风味不同的启动器图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!