按照@AlexWein 在这个问题中的建议并查看ProGuard Troubleshooting,我在 SherlockFragment 中有以下内容:
Class<?> c = Class.forName("co.uk.MyApp.pdf.MyData");
Method main = c.getDeclaredMethod("pdfsleep", Report_Holder.class);
Report_Holder paramsh = null;
paramsh = SRH;
main.invoke(null, (Object)paramsh);
“co.uk.MyApp.pdf.Data”构造函数是:
public class MyData {
public static void pdfsleep(Report_Holder args) {
...
}
}
Proguard 的设置如下:
-keepnames class co.uk.MyApp.classes.Report_Holder
-keepclassmembers class co.uk.MyApp.pdf.Data { public static void pdfsleep(Report_Holder); }
-keepnames class co.uk.MyApp.DataActivity
但我仍然收到 NoSuchMethodException:
05/23/13 12:14:28 GMT+01:00 ERROR AsyncTask #2 - java.lang.NoSuchMethodException: pdfsleep [class co.uk.MyApp.classes.Report_Holder]
at java.lang.Class.getConstructorOrMethod(Class.java:460)
at java.lang.Class.getDeclaredMethod(Class.java:685)
at co.uk.MyApp.fy.a(Unknown Source)
at co.uk.MyApp.fy.doInBackground(Unknown Source)
at android.os.AsyncTask$2.call(AsyncTask.java:264)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
我错过了什么?
更新
我已将 Proguard 行更改为:
-keepattributes Signature
-keepnames class co.uk.MyApp.classes.Report_Holder
-keepclasseswithmembers class co.uk.MyApp.DataActivity
-keepclasseswithmembers class co.uk.MyApp.pdf.Data { void pdfsleep(Report_Holder); }
而且我仍然收到错误。
查看映射文件,我认为我看到了导致问题的原因:
co.uk.MyApp.classes.Report_Holder -> co.uk.MyApp.classes.Report_Holder:
co.uk.MyApp.DataActivity -> co.uk.MyApp.DataActivity:
java.util.ArrayList arrDataItems -> a
co.uk.MyApp.classes.Report_Holder SRH -> b
看起来 Proguard 保留了对 co.uk.MyApp.classes.Report_Holder 的引用,但在将其作为 co.uk.MyApp.DataActivity 的子项引用时对其进行了混淆。
我尝试了不同的方法来保留 co.uk.MyApp.DataActivity,试图让它停止混淆 co.uk.MyApp.classes.Report_Holder,但无法正确获取语法。有什么建议么?
更新 2
我已经按照 Eric Lafortune 的建议更新了一些代码和 ProGuard 配置文件(顺便说一句,我现在正在显示正确的包/类名):
在 co.uk.FibroApp.SleepDataActivity
Class<?> c = Class.forName("co.uk.FibroApp.pdf.SleepData");
Method main = c.getDeclaredMethod("pdfsleep", co.uk.FibroApp.classes.SleepReport_Holder.class);
SleepReport_Holder paramsh = SRH;
co.uk.FibroApp.pdf.SleepData 是:
public class SleepData {
public static void pdfsleep(co.uk.FibroApp.classes.SleepReport_Holder args) {
...
}
}
完整的 ProGuard 配置是:
-keepattributes Signature
-keep class co.uk.FibroApp.classes.SleepReport_Holder
-keep class co.uk.FibroApp.pdf.SleepData
-keepclassmembers class co.uk.FibroApp.pdf.SleepData {
public static void pdfsleep(co.uk.FibroApp.classes.SleepReport_Holder);
}
# do not obfuscate the classes from droidtext but shrink them
-keep,allowshrinking class harmony.java.awt.** { *; }
-keep,allowshrinking class org.apache.harmony.** { *; }
-keep,allowshrinking class org.bouncycastle.** { *; }
-keep class android.support.v4.app.** { *; }
-keep interface android.support.v4.app.** { *; }
-keep class com.actionbarsherlock.** { *; }
-keep interface com.actionbarsherlock.** { *; }
-keepattributes *Annotation*
完整的错误日志是:
05/24/13 08:25:52 WEST ERROR AsyncTask #2 - java.lang.NoSuchMethodException: sleeppdf [class co.uk.FibroApp.classes.SleepReport_Holder]
at java.lang.Class.getConstructorOrMethod(Class.java:460)
at java.lang.Class.getDeclaredMethod(Class.java:685)
at co.uk.FibroApp.fy.a(Unknown Source)
at co.uk.FibroApp.fy.doInBackground(Unknown Source)
at android.os.AsyncTask$2.call(AsyncTask.java:264)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)