如何在Android中排除ProGuard对外部第三方的依赖性

时间:2018-09-05 12:35:22

标签: android android-proguard

我使用第三方依赖项。它在调试模式下效果很好,而且如果我使用以下命令生成签名的APK,效果也很好:

 buildTypes {
    release {

        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.release
    }
}

但在以下情况时崩溃

 buildTypes {
    release {

        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.release
    }
}

我的原木猫是

09-05 18:56:39.124 4730-4730/? A/art: art/runtime/java_vm_ext.cc:470] JNI DETECTED ERROR IN APPLICATION: fid == null
09-05 18:56:39.125 4730-4730/? A/art: art/runtime/java_vm_ext.cc:470]     in call to GetObjectField
art/runtime/java_vm_ext.cc:470]     from int com.opentok.android.Session.init(java.lang.String, android.content.Context, java.lang.String, java.lang.String, boolean)
art/runtime/java_vm_ext.cc:470] "main" prio=5 tid=1 Runnable
art/runtime/java_vm_ext.cc:470]   | group="main" sCount=0 dsCount=0 obj=0x75654000 self=0xabb84400
art/runtime/java_vm_ext.cc:470]   | sysTid=4730 nice=-10 cgrp=default sched=0/0 handle=0xae8e3534
art/runtime/java_vm_ext.cc:470]   | state=R schedstat=( 273272463 63970668 410 ) utm=20 stm=5 core=0 HZ=100
art/runtime/java_vm_ext.cc:470]   | stack=0xbe1e5000-0xbe1e7000 stackSize=8MB
art/runtime/java_vm_ext.cc:470]   | held mutexes= "mutator lock"(shared held)

2 个答案:

答案 0 :(得分:1)

只需将这一行放在ProGuard文件上

-keep public class android.support.v4.** { *;}

用您的外部第三方软件包名称替换android.support.v4

答案 1 :(得分:0)

最简单的方法是使用R8, 只需添加 android.enableR8=true中的gradle.properties