本文參考自:Android 使用android-support-multidex解決Dex超出方法數的限制問題,讓你的應用不再爆棚
作者:時之沙
問題的主要原因:方法數超65536限制。
測試6.0手機沒問題,4.4上面就有問題了。導致出現以上錯誤崩潰。
解決方法:
一、配置build.gradle
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId ""
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0.0"
multiDexEnabled true
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
二、( 1).使用自定義的Application繼承MultiDexApplication類。
( 2).重寫Application的方法attachBaseContext(),調用MultiDex.install()。
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(base);
}
三、到項目的根目錄下執行 ./gradlew clean build