機能 | 説明 |
圧縮 | 使用されていないクラス、フィールド、メソッド、属性の削除。不要処理が削除されるのでアプリケーションのサイズが小さくなります。 |
最適化 | メソッドのバイトコードを解析し最適化します。 |
難読化 | クラス、フィールド、メソッドを無意味な名前に置き換えます。 |
事前検証 | クラスに事前検証情報を付加することで、起動速度を向上させます。 |
proguard.config=proguard.cfg※proguard.cfgがプロジェクトフォルダ直下にある場合の例です
-optimizations !code/simplification/arithmetic,!code/simplification/cast,!field/*,!class/merging/* -optimizationpasses 5 -allowaccessmodification -dontpreverify -dontusemixedcaseclassnames -dontskipnonpubliclibraryclasses -verbose -keepattributes *Annotation* -keep public class com.google.vending.licensing.ILicensingService -keep public class com.android.vending.licensing.ILicensingService # For native methods, see http://proguard.sourceforge.net/manual/examples.html#native -keepclasseswithmembernames class * { native <methods>; } # keep setters in Views so that animations can still work. # see http://proguard.sourceforge.net/manual/examples.html#beans -keepclassmembers public class * extends android.view.View { void set*(***); *** get*(); } # We want to keep methods in Activity that could be used in the XML attribute onClick -keepclassmembers class * extends android.app.Activity { public void *(android.view.View); } # For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations -keepclassmembers enum * { public static **[] values(); public static ** valueOf(java.lang.String); } -keep class * implements android.os.Parcelable { public static final android.os.Parcelable$Creator *; } -keepclassmembers class **.R$* { public static <fields>; } # The support library contains references to newer platform versions. # Don't warn about those in case this app is linking against an older # platform version. We know about them, and they are safe. -dontwarn android.support.**
-libraryjars \libs\sample.jar -keepclasseswithmembers class <sample.jarで使用されているパッケージ>.** { *; }併せて、属性保護設定も追加することがお勧めです(特にSignature)。
-keepattributes *Annotation*,Exception,Signature,InnerClass以上でProguardに関する紹介は終了ですが、Proguardを適用するとエラーが発生することがあります。 いくつか対処方法を紹介しておきます。
エラー | 対処方法 |
Eclipseのコンソールに外部jarに対する大量のWarningが出てアプリが作成できない | -dontwarnオプションを設定して試してください。 例えば、外部jarがcom.sample.xxxxというパッケージであれば、 -dontwarn com.sample.** のように記述します。 |
外部jar内のクラスに関してsuperクラスが見えない的なエラーが出る | 最適化を行わないか、1回にして試してみてください 最適化なし:-dontoptimize 最適化1回:-optimizationpasses 1 |
難読化したアプリでサービスがバインドできない | aidlファイルから自動生成されたjavaコードが難読化されている影響の可能性があります。 aidlファイルから自動生成されるファイルを難読化対象外にしてみてください -keep class * extends android.os.IInterface -keep class * extends android.os.Binder |