티스토리 뷰
android multidex error
앱개발을 하다보면 앱 규모가 커지고 사용하는 라이브러리가 많아지면 만나게되는 에러가 있다.
LEVEL EXCEPTION: com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536 at
이는 앱에서 빌드시 사용되는 메서드가 65536개가 넘어서 발생하는 에러다
(하단참조)
하나의 유형이 아니라 다른 방식으로 에러가 발생 할 수 있기 때문에 ex) Class not found 등
항상 유의해야한다.
해결방법은 간단하다 .
android {
compileSdkVersion 21
buildToolsVersion "21.1.0"
defaultConfig {
...
minSdkVersion 14
targetSdkVersion 21
...
// Enabling multidex support.
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
위와같이 app 레벨의 build.gradle 파일에 multiDexEnabled true를 설정해주고
dependencies에 mutidex를 추가해준다.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.multidex.myapplication">
<application
...
android:name="android.support.multidex.MultiDexApplication">
...
</application>
</manifest>
별도의 Application 클래스를 사용하고 있지 않다면 AndroidManifest.xml을 수정해주면 되고,
public class MyApplication extends Application{
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
Application 클래스를 상속받은 별도의 클래스를 사용하고 있다면 위와 같이 attachBaseContext를 override하여 MultiDex.Install(this); 를 추가해주면 된다.
이 외에도 리팩토링과 proguard를 통해 코드축소를 하는 습관을 갖자!
'Android' 카테고리의 다른 글
Bad notification posted - Couldn't expand RemoteViews for: StatusBarNotification (1) | 2017.04.06 |
---|---|
Android Espresso view class Matcher (0) | 2017.03.03 |
안드로이드 키보드 숨기기 (1) | 2016.11.25 |
안드로이드 프로젝트 내부 json파일 정렬순서 바뀌어서 나올 때 해결법 (0) | 2016.09.05 |
안드로이드 retrofit2 + okhttp3 + rxjava(android) 네트워크(서버통신) 샘플 (0) | 2016.07.25 |
댓글