如何告诉proguard不要在我班级中混淆某些方法名称?

时间:2012-10-09 18:31:36

标签: android proguard

我正在使用的外部集合库允许我在自定义对象列表上执行where方法。它需要我想要过滤的方法/属性名称,并将其作为字符串。由于混淆完成,该方法似乎不存在。

我试图告诉proguard不要混淆该对象上的方法,但它不起作用。

在proguard配置中,我正在尝试这个

-keep public class com.mop.mobile.myproject.obj.MyClass**
-keepnames public class com.mop.mobile.myproject.obj.MyClass**

这是logcat跟踪

E/AndroidRuntime(20419): FATAL EXCEPTION: main
E/AndroidRuntime(20419): java.lang.RuntimeException: Unable to start activity Co
mponentInfo{com.mop.mobile.myproject/com.mop.mobile.myproject.MyPagerActivity}: java.la
ng.RuntimeException: java.lang.RuntimeException: java.lang.NoSuchMethodException
: getMyId []
E/AndroidRuntime(20419):        at android.app.ActivityThread.performLaunchActiv
ity(ActivityThread.java:2059)
E/AndroidRuntime(20419):        at android.app.ActivityThread.handleLaunchActivi
ty(ActivityThread.java:2084)
E/AndroidRuntime(20419):        at android.app.ActivityThread.access$600(Activit
yThread.java:130)
E/AndroidRuntime(20419):        at android.app.ActivityThread$H.handleMessage(Ac
tivityThread.java:1195)
E/AndroidRuntime(20419):        at android.os.Handler.dispatchMessage(Handler.ja
va:99)
E/AndroidRuntime(20419):        at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(20419):        at android.app.ActivityThread.main(ActivityThrea
d.java:4745)
E/AndroidRuntime(20419):        at java.lang.reflect.Method.invokeNative(Native
Method)
E/AndroidRuntime(20419):        at java.lang.reflect.Method.invoke(Method.java:5
11)
E/AndroidRuntime(20419):        at com.android.internal.os.ZygoteInit$MethodAndA
rgsCaller.run(ZygoteInit.java:786)
E/AndroidRuntime(20419):        at com.android.internal.os.ZygoteInit.main(Zygot
eInit.java:553)
E/AndroidRuntime(20419):        at dalvik.system.NativeStart.main(Native Method)

E/AndroidRuntime(20419): Caused by: java.lang.RuntimeException: java.lang.Runtim
eException: java.lang.NoSuchMethodException: getMyId []
E/AndroidRuntime(20419):        at com.a.a.b.a.a.a(Unknown Source)
E/AndroidRuntime(20419):        at com.a.a.b.a.b.a(Unknown Source)
E/AndroidRuntime(20419):        at com.a.a.b.a.a(Unknown Source)
E/AndroidRuntime(20419):        at com.mop.mobile.myproject.MyPagerActivity.a(Unknow
n Source)
E/AndroidRuntime(20419):        at com.mop.mobile.myproject.MyPagerActivity.onCreate
(Unknown Source)
E/AndroidRuntime(20419):        at android.app.Activity.performCreate(Activity.j
ava:5008)
E/AndroidRuntime(20419):        at android.app.Instrumentation.callActivityOnCre
ate(Instrumentation.java:1079)
E/AndroidRuntime(20419):        at android.app.ActivityThread.performLaunchActiv
ity(ActivityThread.java:2023)
E/AndroidRuntime(20419):        ... 11 more
E/AndroidRuntime(20419): Caused by: java.lang.RuntimeException: java.lang.NoSuch
MethodException: getMyId []
E/AndroidRuntime(20419):        at com.a.a.c.a.a(Unknown Source)
E/AndroidRuntime(20419):        ... 19 more
E/AndroidRuntime(20419): Caused by: java.lang.NoSuchMethodException: getOverallP
riorityId []
E/AndroidRuntime(20419):        at java.lang.Class.getConstructorOrMethod(Class.
java:460)
E/AndroidRuntime(20419):        at java.lang.Class.getMethod(Class.java:915)
E/AndroidRuntime(20419):        ... 20 more
W/ActivityManager(  307):   Force finishing activity com.mop.mobile.myproject/.Asse
tListPager
W/ActivityManager(  307):   Force finishing activity com.mop.mobile.myproject/.Near
MeActivity
W/ActivityManager(  307): Activity pause timeout for ActivityRecord{435fbdc0 com
.mop.mobile.myproject/.MyPagerActivity}
I/ActivityManager(  307): No longer want com.google.android.gms (pid 20052): hid
den #16
W/System.err(20419): IOException processing: 26
W/System.err(20419): java.io.IOException: Server returned: 3
W/System.err(20419):    at android_maps_conflict_avoidance.com.google.googlenav.
map.BaseTileRequest.readResponseData(BaseTileRequest.java:115)
W/System.err(20419):    at android_maps_conflict_avoidance.com.google.googlenav.
map.MapService$MapTileRequest.readResponseData(MapService.java:1473)
W/System.err(20419):    at android_maps_conflict_avoidance.com.google.googlenav.
datarequest.DataRequestDispatcher.processDataRequest(DataRequestDispatcher.java:
1117)
W/System.err(20419):    at android_maps_conflict_avoidance.com.google.googlenav.
datarequest.DataRequestDispatcher.serviceRequests(DataRequestDispatcher.java:994
)
W/System.err(20419):    at android_maps_conflict_avoidance.com.google.googlenav.
datarequest.DataRequestDispatcher$DispatcherServer.run(DataRequestDispatcher.jav
a:1702)
W/System.err(20419):    at java.lang.Thread.run(Thread.java:856)
W/ActivityManager(  307): Activity destroy timeout for ActivityRecord{42a743d0 c
om.mop.mobile.myproject/.myprojectActivity}
W/ActivityManager(  307): Activity destroy timeout for ActivityRecord{435fbdc0 c
om.mop.mobile.myproject/.MyPagerActivity}

2 个答案:

答案 0 :(得分:3)

试试这个:

-keep public class com.mop.mobile.myproject.obj.MyClass { *; }

而不是

-keep public class com.mop.mobile.myproject.obj.MyClass**

答案 1 :(得分:2)

告诉proguard不要混淆某个类使用的方法/属性 这些线......

keepclassmembers class com.mop.mobile.myproject.obj.MyClass{*;}

keepattributes com.mop.mobile.myproject.obj.MyClass

它对我有用。