当使用proguard for android应用程序时,反射方法不起作用

时间:2011-10-22 12:15:49

标签: android reflection proguard telephony

当我使用proguard用于在android中使用反射使用telephonyservice apis的应用程序时,我遇到了问题。

我已经定义了一个包com.android.internal.telephony,并且我已经复制了ITelephony.aidl文件。

以下是我使用反射电话方法的代码片段。

Class<?> c = Class.forName(tm.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
com.android.internal.telephony.ITelephony telephonyService = 
     (com.android.internal.telephony.ITelephony) m.invoke(tm);

    if(buttonInAction == acceptButton){
       Log.v(TAG, "Answering the call");
       telephonyService.answerRingingCall();
       finish();
    }
    else{
       Log.v(TAG, "Rejecting the call");
       telephonyService.endCall();
       finish();
    }

现在没有proguard我可以使用这个api,但是当我使用proguard进行compliling时,它会给出classcastexception。我知道我需要在proguard.cfg文件中添加一些东西,我也尝试了几个东西,比如-dontshrink -dontoptimize,但它仍然不起作用。

如果我遗漏了需要在该文件中添加的内容或此问题的任何其他解决方案,请告诉我。 谢谢 纳瓦布

1 个答案:

答案 0 :(得分:18)

这解决了问题:

-keep class com.android.internal.telephony.ITelephony { *; }