I try to compress an android app that consumes ical4j.jar
.
When i build the apk with proguard using gradle proguardDebug
i get
finalize()
clone()
I already verified that android-7 supports finalize()
and clone()
: "...\Android...\sdk\platforms\android-7\android.jar" has methods finalize()
and clone()
in class java.lang.Object
.
Do you have any idea how to fix this?
Note: this is not a duplicate of other 'proguard can't find referenced method' questions because in my specific case i think that the missing method should be there.
I am using
this is proguard config proguard-rules.txt
that probably need some fix:
# proguard-rules.txt
## ical4j also contains groovy code which is not used in android
-dontwarn groovy.**
-dontwarn org.codehaus.groovy.**
-dontwarn org.apache.commons.logging.**
-dontwarn sun.misc.Perf
-dontnote com.google.vending.**
-dontnote com.android.vending.licensing.**
This is my build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
classpath 'net.sf.proguard:proguard-gradle:4.11'
}
}
allprojects {
repositories {
mavenCentral()
}
}
apply plugin: 'android'
configurations {
compile.exclude group: 'commons-logging' // referenced in some portable lib. use androids internal instead
}
android {
compileSdkVersion 19
buildToolsVersion '19.0.3'
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
defaultConfig {
minSdkVersion 7
targetSdkVersion 19
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
// used for testing. remove if it works as expected
debug {
runProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'org.mnode.ical4j:ical4j:1.0.5'
compile 'backport-util-concurrent:backport-util-concurrent:3.1'
compile 'commons-codec:commons-codec:1.8'
compile 'commons-lang:commons-lang:2.6'
}
[Update 2014-12-20]
I have added my working configuration as answer below.
Note: with Current Android Studio 1.0 (android.buildToolsVersion >= '20') you must replace runProguard with minifyEnabled
Example
android {
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
net.fortuna.ical4j.model.CalendarFactory
extends groovy.util.AbstractFactory
which extends java.lang.Object
. However, the middle class is missing from your input (you're suppressing the corresponding warnings with -dontwarn). With part of the class hierarchy missing, ProGuard doesn't realize that CalendarFactory may access the protected methods clone
and finalize
, and it prints out these warnings.
Since your code probably doesn't use the class at all, you can suppress the warnings:
-dontwarn net.fortuna.ical4j.model.CalendarFactory
Or for covering all similar classes:
-dontwarn net.fortuna.ical4j.model.**
You shouldn't add any -keep options for this issue; the Android SDK already specifies the basic Android-related -keep options for you.