Android Proguard “Can't find referenced”

2019-09-06 21:13发布

I want to generate a signed apk. But I reached the 64k methods limit so I searched for some solutions and one of them is to use proguard. I edited my build.gradle like this:

 buildTypes {

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

    }

When I then try to generate the signed apk I get a lot of warnings:

Warning:com.akexorcist.roundcornerprogressbar.TextRoundCornerProgressBar$2: can't find referenced method 'android.widget.TextView access$000(com.akexorcist.roundcornerprogressbar.TextRoundCornerProgressBar)' in program class com.akexorcist.roundcornerprogressbar.TextRoundCornerProgressBar
Warning:com.akexorcist.roundcornerprogressbar.TextRoundCornerProgressBar$2: 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.

So the problem seem to be the repositories I implemented. I read that I have to configurate the proguard-rules.pro file but I never used this before and have no idea about the syntax. How can I fix that?

EDIT Dependencies:

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'

2条回答
仙女界的扛把子
2楼-- · 2019-09-06 21:37

There are two problematic libraries:

RoundCornerProgressBar

MPAndroidChart

The first problem is with the class com.akexorcist.roundcornerprogressbar.TextRoundCornerProgressBar. There is a solution here that overcomes the problem, by adding to Proguard:

-dontwarn com.akexorcist.roundcornerprogressbar.TextRoundCornerProgressBar

The second one is simply solved by adding two statements to Proguard that the author of the library clearly describes here:

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

Your Proguard file should contain those lines and the problems should disappear.

查看更多
smile是对你的礼貌
3楼-- · 2019-09-06 21:49

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'
    }
}
查看更多
登录 后发表回答