다른 gradle buildType에 대해 다른 Android 앱 아이콘을 제공하는 방법은 무엇입니까?
내 Gradle을 파일에 설정이 개 빌드 유형이 : debug
와 release
. debug
빌드 유형에 대해 다른 앱 아이콘을 설정하고 싶습니다 . 제품 맛에 들어 가지 않고 빌드 유형을 통해서만이 작업을 수행 할 수 있습니까? build.gradle 파일은 다음과 같습니다.
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
:
[Project Root]
-[Module]
-src
-main
-res
-drawable-*
-ic_launcher.png
그런 다음 디버그 빌드 유형에 대한 별도의 아이콘을 추가하려면 다음을 추가합니다.
[Project Root]
-[Module]
-src
-main
-res
-drawable-*
-ic_launcher.png
-debug
-res
-drawable-*
-ic_launcher.png
그런 다음 디버그 빌드 유형으로 빌드 할 때 디버그 폴더에있는 ic_launcher를 사용합니다.
This is a handy approach although it has an important downside... both launchers will be put into your apk. – Bartek Lipinski
The better way: InsanityOnABun's answer
AndroidManifest.xml
<manifest
...
<application
android:allowBackup="true"
android:icon="${appIcon}"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
...
</application>
</manifest>
build.gradle
android {
...
productFlavors{
Test{
versionName "$defaultConfig.versionName" + ".test"
resValue "string", "app_name", "App-Test"
manifestPlaceholders = [
appIcon: "@mipmap/ic_launcher_test"
]
}
Product{
resValue "string", "app_name", "App"
manifestPlaceholders = [
appIcon: "@mipmap/ic_launcher"
]
}
}
}
the Github url:Build multi-version App with Gradle
You can specify the icon in the product flavor's partial AndroidManifest.xml file as well:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
tools:replace="android:icon"
android:icon="@drawable/alternative_icon" />
</manifest>
This will overwrite the icon that you specify in the original AndroidManifest.xml
For getting different icons while using different flavors with multiple dimensions, such as:
flavorDimensions "color", "size"
productFlavors {
black {
dimension "color"
}
white {
dimension "color"
}
big {
dimension "size"
}
small {
dimension "size"
}
}
This can be achieved as:
First, put the debug resources in separate folders, such as:
src/blackDebug/res
src/whiteDebug/res
Second, put the key with multiple flavor dimensions is that the sourceset name must contain all the possible flavor combinations, even if some of these dimensions do not affect the icon.
sourceSets {
// Override the icons in debug mode
blackBigDebug.res.srcDir 'src/blackDebug/res'
blackSmallDebug.res.srcDir 'src/blackDebug/res'
whiteBigDebug.res.srcDir 'src/whiteDebug/res'
whiteSamllDebug.res.srcDir 'src/whiteDebug/res'
}
Just to make it clear, the following will not work when multiple dimensions are in use:
sourceSets {
// Override the icons in debug mode
blackDebug.res.srcDir 'src/blackDebug/res'
whiteDebug.res.srcDir 'src/whiteDebug/res'
}
Step by step solution, including replacing mipmap-anydpi-v26 and keeping files for all dimensions:
First define in build.gradle (Module: app) your build type in android -> buildTypes -> debug, internal, etc
On the project hierarchy, below Android, right click on app -> New -> Image Asset -> in Path choose your icon -> any other changes on Background Layer and Legacy -> Next -> in Res Directory choose your desired build type (debug, internal, main, etc) -> Finish
That way the icons will replace every old icon you had.
'program story' 카테고리의 다른 글
SharedPreferences에서 일부 키 / 값 쌍을 제거하는 방법은 무엇입니까? (0) | 2020.09.23 |
---|---|
SQL Server 2005 데이터베이스에서 가장 많은 공간을 차지하는 테이블을 어떻게 알 수 있습니까? (0) | 2020.09.23 |
Windows에서 bash를 사용하려고하는데 설치된 배포 메시지가 없습니다. (0) | 2020.09.23 |
두 요소가 동일한 지 테스트 (0) | 2020.09.23 |
POST NSURLRequest에 데이터 추가 (0) | 2020.09.23 |