내 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를 사용합니다.
답변
이것은 중요한 단점이 있지만 편리한 접근 방식입니다. 두 런처가 모두 APK에 포함됩니다. – Bartek Lipinski
더 나은 방법 : InsanityOnABun의 답변
AndroidManifest.xml
<manifest
...
<application
android:allowBackup="true"
android:icon="${appIcon}"
android:roundIcon="${appIconRound}"
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",
appIconRound: "@mipmap/ic_launcher_test_round"
]
}
Product{
resValue "string", "app_name", "App"
manifestPlaceholders = [
appIcon: "@mipmap/ic_launcher",
appIconRound: "@mipmap/ic_launcher_round"
]
}
}
}
Github URL : Gradle로 다중 버전 앱 빌드
답변
제품 버전의 부분 AndroidManifest.xml 파일에서도 아이콘을 지정할 수 있습니다.
<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>
원본 AndroidManifest.xml에 지정한 아이콘을 덮어 씁니다.
답변
다음과 같이 여러 차원으로 다른 풍미를 사용하면서 다른 아이콘을 가져 오는 경우 :
flavorDimensions "color", "size"
productFlavors {
black {
dimension "color"
}
white {
dimension "color"
}
big {
dimension "size"
}
small {
dimension "size"
}
}
이것은 다음과 같이 달성 될 수 있습니다.
먼저 디버그 리소스를 다음과 같은 별도의 폴더에 저장합니다.
src/blackDebug/res
src/whiteDebug/res
둘째, 여러 플레이버 차원이있는 키를 넣으려면 이러한 차원 중 일부가 아이콘에 영향을주지 않더라도 소스 세트 이름에 가능한 모든 플레이버 조합이 포함되어야합니다.
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'
}
명확히하기 위해 여러 차원이 사용중인 경우 다음 은 작동하지 않습니다 .
sourceSets {
// Override the icons in debug mode
blackDebug.res.srcDir 'src/blackDebug/res'
whiteDebug.res.srcDir 'src/whiteDebug/res'
}
답변
mipmap-anydpi-v26 교체 및 모든 차원에 대한 파일 유지를 포함한 단계별 솔루션 :
먼저 build.gradle (Module : app)에서 Android-> buildTypes-> debug, internal 등의 빌드 유형을 정의하십시오.
프로젝트 계층 구조에서 Android 아래에서 앱-> 새로 만들기-> 이미지 자산-> 경로에서 아이콘 선택-> 배경 레이어 및 레거시의 다른 변경 사항-> 다음-> Res 디렉토리에서 원하는 빌드 유형을 선택합니다 ( 디버그, 내부, 기본 등)-> 완료
이렇게하면 아이콘이 기존의 모든 아이콘을 대체합니다.