Android引入第三方SDK混淆报错shrinkDebugMultiDexComponents的解决方案

问题

项目工程中,引用了一个第三方的SDK,它的jar包是已经混淆过的。在IDE下代码编译没问题,但是运行在手机上就报错。

Error:Execution failed for task ‘:app:shrinkDebugMultiDexComponents’.
java.io.IOException: Can’t read [src\app\build\intermediates\multi-dex\debug\allclasses.jar] (Can’t process class [com/dvrcam/DvrCamSDK/a$d.class] (Unknown verification type [255] in stack map frame))

大致意思是jar包目录com/dvrcam/DvrCamSDK/a/下的内部类d.class混淆失败。

解决方案

在工程的根目录下创建一个文件夹proguard,放入proguard.jar文件,下载地址:proguard.jar

Android引入第三方SDK混淆报错shrinkDebugMultiDexComponents的解决方案_第1张图片

在根目录的build.gradle文件中加入
flatDir { dirs ‘proguard’ }classpath ‘proguard.io:proguard:5.2.1’

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        flatDir { dirs 'proguard' }//1.依赖库类目录
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.3'
        classpath 'proguard.io:proguard:5.2.1'//2.依赖的库类
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

按照以上步骤操作,就能运行成功!

你可能感兴趣的:(Android引入第三方SDK混淆报错shrinkDebugMultiDexComponents的解决方案)