安卓的onClick不工作使用ProGuard [英] android:onClick not working with ProGuard

查看:139
本文介绍了安卓的onClick不工作使用ProGuard的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从今天起,奇怪的事情发生了我的申请。我每次点击一个按钮,已设置了android:onclick属性,我得到的 IllegalStateException异常:无法找到一个方法...

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 ...

我注意到,只有发生在我能Proguard的文件中:default.properties

I noticed that only happens when I enable Proguard in the file: default.properties

这是我proguard.cfg:

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 *;
}

的事情是上周没有发生过。(我是用ProGuard的太)。任何想法?

The thing is that doesn't happened last week.. (I was using proguard too). Any ideas?

修改 我发现了另一个解决这个问题: 有问题的项目是用旧版本的ADT插件(Eclipse中)的创建。我创建具有相同参数的新项目,并复制的的src / RES / 清单的,而问题就解决了​​!

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!

推荐答案

您需要告诉ProGuard的不变异与你的机器人相关的方法:的onClick 标记。

You need to tell proguard not to mutate the method associated with your android:onClick tag.

下面是一个例子规则(取自 ProGuard的网站 ):

Here is an example rule (taken from the proguard website):

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

这篇关于安卓的onClick不工作使用ProGuard的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