android:onClick 不适用于 ProGuard

发布于 2024-12-10 12:30:08 字数 1609 浏览 0 评论 0原文

从今天开始,我的应用程序发生了一些奇怪的事情。每次我单击设置了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

故笙诉离歌 2024-12-17 12:30:08

在android框架工具的示例文件(YOUR_ANDROID_DIR/tools/proguard/proguard-android.txt)中,您可以找到以下规则:

# We want to keep methods in Activity that could be used in the XML attribute onClick
-keepclassmembers class * extends android.app.Activity {
   public void *(android.view.View);
}

通过注释,它非常明确。

in the example file in the android framework tools (YOUR_ANDROID_DIR/tools/proguard/proguard-android.txt), you can find the following rule:

# We want to keep methods in Activity that could be used in the XML attribute onClick
-keepclassmembers class * extends android.app.Activity {
   public void *(android.view.View);
}

With the comment it's quite explicit.

八巷 2024-12-17 12:30:08

您需要告诉 proguard 不要改变与您的 android:onClick 标记关联的方法。

下面是一个示例规则(取自 proguard 网站):

-keep class mypackage.MyCallbackClass {
    void myCallbackMethod(java.lang.String);
}

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):

-keep class mypackage.MyCallbackClass {
    void myCallbackMethod(java.lang.String);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文