36

プロガードを使用したばかりですが、リフレクションを介してインスタンス化しようとしているクラスが機能していません。

私はインターフェースを持っています

Algorithm

私はこのようなクラスを渡します

AlgorithmFactory.SomeClassThatExtendsAlgorithmImpl.class

クラスはこのようにインスタンス化されます

public ArrayList<Algorithm> getAlgorithms(Context cnx) {
ArrayList<Algorithm> list = new ArrayList<Algorithm>();

for(Class<? extends Algorithm> alg: algorithms) {

    try {
        Constructor<? extends Algorithm> c = alg.getConstructor(Context.class);
        list.add(c.newInstance(cnx));
    } catch (IllegalArgumentException e) {
        Log.e(TAG, "IllegalArgumentException", e);
        throw new IllegalStateException("There was a problem creating the Algorithm class");
    } catch (InvocationTargetException e) {
        Log.e(TAG, "InvocationTargetException", e);
        throw new IllegalStateException("There was a problem creating the Algorithm class");
    } catch (InstantiationException e) {
        Log.e(TAG, "InstantiationException", e);
        throw new IllegalStateException("There was a problem creating the Algorithm class");
    } catch (IllegalAccessException e) {
        Log.e(TAG, "IllegalAccessException", e);
        throw new IllegalStateException("There was a problem creating the Algorithm class");
    } catch (SecurityException e) {
        Log.e(TAG, "SecurityException", e);
        throw new IllegalStateException("There was a problem creating the Algorithm class");
    } catch (NoSuchMethodException e) {
        Log.e(TAG, "NoSuchMethodException", e);
        throw new IllegalStateException("There was a problem creating the Algorithm class");
    }
}
return list;
}

ここに私のproguard.cnfがあります

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*

-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 com.android.vending.licensing.ILicensingService


-keepclasseswithmembernames class * {
    native <methods>;
}

-keepclasseswithmembernames class * {
    public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembernames class * {
    public <init>(android.content.Context, android.util.AttributeSet, int);
}

-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}

-assumenosideeffects class android.util.Log {
    public static *** d(...);
    public static *** v(...);
    public static *** i(...);
    public static *** w(...);
    public static *** e(...);
}
4

3 に答える 3

61

解決済み

この問題を抱えている他の人のために、あなたはproguard.cnfに以下を追加する必要があります

-keep public class * extends com.yoursite.android.yourappname.YourClassName

-keepclassmembers class * extends com.yoursite.android.yourappname.YourClassName{
 public <init>(android.content.Context);
}

最初のキープは、YourClassNameを拡張するクラス名を難読化しないようにプロガードに指示します

2つ目は、コンストラクター名(<init>コンストラクターを意味する)を難読化せずに保持することを示しています。ContextYourClassName

さらに、XMLレイアウトファイルでonClick属性を使用しているAndroid開発者の場合は、proguard.cnfファイルに関数の名前を追加する必要もあります。

-keepclassmembers class * {
 public void myClickHandler(android.view.View);
}

これは、すべてのクラスでmyClickHandler単一の引数で名前が付けられたすべてのメソッドを保持することを意味します。View上記のようにextendsキーワードを使用すると、これをさらに制限できます。

お役に立てれば。

于 2010-12-16T03:41:28.347 に答える
18

クリック時の修正では、各メソッド名をリストする必要はありません。できるよ:

-keepclassmembers class * {
   public void *(android.view.View);
}

View as パラメータを持つすべてのメソッドを検索します。

于 2010-12-16T16:34:12.230 に答える