MultiDex示例:
AndroidStudio中MultiDex配置:
1、grandle配置
multiDexEnabled true // true时,生成多个dex
setMultiDexKeepFile file("multiDexKeep.txt") // 当前项目中指定的classes,编译到class.dex中implementation "com.android.support:multidex:1.0.1"
2、multiDexKeep.txt文件 (生成工具:http://scimence.cn/soft/ApkClasses/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 {@Overridepublic void onCreate() {super.onCreate();}@Overrideprotected void attachBaseContext(Context base) {super.attachBaseContext(base);MultiDex.install(this); // 调用MutiDex}
}
4、重新生成apk即可