Obfuscated build gives NoSuchMethodException: <init> [class android.app.Activity, int]

3,002 views
Skip to first unread message

Brian C

unread,
Sep 28, 2012, 7:10:50 PM9/28/12
to actionba...@googlegroups.com
I've got the recommended proguard config as shown below.  Anyone else see this error?
I'm using the 4.1.0 release.

-keep class android.support.v4.app.** { *; } 
-keep interface android.support.v4.app.** { *; } 
-keep class com.actionbarsherlock.** { *; } 
-keep interface com.actionbarsherlock.** { *; } 


Here's a snip of the logcat output:

E/AndroidRuntime( 7423): Caused by: java.lang.RuntimeException: java.lang.NoSuchMethodException: <init> [class android.app.Activity, int]
E/AndroidRuntime( 7423): at com.actionbarsherlock.a.a(ActionBarSherlock.java:232)
E/AndroidRuntime( 7423): at com.actionbarsherlock.a.g.f(SherlockFragmentActivity.java:32)
E/AndroidRuntime( 7423): at com.actionbarsherlock.a.g.g(SherlockFragmentActivity.java:43)


From ActionBarSherlock.java:

private static final Class<?>[] CONSTRUCTOR_ARGS = new Class[] { Activity.class, int.class };

...

try {
     Constructor<? extends ActionBarSherlock> ctor = impl.getConstructor(CONSTRUCTOR_ARGS);
     return ctor.newInstance(activity, flags);
 } catch (NoSuchMethodException e) {
      throw new RuntimeException(e);
}


Based on what getConstructor does I'd expect I need to inform proguard to not obfuscate an class ctor that takes Activity.class and int.class as parameters.

Jake Wharton

unread,
Sep 29, 2012, 1:16:56 PM9/29/12
to actionba...@googlegroups.com

That is correct. There is a single constructor on the two implementations of the ActionBarSherlock.java interface which are required.

Brian C

unread,
Oct 1, 2012, 1:29:14 PM10/1/12
to actionba...@googlegroups.com
What would be the appropriate proguard config?  I'm using the things suggested on the website but I still get this error.

Brian C

unread,
Oct 4, 2012, 1:22:15 PM10/4/12
to actionba...@googlegroups.com
Any update on this?  I still haven't found a proguard config that works with ABS.

Jake Wharton

unread,
Oct 4, 2012, 1:26:25 PM10/4/12
to actionba...@googlegroups.com
I don't use proguard. Maybe someone else can help. Why not just keep everything in com.actionbarsherlock and be done with it?

---
Jake Wharton
http://about.me/jakewharton

Brian C

unread,
Oct 4, 2012, 2:14:40 PM10/4/12
to actionba...@googlegroups.com
I'm already keeping everything (classes and interfaces) from com.actionbarsherlock based on the recommended settings on the website, but it still throws the NoSuchMethodException runtime error:


-keep class android.support.v4.app.** { *; } 
-keep interface android.support.v4.app.** { *; } 
-keep class com.actionbarsherlock.** { *; } 
-keep interface com.actionbarsherlock.** { *; }

Aru Sahni

unread,
Oct 5, 2012, 6:50:33 AM10/5/12
to actionba...@googlegroups.com
I had issues with ADT 20's default proguard configuration. I ended up copy-pasting ADTv19's configuration into my proguard-project.txt

~A

Luca Santarelli

unread,
Oct 5, 2012, 12:05:01 PM10/5/12
to actionba...@googlegroups.com
This is my proguard-project.txt file, all my projects get obfuscated without errors. Notice the "android.suppor.**" in place of "android.support.v4.**".

# ActionBarSherlock

-keep class android.support.** { *; }

-keep interface android.support.** { *; }

-keep class com.actionbarsherlock.** { *; }

-keep interface com.actionbarsherlock.** { *; }




# Keep line numbers to alleviate debugging stack traces

-renamesourcefileattribute SourceFile

-keepattributes SourceFile,LineNumberTable

Brian C

unread,
Oct 5, 2012, 6:17:23 PM10/5/12
to actionba...@googlegroups.com
Sorry, user error... my build was using a different config file.  The recommended values on the website work fine.

tanwe...@gmail.com

unread,
Jan 7, 2013, 7:36:14 PM1/7/13
to actionba...@googlegroups.com
Hi Brian,

Can you paste these values which you are using ?
Thanks

John H

unread,
Nov 13, 2015, 1:35:33 PM11/13/15
to ActionBarSherlock
Luca,

This worked perfectly for me.  Thanks!!!!
Reply all
Reply to author
Forward
0 new messages