在proguard的时候, 我们的类也会被混淆掉,导致出现
java.lang.NoSuchMethodException: [class android.content.Context这个错误
解决, 在proguard声明不要混淆需要实例化类的构造函数
-keepclassmembers class * extends com.hzy.tvmao.ir.engine.BaseIR{
public <init>(android.content.Context);
}
我这里使用了一个工厂类来创建extends BaseIR的实例
/*** IREngine的工厂, 使用方式是<br>* sBaseIREngine = IREngineFactory.getBaseIR(SamsungIR.class,* TmApp.getContext());* * @author gaoshuai* */
public class IREngineFactory {
public static BaseIR getIR(Class<? extends BaseIR> clazz, Context context, int test) {
try {Constructor<? extends BaseIR> constructor = clazz.getDeclaredConstructor(Context.class, int.class);constructor.setAccessible(true);BaseIR a1 = (BaseIR) constructor.newInstance(context, test);LogUtil.i(a1.getName() + " ir service found");return a1;}catch (Throwable e) {e.printStackTrace();LogUtil.i("IR Throwable t.toString=" + e.toString());}return null;}public static BaseIR getIR(Class<? extends BaseIR> clazz, Context context) {
// TODO Auto-generated method stubreturn null;}
}
http://stackoverflow.com/questions/4447145/proguard-and-reflection-in-android