1

I have generated an APK of my Android application (as a try) and I did not have any problem, the APK has been generated correctly.

Now, I want to obfuscate my code while generating the APK so I used the following line on my release block on build.gradle file.

minifyEnabled true

The problem is that now it throws me the following error:

Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'. java.io.IOException: Please correct the above warnings first.

with a lot of warnings. To be more exact, 1018 warnings.

Most of them are like:

Warning:com.itextpdf.text.pdf.security.PdfPKCS7: can't find referenced class org.spongycastle.asn1.tsp.MessageImprint

or

Warning:com.github.mikephil.charting.data.realm.base.RealmBaseDataSet: can't find referenced class io.realm.Sort

Always is the same error. A class that cannot find a referenced class.

I am using MPAndroidChart so I think it is something related (because of the name of the packages that appears on the warnings) but I am not able to correct those warnings.

EDIT: As a prove, I have tried keeping the classes using:

-keep public class com.itextpdf.text.pdf.**

on my proguard-rules.pro file but I still have the same warnings.

My release section on build.gradle file is:

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

Am I missing something while obfuscating my code?

Thanks in advance!

David Rawson
  • 20,912
  • 7
  • 88
  • 124
Francisco Romero
  • 12,787
  • 22
  • 92
  • 167
  • [Check this](http://stackoverflow.com/questions/33589318/error-building-apk-when-minifyenabled-true) – Vygintas B Dec 29 '16 at 09:51
  • @VygintasB I do not think `-dontwarn` will be a safe option. I am trying using `-keep` the public classes but I am not able to make it to work. – Francisco Romero Dec 29 '16 at 11:55

2 Answers2

2

Finally, I have found that MPAndroidChart has a document in which tells you how to configure Proguard.

With the following configuration:

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

I was able to create the obfuscate APK without any warnings.

Also, I have noticed that itextpdf was a library that I used on the past but I did not need it nowadays so I just have to delete it from the dependencies on my gradle file and the warnings also have dissapeared.

Francisco Romero
  • 12,787
  • 22
  • 92
  • 167
1

I found a solution for this issue during apk generation.

Open build.gradle(app) and change build type as following.

buildTypes {
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt')
    }
}
CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440
Droid Genie
  • 351
  • 4
  • 15