问题描述
我的 gradle 文件中设置了两种构建类型:debug
和 release
.我希望能够为 debug
构建类型设置不同的应用程序图标.有没有办法仅通过构建类型来解决这个问题,而无需进入产品口味?build.gradle 文件在下面.
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'])
}
推荐答案
想通了.您需要做的是创建一个名为 debug
的单独 src 文件夹,其中包含不同的图标.例如,如果您的项目布局如下,并且您的启动器图标名为 ic_launcher.png
:
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
然后,当您在 debug 构建类型下构建时,它将使用在 debug 文件夹中找到的 ic_launcher.
Then, when you build under the debug build type, it will use the ic_launcher found in the debug folder.
这篇关于如何为不同的 gradle buildType 提供不同的 Android 应用程序图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!