LoginSignup
20
20

More than 5 years have passed since last update.

ProGuardのメモ

Posted at

まだよくわからないけど、利用するライブラリによってProGuardの指定をきちんとしないと動かなかったりするらしい。

Google Play Services

ドキュメントによると以下の指定が必要らしい。

-keep class * extends java.util.ListResourceBundle {
  protected Object[][] getContents();
}

-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
  public static final *** NULL;
}

-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
  @com.google.android.gms.common.annotation.KeepName *;
}

-keepnames class * implements android.os.Parcelable {
  public static final ** CREATOR;
}

OrmLite

OrmLite DAOはリフレクションを使うため、下記指定が必要らしい。

-keep class com.j256.**
-keepclassmembers class com.j256.** { *; }
-keep enum com.j256.**
-keepclassmembers enum com.j256.** { *; }
-keep interface com.j256.**
-keepclassmembers interface com.j256.** { *; }

Logger

Caused by: java.lang.ClassCastException: The application has specified that a custom LogFactory implementation should be used but Class 'org.apache.commons.logging.impl.LogFactoryImpl' cannot be converted to 'xc'. Please check the custom implementation. Help can be found @http://commons.apache.org/logging/troubleshooting.html.
…みたいなエラーメッセージが出る場合は、下記指定をすると良いらしい。

-keep public class org.apache.commons.** { *; }

コンストラクター

コードから明示的に使われていないコンストラクターが除去されてしまう場合は、除去しない設定を書く。

-keepclassmembers class * {
   public <init>(android.content.Context);
}

EventBus

EventBusはリフレクションでonEventメソッドを探すので、下記指定が必要。

-keepclassmembers class ** {
     public void onEvent(**);
 }

JSONマッピング用、DBエンティティ用クラス

GsonみたいなJSONマッピング機能やOrmLiteのようなORM機能はリフレクションでフィールドを取得するので、それらのデータを表すためのクラスはフィールドを削除したりしない指定が必要。

-keepattributes *Annotation*
-keepclassmembers class com.my.app.data.using.ormlite.** { *; }

ProGuardめんどくさいよう…

20
20
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20
20