Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reflection methods are not working when used proguard for android application

I am facing a problem when i use proguard for application having used telephonyservice apis using reflection in android.

I have defined a package com.android.internal.telephony and there i have copied ITelephony.aidl file.

Here is the snippet of the code where i am using the methods of telephony using reflection.

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();
    }

Now without proguard i am able to use this apis, but when i use proguard for compliling, it gives classcastexception. I know i need to add something in proguard.cfg file and i also tried several things like -dontshrink -dontoptimize, but still it did not work.

Please let me know if i am missing something which needs to be added in that file or any other solution to this problem. Thanks Nawab

like image 933
nawab Avatar asked Oct 22 '11 12:10

nawab


1 Answers

This solves issue:

-keep class com.android.internal.telephony.ITelephony { *; }
like image 132
Jakub Szczygieł Avatar answered Sep 19 '22 21:09

Jakub Szczygieł