multidex용 앱 구성
multidex 구성을 사용하도록 앱 프로젝트를 설정하려면 앱이 지원하는 최소 Android 버전에 따라 앱 프로젝트에서 다음 내용을 변경해야 할 수 있습니다.
minSdkVersion
이 21 이상으로 설정되어 있을 경우 아래와 같이 모듈 수준의 build.gradle
파일에서 multiDexEnabled
를 true
로 설정하기만 하면 됩니다.
android {
defaultConfig {
...
minSdkVersion 21
targetSdkVersion 26
multiDexEnabled true
}
...
}
그러나 minSdkVersion
이 20 이하로 설정되어 있으면 다음과 같이 multidex 지원 라이브러리를 사용해야 합니다.
multidex를 활성화하고 multidex 라이브러리를 종속성으로 추가할 수 있도록 아래와 같이 모듈 수준
build.gradle
파일을 변경합니다.android {
defaultConfig {
...
minSdkVersion 15
targetSdkVersion 26
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
}Application
클래스 재정의 여부에 따라 다음 중 하나를 수행합니다.Application
클래스를 재정의하지 않을 경우 매니페스트 파일을 편집하여<application>
태그에서android:name
을 다음과 같이 설정합니다.<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp">
<application
android:name="android.support.multidex.MultiDexApplication" >
...
</application>
</manifest>Application
클래스를 재정의할 경우 다음과 같이MultiDexApplication
을 확장하도록 변경합니다(해당할 경우).public class MyApplication extends MultiDexApplication { ... }
또는
Application
클래스를 재정의하지만 기본 클래스를 변경할 수 없을 경우attachBaseContext()
메서드를 재정의하고MultiDex.install(this)
을 호출하여 multidex를 활성화합니다.public class MyApplication extends SomeOtherApplication {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(context);
Multidex.install(this);
}
}
앱을 빌드할 때 Android 빌드 도구는 기본 DEX 파일(classes.dex
)과 지원하는 DEX 파일(classes2.dex
, classes3.dex
등)을 필요에 따라 구성합니다. 그 후 빌드 시스템이 모든 DEX 파일을 APK로 패키징합니다.
런타임에서 multidex API는 특수 클래스 로더를 사용하여 (기본 classes.dex
파일)에서만 검색하는 대신) 메서드에서 사용할 수 있는 모든 DEX 파일을 검색합니다.
출처 : https://developer.android.com/studio/build/multidex.html?hl=ko#avoid
'Development > Android' 카테고리의 다른 글
Android Glide Proguard rules (0) | 2018.05.16 |
---|---|
If Broadcast Receiver is taking too long to receive in onReceive() (0) | 2018.05.04 |
apk 파일 디컴파일 하기 (0) | 2018.04.06 |
안드로이드 개발자라면 꼭 봐야할 사이트들 (0) | 2018.04.02 |
Android Badge Count Update (0) | 2018.04.02 |