MultiDex示例:
AndroidStudio中MultiDex配置:
1、grandle配置
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.zq.multidexdemo"
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
setMultiDexKeepFile file("multidexkeepfile.txt")
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation "com.android.support:multidex:1.0.1"
}
2、multiDexKeep.txt文件,生成工具 ApkClasses.exe
备注:若出现DexArchiveMergerException,则为multiDexKeep.txt中的类路径、或名称配置有问题
Caused by: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: D:\sci\ADT\workspace\**
Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete
Caused by: com.android.tools.r8.utils.AbortException
3、Application中调用MultiDex
package com.ltsdk.union;
import android.app.Application;
import android.content.Context;
import android.support.multidex.MultiDex;
// 自定义 Application
public class LtsdkApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
}
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this); // 调用MutiDex
}
}