Dexguard 与 Multidex

Dexguard with Multidex

我在将 Dexguard 集成到需要启用 Multidex 的项目中时遇到问题,我没有遇到编译错误,但在启动应用程序时崩溃并出现此错误

java.lang.RuntimeException: Unable to instantiate application xx.xxx.xxx.XXXApp: java.lang.ClassNotFoundException: Didn't find class "xx.xxx.xxx.XXXApp" on path: DexPathList

这是 app.gradle 文件:

apply plugin: 'com.android.application'
...
apply plugin: 'dexguard'

android {
    compileSdkVersion 27
    buildToolsVersion "27.0.3"
    defaultConfig {
        applicationId "xx.xxx.xxx"
        ...
        multiDexEnabled true
    }
    buildTypes {
        debug {
            proguardFile getDefaultDexGuardFile('dexguard-debug.pro')
            proguardFile 'dexguard-project.txt'
            //proguardFile 'proguard-project.txt'
        }
        release {
            proguardFile getDefaultDexGuardFile('dexguard-release.pro')
            proguardFile 'dexguard-project.txt'
            //proguardFile 'proguard-project.txt'
        }
    }
    flavorDimensions "server"
    productFlavors {
        dev {
            applicationIdSuffix ".dev"
            dimension "server"
        }
        ...
        prod {
            dimension "server"
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    ...

    implementation 'com.android.support:multidex:1.0.1'

    //support libraries
    ...
    //play services
    ...
    //architecture components
    ...
    //others
    ...
}

apply plugin: 'com.google.gms.google-services'

dexguard-project.txt 文件中,我只是添加了 -multidex 选项

我也尝试过使用 -keep public class * extends android.app.Application 但没有成功。

编辑

我使用自定义应用程序 class 扩展了另一个自定义应用程序 -.- 所以我添加了下面的代码段

@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
}

这是清单的相关部分

<application
        android:name=".XXXApp"
        ...

有人遇到过同样的问题吗?

最后解决办法很简单,就是把multidexEnabled改成false

defaultConfig {
        applicationId "xx.xxx.xxx"
        ...
        multiDexEnabled false
    }