수색…


비고

APK 파일을 가능한 작게 만들려면 축소 빌드를 사용하여 릴리스 빌드에서 사용되지 않는 코드와 리소스를 제거해야합니다.

ProGuard로 코드 줄이기

ProGuard를 사용하여 코드 축소를 사용하려면 build.gradle 파일의 적절한 빌드 유형에 minifyEnabled true를 추가하십시오.

android {
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile(‘proguard-android.txt'),
                    'proguard-rules.pro'
        }
    }
}

어디에:

  • minifyEnabled true : 코드 축소 허용
  • getDefaultProguardFile('proguard-android.txt') 메소드는 Android SDK에서 기본 ProGuard 설정을 가져옵니다.
  • proguard-rules.pro 파일은 사용자 정의 ProGuard 규칙을 추가 할 수있는 곳입니다

자원 축소

리소스 축소를 사용하려면 build.gradle 파일에서 shrinkResources 속성을 true로 설정하십시오.

android {
    ...

    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

리소스 축소가 코드 축소 와 함께 작동 하기 때문에주의를 기울여야합니다.

다음과 같이 XML 파일 작성을 유지하거나 버릴 자원을 사용자 정의 할 수 있습니다.

<?xml version=1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
    tools:keep="@layout/mylayout,@layout/custom_*"
    tools:discard="@layout/unused" />

이 파일을 res/raw 폴더에 저장하십시오.

사용되지 않는 대체 리소스를 제거하십시오.

모든 라이브러리에는 응용 프로그램에 유용하지 않은 리소스가 있습니다. 예를 들어 Google Play 서비스에는 자체 애플리케이션이 지원하지 않는 언어에 대한 번역이 함께 제공됩니다.

보관할 자원을 지정하기 위해 build.gradle 파일을 구성 할 수 있습니다.
예 :

defaultConfig {
    // ...

    resConfigs "en", "de", "it"
    resConfigs "nodpi", "xhdpi", "xxhdpi", "xxxhdpi"
}


Modified text is an extract of the original Stack Overflow Documentation
아래 라이선스 CC BY-SA 3.0
와 제휴하지 않음 Stack Overflow