問題描述
我有一個由 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"
}
}
}
它工作正常,但現在我想為每種產品風格提供特定的啟動器圖標.我試圖為亞馬遜添加額外的 Manifest 文件,但沒有成功.我收到錯誤在 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 studio/gradle 布局并為您的 productFlavors 創建文件夾:
Switch to the new android studio/gradle layout and create folders for your productFlavors:
src/main/
- 所有風格的共享代碼/資源src/amazon
- 各種風格的亞馬遜特定代碼/資源src/google
- 各種風格的 Google 特定代碼/資源
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/main/AndroidManifest.xml
) 中,如果你的 android:icon
是 @drawable/icon
,你將在 src/amazon/res/drawable-*/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
:
所以,對于您的亞馬遜資源集:
So, for your amazon sourceset:
android.sourceSets.amazon {
res.srcDirs = ['res', '/path/to/amazon/res/dir']
}
然后在你的 /path/to/amazon/res/dir/drawable-*
你會有你的啟動器圖標.
And then in your /path/to/amazon/res/dir/drawable-*
you would have your launcher icon.
這篇關于如何為每種產品風格提供不同的啟動器圖標的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!