0

I am using Kofax in our project, and it uses a lot of Reflection and Robogiuice. We are using Dexguard to obfuscate our code. One of the problems we have is the private constructor was stripped. I already have this in my code:

-keepclassmembers class *  {
   private <init>(...);
}

But it does not help, some of my class's constructors are still stripped.

1) Could not find a suitable constructor in >com.kofax.mobile.sdk.capture.MainModule$ReflectionMakeSize. Classes must have >either one (and only one) constructor annotated with @Inject or a zero-argument >constructor that is not private. at >com.kofax.mobile.sdk.capture.MainModule$ReflectionMakeSize.class(Unknown >Source) at >com.kofax.mobile.sdk.capture.MainModule.configure(:145)

Anyone knows how to fix this?

EDIT.

I just found out that, only constructor of the private static class are removed, other class's constructor still there.

Anyone knows why?

Kent
  • 1
  • 3

2 Answers2

0

One of the solutions might be to add @Keep annotation before such constructor
For example:

@Keep
private Adapter(FragmentActivity mActivity, List<RowModel> list) {
    super(mActivity, list);
}
R. Zagórski
  • 20,020
  • 5
  • 65
  • 90
  • Thanks. However the code got stripped is inside a library, so I cannot add the `@keep` annotation – Kent Jul 29 '16 at 09:31
  • @Keep does not just keep the method but the whole class. – Mr. Fish Apr 07 '17 at 11:50
  • [The documentation](https://developer.android.com/reference/android/support/annotation/Keep.html) states, that `@Keep` is applicable to methods also. Of course, if you keep one method from class it has to keep the refrence to the whole class, that is obvious. – R. Zagórski Apr 09 '17 at 09:12
0

The error message says that you must have either a constructor that is annotated with @Inject or a non-private constructor without arguments.

So I would add rules like that:

-keepclassmembers class * {
    !private <init>();
    @com.google.inject.Inject <init>(...);
    @javax.inject.Inject <init>(...);
}

I added both, the com.google.inject Inject annotation as well as the one from javax.inject as I was not sure which one is referred to from kofax. You may remove the unneeded one.

T. Neidhart
  • 6,060
  • 2
  • 15
  • 38
  • Thanks T. Neidhart. But when I add the snippet you suggested I got this error: `> Can't find common super class of [org/apache/log4j/chainsaw/LoadXMLAction] (with 1 known super classes) and [java/lang/NoClassDefFoundError] (with 5 known super classes)` – Kent Jul 29 '16 at 12:35
  • This error is unrelated to the configuration from above. The problem with the log4j class is known and happens on Android as swing is not available, see the answer from Eric here: http://stackoverflow.com/questions/16667022/proguard-cant-find-any-super-classes – T. Neidhart Jul 29 '16 at 15:00
  • Thanks, it was another setting. But the suggested setting does not work either. I have checked the mapping and, unused classes. One thing very weird is, in the output map, I can see that the constructor is there, but when I decompile the apk, it was not there ```com.kofax.mobile.sdk.capture.MainModule$ReflectionMakeSize -> com.kofax.mobile.sdk.capture.MainModule$ReflectionMakeSize: 215:215:void () -> 221:228:android.hardware.Camera$Size makeSize(android.graphics.Point) -> makeSize``` – Kent Jul 30 '16 at 10:31