12

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

B770
  • 1,272
  • 3
  • 17
  • 34
nawab
  • 362
  • 4
  • 9
  • possible duplicate of [Proguard and reflection in Android](http://stackoverflow.com/questions/4447145/proguard-and-reflection-in-android) – Peter Knego Oct 22 '11 at 12:21
  • 1
    I already looked at it but did not help me much. – nawab Oct 22 '11 at 12:24
  • I think i have found the answer....i used the option -keeppackagenames and it is working. I am still verifying it. Will post if it is the correct solution of this problem. – nawab Oct 22 '11 at 12:35
  • Yeah it had worked...:) – nawab May 21 '15 at 11:52

1 Answers1

18

This solves issue:

-keep class com.android.internal.telephony.ITelephony { *; }
Jakub Szczygieł
  • 1,203
  • 1
  • 13
  • 26
  • it worked perfectly, i faced a problem when i applied this fix initially because i wasn't paying attention, I added the line but forgot to add the file to the build.cradle. it should be added like this::::: proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),'proguard-project.txt':::::: – A.Alqadomi Apr 29 '15 at 14:07
  • not work ,it complains SecurityException: null from uid 10320 not allowed to perform CALL_PHONE – hoot Aug 13 '16 at 03:41