【问题标题】:Dexguard with Multidex使用 Multidex 的 Dexguard
【发布时间】:2018-04-17 08:59:26
【问题描述】:

我在需要启用 Multidex 的项目中集成 Dexguard 时遇到问题,我没有收到编译错误,但是在启动应用程序时它会因此错误而崩溃

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,但没有运气。

编辑

我使用了一个自定义应用程序类,它扩展了另一个自定义应用程序类 -.- 所以我在下面添加了 sn-p

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

这是清单的相对部分

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

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

【问题讨论】:

标签: android android-multidex dexguard


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-08-25
    • 2017-09-25
    • 1970-01-01
    • 1970-01-01
    • 2015-09-27
    • 2014-10-16
    • 2017-07-29
    • 1970-01-01
    相关资源
    最近更新 更多