解決Android 5.0以下出現 java.lang.NoClassDefFoundError
阿新 • • 發佈:2019-02-12
作者:時之沙
問題的主要原因:方法數超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