vendredi 8 décembre 2017

How to allow Reflection for a Class method using Proguard

I have Proguard enabled for my Library.

In my Library I have a Class called Hard.

I then use this library in my APP. I then try call this the Library Class Hard and it's method called onOrientationChange() using Reflection.

  Class noParams[] = {};
                Class[] paramContext = new Class[1];
                paramContext[0] = Context.class;
                Class[] paramActivity = new Class[1];
                paramActivity[0] = Activity.class;
                Class push = null;
                try {
                    push = Class.forName("com.test.example.Hard");
                    if (null != push) {
                        Constructor constructor = push.getDeclaredConstructor();
                        Object clazz = constructor.newInstance();
                        Method enteringActivity = clazz.getClass().getDeclaredMethod("onOrientationChange", paramActivity);
                        enteringActivity.invoke(clazz, activity);
                    }
                } catch (ClassNotFoundException e1) {
                    Log.w(Util.TAG, "method Orientation is not present");
                } catch (IllegalAccessException e1) {
                    e1.printStackTrace();
                } catch (NoSuchMethodException e1) {
                    e1.printStackTrace();
                } catch (InvocationTargetException e1) {
                    e1.printStackTrace();
                } catch (InstantiationException e) {
                    e.printStackTrace();
                }

But when i Try use the Library in my blank App i get the No such Method Exception Error.

java.lang.NoSuchMethodException: onOrientationChange [class android.app.Activity]

Here is my Library Class with it's method. package com.test.example;

public class Hard extends TelephoneBase implements WidgetClickListener, Constants {

  public void onOrientationChange(Activity activity) {
        TestExample(activity);
    }

}

Here is the Proguard.pro file

-keep class javax.** { *; }
-keep class org.** { *; }
-keep class twitter4j.** { *; }

-keep class class com.test.example.Hard { *; }
-keepclassmembers class com.test.example.Hard { *; }

-dontpreverify
-dontoptimize
-dontshrink

Could someone please tell me what I am doing wrong?





Aucun commentaire:

Enregistrer un commentaire