title: Proguard and reflection in Android
body: <p>I have just used proguard, but classes I am trying to instantiate via reflection are not working.</p>
  
  <p>I have an interface</p>
  
  <pre><code>Algorithm
  </code></pre>
  
  <p>I pass classes like this</p>
  
  <pre><code>AlgorithmFactory.SomeClassThatExtendsAlgorithmImpl.class
  </code></pre>
  
  <p>The class is instantiated like this</p>
  
  <pre><code>public ArrayList&lt;Algorithm&gt; getAlgorithms(Context cnx) {
  ArrayList&lt;Algorithm&gt; list = new ArrayList&lt;Algorithm&gt;();
  
  for(Class&lt;? extends Algorithm&gt; alg: algorithms) {
  
      try {
          Constructor&lt;? extends Algorithm&gt; 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;
  }
  </code></pre>
  
  <p>Here is my proguard.cnf</p>
  
  <pre><code>-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 &lt;methods&gt;;
  }
  
  -keepclasseswithmembernames class * {
      public &lt;init&gt;(android.content.Context, android.util.AttributeSet);
  }
  
  -keepclasseswithmembernames class * {
      public &lt;init&gt;(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(...);
  }
  </code></pre>