android:onClick 不适用于 ProGuard
从今天开始,我的应用程序发生了一些奇怪的事情。每次我单击设置了 android:onClick 属性的按钮时,我都会收到一个 IllegalStateException: Could not find a method ...
我注意到只有当我在文件中启用 Proguard 时才会发生这种情况:default。这
是我的 proguard.cfg:
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService
-keepclasseswithmembernames class * {
native <methods>;
}
-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
问题是上周没有发生。(我也在使用 proguard)。有什么想法吗?
编辑 我找到了解决这个问题的另一种方法: 有问题的项目是使用旧版本的ADT插件(Eclipse)创建的。我创建了一个具有相同参数的新项目,并复制了 src/、res/ 和 Manifest,问题就解决了!
Since today, something weird is happening with my application. Every time I click a button that has set the android:onClick attribute, I get an IllegalStateException: Could not find a method ...
I noticed that only happens when I enable Proguard in the file: default.properties
This is my proguard.cfg:
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService
-keepclasseswithmembernames class * {
native <methods>;
}
-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
The thing is that doesn't happened last week.. (I was using proguard too). Any ideas?
EDIT
I found another solution to this problem:
The project with problems was created with an old version of the ADT plugin (Eclipse). I created a new project with the same parameters and copied the src/, res/ and Manifest, and problem solved!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在android框架工具的示例文件(YOUR_ANDROID_DIR/tools/proguard/proguard-android.txt)中,您可以找到以下规则:
通过注释,它非常明确。
in the example file in the android framework tools (YOUR_ANDROID_DIR/tools/proguard/proguard-android.txt), you can find the following rule:
With the comment it's quite explicit.
您需要告诉 proguard 不要改变与您的
android:onClick
标记关联的方法。下面是一个示例规则(取自 proguard 网站):
You need to tell proguard not to mutate the method associated with your
android:onClick
tag.Here is an example rule (taken from the proguard website):