Android混淆器"Can't find referenced"

Android Proguard "Can't find referenced"

我想生成一个签名的 apk。但是我达到了 64k 方法的限制,所以我搜索了一些解决方案,其中之一是使用混淆器。 我这样编辑 build.gradle:

 buildTypes {

        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }

    }

当我尝试生成签名的 apk 时,我收到了很多警告:

Warning:com.akexorcist.roundcornerprogressbar.TextRoundCornerProgressBar: can't find referenced method 'android.widget.TextView access[=13=]0(com.akexorcist.roundcornerprogressbar.TextRoundCornerProgressBar)' in program class com.akexorcist.roundcornerprogressbar.TextRoundCornerProgressBar
Warning:com.akexorcist.roundcornerprogressbar.TextRoundCornerProgressBar: can't find enclosing method 'void setTextProgressAlign()' in program class com.akexorcist.roundcornerprogressbar.TextRoundCornerProgressBar
Warning:com.github.mikephil.charting.data.realm.base.RealmBarLineScatterCandleBubbleDataSet: can't find referenced class io.realm.RealmResults
Warning:com.github.mikephil.charting.data.realm.base.RealmBarLineScatterCandleBubbleDataSet: can't find referenced class io.realm.RealmObject
Warning:com.github.mikephil.charting.data.realm.base.RealmBaseDataSet: can't find referenced class io.realm.Sort
Warning:com.github.mikephil.charting.data.realm.base.RealmBaseDataSet: can't find referenced class io.realm.RealmResults
Warning:com.github.mikephil.charting.data.realm.base.RealmBaseDataSet: can't find referenced class io.realm.Sort
Warning:com.github.mikephil.charting.data.realm.base.RealmBaseDataSet: can't find referenced class io.realm.RealmResults
Warning:com.github.mikephil.charting.data.realm.base.RealmBaseDataSet: can't find referenced class io.realm.RealmObject
Warning:com.github.mikephil.charting.data.realm.base.RealmLineRadarDataSet: can't find referenced class io.realm.RealmResults
Warning:com.github.mikephil.charting.data.realm.base.RealmLineRadarDataSet: can't find referenced class io.realm.RealmObject
Warning:com.github.mikephil.charting.data.realm.base.RealmLineRadarDataSet: can't find referenced class io.realm.DynamicRealmObject
Warning:com.github.mikephil.charting.data.realm.base.RealmLineRadarDataSet: can't find referenced class io.realm.RealmResults
Warning:com.github.mikephil.charting.data.realm.base.RealmLineRadarDataSet: can't find referenced class io.realm.DynamicRealmObject
Warning:com.github.mikephil.charting.data.realm.base.RealmLineRadarDataSet: can't find referenced class io.realm.RealmObject
Warning:com.github.mikephil.charting.data.realm.base.RealmLineRadarDataSet: can't find referenced class io.realm.DynamicRealmObject
Warning:com.github.mikephil.charting.data.realm.base.RealmLineRadarDataSet: can't find referenced class io.realm.RealmObject
Warning:com.github.mikephil.charting.data.realm.base.RealmLineRadarDataSet: can't find referenced class io.realm.RealmResults
Warning:com.github.mikephil.charting.data.realm.base.RealmLineRadarDataSet: can't find referenced class io.realm.RealmObject
Warning:com.github.mikephil.charting.data.realm.base.RealmLineScatterCandleRadarDataSet: can't find referenced class io.realm.RealmResults
Warning:com.github.mikephil.charting.data.realm.base.RealmLineScatterCandleRadarDataSet: can't find referenced class io.realm.RealmObject
Warning:com.github.mikephil.charting.data.realm.base.RealmUtils: can't find referenced class io.realm.RealmResults
Warning:com.github.mikephil.charting.data.realm.base.RealmUtils: can't find referenced class io.realm.RealmObject
Warning:com.github.mikephil.charting.data.realm.base.RealmUtils: can't find referenced class io.realm.DynamicRealmObject
Warning:com.github.mikephil.charting.data.realm.base.RealmUtils: can't find referenced class io.realm.RealmResults
Warning:com.github.mikephil.charting.data.realm.base.RealmUtils: can't find referenced class io.realm.DynamicRealmObject
Warning:com.github.mikephil.charting.data.realm.base.RealmUtils: can't find referenced class io.realm.RealmObject
Warning:com.github.mikephil.charting.data.realm.base.RealmUtils: can't find referenced class io.realm.RealmResults
Warning:com.github.mikephil.charting.data.realm.base.RealmUtils: can't find referenced class io.realm.RealmObject
Warning:com.github.mikephil.charting.data.realm.base.RealmUtils: can't find referenced class io.realm.RealmResults
Warning:com.github.mikephil.charting.data.realm.base.RealmUtils: can't find referenced class io.realm.RealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmBarData: can't find referenced class io.realm.RealmResults
Warning:com.github.mikephil.charting.data.realm.implementation.RealmBarData: can't find referenced class io.realm.RealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmBarData: can't find referenced class io.realm.RealmResults
Warning:com.github.mikephil.charting.data.realm.implementation.RealmBarData: can't find referenced class io.realm.RealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmBarDataSet: can't find referenced class io.realm.RealmResults
Warning:com.github.mikephil.charting.data.realm.implementation.RealmBarDataSet: can't find referenced class io.realm.RealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmBarDataSet: can't find referenced class io.realm.DynamicRealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmBarDataSet: can't find referenced class io.realm.RealmList
Warning:com.github.mikephil.charting.data.realm.implementation.RealmBarDataSet: can't find referenced class io.realm.RealmResults
Warning:com.github.mikephil.charting.data.realm.implementation.RealmBarDataSet: can't find referenced class io.realm.RealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmBarDataSet: can't find referenced class io.realm.DynamicRealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmBarDataSet: can't find referenced class io.realm.RealmList
Warning:com.github.mikephil.charting.data.realm.implementation.RealmBarDataSet: can't find referenced class io.realm.RealmResults
Warning:com.github.mikephil.charting.data.realm.implementation.RealmBarDataSet: can't find referenced class io.realm.RealmList
Warning:com.github.mikephil.charting.data.realm.implementation.RealmBarDataSet: can't find referenced class io.realm.RealmResults
Warning:com.github.mikephil.charting.data.realm.implementation.RealmBarDataSet: can't find referenced class io.realm.DynamicRealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmBarDataSet: can't find referenced class io.realm.RealmList
Warning:com.github.mikephil.charting.data.realm.implementation.RealmBarDataSet: can't find referenced class io.realm.DynamicRealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmBarDataSet: can't find referenced class io.realm.RealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmBarDataSet: can't find referenced class io.realm.RealmResults
Warning:com.github.mikephil.charting.data.realm.implementation.RealmBarDataSet: can't find referenced class io.realm.RealmList
Warning:com.github.mikephil.charting.data.realm.implementation.RealmBarDataSet: can't find referenced class io.realm.DynamicRealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmBarDataSet: can't find referenced class io.realm.RealmResults
Warning:com.github.mikephil.charting.data.realm.implementation.RealmBarDataSet: can't find referenced class io.realm.RealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmBubbleData: can't find referenced class io.realm.RealmResults
Warning:com.github.mikephil.charting.data.realm.implementation.RealmBubbleData: can't find referenced class io.realm.RealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmBubbleData: can't find referenced class io.realm.RealmResults
Warning:com.github.mikephil.charting.data.realm.implementation.RealmBubbleData: can't find referenced class io.realm.RealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmBubbleDataSet: can't find referenced class io.realm.RealmResults
Warning:com.github.mikephil.charting.data.realm.implementation.RealmBubbleDataSet: can't find referenced class io.realm.RealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmBubbleDataSet: can't find referenced class io.realm.DynamicRealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmBubbleDataSet: can't find referenced class io.realm.RealmResults
Warning:com.github.mikephil.charting.data.realm.implementation.RealmBubbleDataSet: can't find referenced class io.realm.DynamicRealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmBubbleDataSet: can't find referenced class io.realm.RealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmBubbleDataSet: can't find referenced class io.realm.DynamicRealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmBubbleDataSet: can't find referenced class io.realm.RealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmBubbleDataSet: can't find referenced class io.realm.RealmResults
Warning:com.github.mikephil.charting.data.realm.implementation.RealmBubbleDataSet: can't find referenced class io.realm.RealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmCandleData: can't find referenced class io.realm.RealmResults
Warning:com.github.mikephil.charting.data.realm.implementation.RealmCandleData: can't find referenced class io.realm.RealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmCandleData: can't find referenced class io.realm.RealmResults
Warning:com.github.mikephil.charting.data.realm.implementation.RealmCandleData: can't find referenced class io.realm.RealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmCandleDataSet: can't find referenced class io.realm.RealmResults
Warning:com.github.mikephil.charting.data.realm.implementation.RealmCandleDataSet: can't find referenced class io.realm.RealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmCandleDataSet: can't find referenced class io.realm.DynamicRealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmCandleDataSet: can't find referenced class io.realm.RealmResults
Warning:com.github.mikephil.charting.data.realm.implementation.RealmCandleDataSet: can't find referenced class io.realm.DynamicRealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmCandleDataSet: can't find referenced class io.realm.RealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmCandleDataSet: can't find referenced class io.realm.DynamicRealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmCandleDataSet: can't find referenced class io.realm.RealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmCandleDataSet: can't find referenced class io.realm.RealmResults
Warning:com.github.mikephil.charting.data.realm.implementation.RealmCandleDataSet: can't find referenced class io.realm.RealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmLineData: can't find referenced class io.realm.RealmResults
Warning:com.github.mikephil.charting.data.realm.implementation.RealmLineData: can't find referenced class io.realm.RealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmLineData: can't find referenced class io.realm.RealmResults
Warning:com.github.mikephil.charting.data.realm.implementation.RealmLineData: can't find referenced class io.realm.RealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmLineDataSet: can't find referenced class io.realm.RealmResults
Warning:com.github.mikephil.charting.data.realm.implementation.RealmLineDataSet: can't find referenced class io.realm.RealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmPieData: can't find referenced class io.realm.RealmResults
Warning:com.github.mikephil.charting.data.realm.implementation.RealmPieData: can't find referenced class io.realm.RealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmPieData: can't find referenced class io.realm.RealmResults
Warning:com.github.mikephil.charting.data.realm.implementation.RealmPieData: can't find referenced class io.realm.RealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmPieDataSet: can't find referenced class io.realm.RealmResults
Warning:com.github.mikephil.charting.data.realm.implementation.RealmPieDataSet: can't find referenced class io.realm.RealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmPieDataSet: can't find referenced class io.realm.DynamicRealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmPieDataSet: can't find referenced class io.realm.RealmResults
Warning:com.github.mikephil.charting.data.realm.implementation.RealmPieDataSet: can't find referenced class io.realm.DynamicRealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmPieDataSet: can't find referenced class io.realm.RealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmPieDataSet: can't find referenced class io.realm.DynamicRealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmPieDataSet: can't find referenced class io.realm.RealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmPieDataSet: can't find referenced class io.realm.RealmResults
Warning:com.github.mikephil.charting.data.realm.implementation.RealmPieDataSet: can't find referenced class io.realm.RealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmRadarData: can't find referenced class io.realm.RealmResults
Warning:com.github.mikephil.charting.data.realm.implementation.RealmRadarData: can't find referenced class io.realm.RealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmRadarData: can't find referenced class io.realm.RealmResults
Warning:com.github.mikephil.charting.data.realm.implementation.RealmRadarData: can't find referenced class io.realm.RealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmRadarDataSet: can't find referenced class io.realm.RealmResults
Warning:com.github.mikephil.charting.data.realm.implementation.RealmRadarDataSet: can't find referenced class io.realm.RealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmScatterData: can't find referenced class io.realm.RealmResults
Warning:com.github.mikephil.charting.data.realm.implementation.RealmScatterData: can't find referenced class io.realm.RealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmScatterData: can't find referenced class io.realm.RealmResults
Warning:com.github.mikephil.charting.data.realm.implementation.RealmScatterData: can't find referenced class io.realm.RealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmScatterDataSet: can't find referenced class io.realm.RealmResults
Warning:com.github.mikephil.charting.data.realm.implementation.RealmScatterDataSet: can't find referenced class io.realm.RealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmScatterDataSet: can't find referenced class io.realm.DynamicRealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmScatterDataSet: can't find referenced class io.realm.RealmResults
Warning:com.github.mikephil.charting.data.realm.implementation.RealmScatterDataSet: can't find referenced class io.realm.DynamicRealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmScatterDataSet: can't find referenced class io.realm.RealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmScatterDataSet: can't find referenced class io.realm.DynamicRealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmScatterDataSet: can't find referenced class io.realm.RealmObject
Warning:com.github.mikephil.charting.data.realm.implementation.RealmScatterDataSet: can't find referenced class io.realm.RealmResults
Warning:com.github.mikephil.charting.data.realm.implementation.RealmScatterDataSet: can't find referenced class io.realm.RealmObject
Warning:there were 283 unresolved references to classes or interfaces.
Warning:there were 2 unresolved references to program class members.
Warning:Exception while processing task java.io.IOException: Please correct the above warnings first.
Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForFreeRelease'.
> java.io.IOException: Please correct the above warnings first.

