Monday, June 13, 2011

Button onclick & proguard

I have a simple program that has a single Button on an Android layout file, and this Button has an onClick attribute that is designing which method it should be triggered when clicked. This worked great while on development, but once I exported and installed a signed package I got a problem: NoSuchMethodException being thrown after a click.

After looking through the source code with no clue on where the problem would be, I remembered I had Proguard enabled. Proguard modifies method names to short names like: a, b, c, d and so on. So it is obvious that when clicking on a button all you will get is a NoSuchMethodException because the method itself has been renamed to something else.

To avoid this problem, I've added this to my proguard.cfg:

-keepclassmembers class {
  public void handleXxxYyyButton(android.view.View);

This problem is tricky because on development mode it works perfectly as Proguard is no involved. It will only throw an exception when you actually deploy your exported application. That said, I recommend everyone to test applications with the exported signed package before releasing them to the market.


Mohan said...

Thank you. We are also into similar problem and seems to be no issue with the code. We will try this.

joão said...

Great to hear that!! =) I hope it helps you in solving the problem.


Thanks for sharing the post.. parents are worlds best person in each lives of individual..they need or must succeed to sustain needs of the family. vShare iOS 11

2009 DREAM said...

I recently found many useful information in your website especially this blog page. Among the lots of comments on your articles. Thanks for sharing. Jailbreak iOS 11.3

Sample Data said...

SBGame Hacke randroid

Anonymous said...

As you accept odds at the time of inserting your wager, Sports Proto calculates your payout and displays how much you would win. However, payouts are decrease than international betting websites and you can only wager on baseball and basketball. The organized group had offices around the South Chungcheong Province from which they managed 4 completely different gambling web sites. The unlawful web pages operated by the gang required particular entry and weren't broadly available in this means preserving the unlawful gambling underneath the South Korean authorities’ radar. The police reported that the organized group has been utilizing 26 completely different gambling 1xbet accounts just over the past six months. The South Korean police busted an intricate scheme of unlawful on-line gambling web sites that have been operating for years catering to the gambling cravings of foreigners in a rustic the place on-line gambling is banned.