Bug 709230 part 2 - Optimize Java .class files with ProGuard. r=dougt

This commit is contained in:
Chris Peterson 2012-01-26 10:50:37 -08:00
Родитель cad3854a5b
Коммит 059dae79c1
3 изменённых файлов: 106 добавлений и 1 удалений

Просмотреть файл

@ -48,6 +48,7 @@ endif
DX=$(ANDROID_PLATFORM_TOOLS)/dx
AAPT=$(ANDROID_PLATFORM_TOOLS)/aapt
APKBUILDER=$(ANDROID_SDK)/../../tools/apkbuilder
PROGUARD=java -jar $(ANDROID_SDK)/../../tools/proguard/lib/proguard.jar
ZIPALIGN=$(ANDROID_SDK)/../../tools/zipalign
ifdef JARSIGNER

Просмотреть файл

@ -586,7 +586,13 @@ classes.dex: $(FENNEC_JAVA_FILES) $(FENNEC_PP_JAVA_FILES) $(SYNC_JAVA_FILES) $(S
$(NSINSTALL) -D classes
$(JAVAC) $(JAVAC_FLAGS) -d classes $(addprefix $(srcdir)/,$(SYNC_THIRDPARTY_JAVA_FILES))
$(JAVAC) $(JAVAC_FLAGS) -Xlint:all,-deprecation,-fallthrough -d classes -classpath classes $(addprefix $(srcdir)/,$(FENNEC_JAVA_FILES)) $(FENNEC_PP_JAVA_FILES) $(addprefix $(srcdir)/,$(SYNC_JAVA_FILES)) $(SYNC_PP_JAVA_FILES) R.java
$(DX) --dex --output=$@ classes
$(PROGUARD) @$(topsrcdir)/mobile/android/config/proguard.cfg \
-injars classes \
-outjars classes-proguarded \
-libraryjars $(ANDROID_SDK)/android.jar
# ProGuard may optimize away local variables, so dx --no-locals to ignore
# debug symbols for missing local variables.
$(DX) --dex --output=$@ --no-locals classes-proguarded
PP_RES_XML=$(SYNC_PP_RES_XML)

Просмотреть файл

@ -0,0 +1,98 @@
#
# Rules from Google's example proguard.cfg in the Android SDK:
# android-sdk-macosx/tools/lib/proguard.cfg
#
# TODO: We can remove -dontskipnonpubliclibraryclasses for ProGuard >= 4.5
# because it is enabled by default.
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
# Preserve all fundamental application classes.
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
# Preserve all native method names and the names of their classes.
-keepclasseswithmembernames class * {
native <methods>;
}
# Preserve all classes that have special context constructors, and the
# constructors themselves.
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
# Preserve all classes that have special context constructors, and the
# constructors themselves.
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
# Preserve the special static methods that are required in all enumeration
# classes.
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
#
# Rules from ProGuard's Android example:
# http://proguard.sourceforge.net/manual/examples.html#androidapplication
#
# Switch off some optimizations that trip older versions of the Dalvik VM.
# https://code.google.com/p/android/issues/detail?id=964
-optimizations !code/simplification/cast
# Preserve all View implementations, their special context constructors, and
# their setters.
-keep public class * extends android.view.View {
public <init>(android.content.Context);
public <init>(android.content.Context, android.util.AttributeSet);
public <init>(android.content.Context, android.util.AttributeSet, int);
public void set*(...);
}
# Preserve the special fields of all Parcelable implementations.
-keepclassmembers class * implements android.os.Parcelable {
static android.os.Parcelable$Creator CREATOR;
}
# Preserve static fields of inner classes of R classes that might be accessed
# through introspection.
-keepclassmembers class **.R$* {
public static <fields>;
}
#
# Mozilla-specific rules
#
# Preserve public classes and methods accessed from C++ JNI.
-keep public class org.mozilla.gecko.** { public *; }
# Google defaults to 5 passes, but Fennec benefits from up to 9-10 passes.
-optimizationpasses 10
# Disable obfuscation because it makes exception stack traces more
# difficult to debug. Plus Firefox's code is already open-source.
-dontobfuscate
# Silence warnings about "Note: duplicate definition of library class".
-dontnote **,!org.mozilla.**
# Allow private members to be made public to improve method inlining.
# TODO: Enable -allowaccessmodification optimizations for ProGuard >= 4.6.
# These optimizations trigger a ProGuard 4.4 bug when inlining private methods.
##-allowaccessmodification