所以问题似乎出在我实现的存储库上。我读到我必须配置 proguard-rules.pro 文件,但我以前从未使用过它并且不知道语法。 我该如何解决?

编辑 依赖项:

compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.android.support:design:24.2.1'
    compile 'com.android.support:recyclerview-v7:24.2.1'
    compile 'com.android.support:cardview-v7:24.2.1'
    compile 'com.bignerdranch.android:expandablerecyclerview:2.1.1'
    compile 'com.github.lzyzsd:circleprogress:1.1.0@aar'
    compile 'com.github.PhilJay:MPAndroidChart:v2.2.3'
    compile 'net.qiujuer.genius:ui:1.5.2'
    compile 'com.akexorcist:RoundCornerProgressBar:2.0.3'
    compile 'com.rengwuxian.materialedittext:library:2.1.4'
    compile 'com.github.medyo:fancybuttons:1.8.1'
    compile 'com.google.android.gms:play-services:9.6.1'
    compile 'com.github.sundeepk:compact-calendar-view:1.9.3'

buildTypes {

    release {
        debuggable false
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }


    debug {
        debuggable true
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

有两个有问题的库:

RoundCornerProgressBar

MPAndroidChart

第一个问题是 class com.akexorcist.roundcornerprogressbar.TextRoundCornerProgressBar。有一个解决方案 here 可以解决这个问题,方法是添加到 Proguard:

-dontwarn com.akexorcist.roundcornerprogressbar.TextRoundCornerProgressBar

第二个很简单,在Proguard中添加两条语句,库的作者明确描述here:

-keep class com.github.mikephil.charting.** { *; }
-dontwarn io.realm.**

您的 Proguard 文件应该包含这些行,问题应该会消失。