2

I have a fairly large project that uses some reflection in the code. The line of code that is causing the following crash:

W/System.err(22122): java.lang.NoSuchMethodException: <init> [class com.DynaZu.Tracker.cd]
W/System.err(22122):    at java.lang.Class.getConstructorOrMethod(Class.java:460) 
W/System.err(22122):    at java.lang.Class.getDeclaredConstructor(Class.java:588)
W/System.err(22122):    at com.DynaZu.Tracker.ItemAdapter.getView(SourceFile:356)
W/System.err(22122):    at android.widget.AbsListView.obtainView(AbsListView.java:2267)

Is the SourceFile:356 line:

try {
    itemViewHolder = mViewHolderClass.getDeclaredConstructor(item.getClass())
                       .newInstance(item);
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            } catch (NoSuchMethodException e) {
                e.printStackTrace();
            }

elsewhere in the file:

Class<? extends ItemViewHolder> mViewHolderClass;

and the item is one of several potential classes all derived from class Item.

When I look into dump.txt, etc... I see lots and lots of stuff I can't quite turn back into a specific directive for proguard.cfg. From dump.txt:

 + Methodref [com/DynaZu/Tracker/cd.<init> (Ljava/lang/String;)V]
 + Methodref [com/DynaZu/Tracker/cd.a ()Ljava/lang/String;]
 + Methodref [com/DynaZu/Tracker/cd.equals (Ljava/lang/Object;)Z]
 + Methodref [com/DynaZu/Tracker/cd.h ()J]
 + Methodref [com/DynaZu/Tracker/cd.o ()Ljava/lang/String;]
 + Methodref [com/DynaZu/Tracker/cd.p ()Lcom/DynaZu/Tracker/cd;]
 + Methodref [com/DynaZu/Tracker/cd.q ()F]
 + Methodref [com/DynaZu/Tracker/ce.a (J)Lcom/DynaZu/Tracker/cd;]
 + Methodref [com/DynaZu/Tracker/ce.a (Lcom/DynaZu/Tracker/cd;)V]
 + InterfaceMethodref [com/DynaZu/Tracker/ac.a (IILcom/DynaZu/Tracker/cd;ZZ)V]
 + NameAndType [<init> (Lcom/DynaZu/Tracker/cd;)V]
 + NameAndType [a (IILcom/DynaZu/Tracker/cd;ZZ)V]
 + NameAndType [a (J)Lcom/DynaZu/Tracker/cd;]
 + NameAndType [a (Lcom/DynaZu/Tracker/cd;)V]
 + NameAndType [a Lcom/DynaZu/Tracker/cd;]
 + NameAndType [b (Lcom/DynaZu/Tracker/cd;I)V]
 + NameAndType [c Lcom/DynaZu/Tracker/cd;]
 + NameAndType [p ()Lcom/DynaZu/Tracker/cd;]
 + Utf8 [()Lcom/DynaZu/Tracker/cd;]

And for proguard.cfg I realize I want something like:

-keepclassmembers class * extends Item
-keep class * extends Item

Any suggestions would be helpful. For example, is there a way to turn of proguard for one java file or one section of this java file???

Looking into this, I believe I need to add something like:

-keepclassmembers class com.DynaZu.Tracker.TaskViewHolder
{
  <init>(com.DynaZu.Tracker.Task);
}

etc... BUT ProGuard complains these class are Unknown... ? So how should an existing class in the project be noted in proguard.cfg. ??? I have also tried just the class name TaskViewHolder by itself.

Extreme Coders
  • 3,441
  • 2
  • 39
  • 55
JoelParke
  • 2,676
  • 2
  • 24
  • 38

1 Answers1

2

I was able to resolve this by looking into the proguard/.. dump.txt and especially mapping.txt. From there I understood how some of my classes were named. So I added the following to my proguard.cfg:

-keepclassmembers class com.DynaZu.Tracker.ItemViewHolder$TaskViewHolder
{
  <init>(com.DynaZu.Tracker.Task);
}
-keepclassmembers class com.DynaZu.Tracker.ItemViewHolder$ProjectViewHolder
{
  <init>(com.DynaZu.Tracker.Project);
}
-keepclassmembers class com.DynaZu.Tracker.ItemViewHolder
{
  <init>(com.DynaZu.Tracker.Item);
}
-keep class com.DynaZu.Tracker.Item
-keep class com.DynaZu.Tracker.Task
-keep class com.DynaZu.Tracker.Project

Once I understood what was going on, it wasn't hard. I hope this helps someone else with this difficultly. I have to say that having a community and the availability of Stack Overflow is a life saver!

JoelParke
  • 2,676
  • 2
  • 24
  • 38