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!
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.
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')
}
}
来源:https://stackoverflow.com/questions/41377007/errorexecution-failed-for-task-apptransformclassesandresourceswithproguardfo