Wednesday, 15 June 2011

java - ProGuard obfuscation leads to ClassNotFoundException -



java - ProGuard obfuscation leads to ClassNotFoundException -

i seek obfuscate code proguard, when that, not find initial activity defined in androidmanifest anymore (classnotfoundexception).

this how activity looks:

public class loadingactivity extends activity { private static final string tag = loadingactivity.class.getsimplename(); private int effectivewidth; private int effectiveheight; private asynctask<void, void, void> bitmaploadertask; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_loading); setrequestedorientation(activityinfo.screen_orientation_landscape); initspecs(); } @override protected void onpause() { super.onpause(); if (bitmaploadertask != null) { bitmaploadertask.cancel(true); } } @override protected void onstart() { super.onstart(); if (resizedbitmapmapping.isstillholdingallimages()) { logger.log(tag, "resizedbitmapmapping still contains images, skip loading...", logcontroller.isloggingenabled(), log.debug); startmenu(); } else { bitmaploadertask = new bitmaploadertask(getresources(), effectivewidth, effectiveheight, this); bitmaploadertask.execute(); } } @suppresswarnings("deprecation") private void initspecs() { packagenameholder.setpackagename(getpackagename()); windowmanager windowmanager = (windowmanager)this.getsystemservice(context.window_service); point size = new point(); if (build.version.sdk_int >= build.version_codes.honeycomb_mr2) { windowmanager.getdefaultdisplay().getsize(size); effectivewidth = size.x; effectiveheight = size.y; } else { display display = windowmanager.getdefaultdisplay(); effectivewidth = display.getwidth(); effectiveheight = display.getheight(); } } public void startmenu() { final intent gameintent = new intent(this, menuactivity.class); startactivity(gameintent); overridependingtransition(0, 0); } public void cancel() { finish(); } }

my proguard.cfg looks this:

-dontoptimize -dontshrink -verbose -keep class com.chartboost.** { *; } -keep class * extends java.util.listresourcebundle { protected object[][] getcontents(); } -keep public class com.google.android.gms.common.internal.safeparcel.safeparcelable { public static final *** null; } -keepnames @com.google.android.gms.common.annotation.keepname class * -keepclassmembernames class * { @com.google.android.gms.common.annotation.keepname *; } -keepnames class * implements android.os.parcelable { public static final ** creator; }

for testing added

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

then, app works, it's not obfuscated (which clear). ideas how obfuscated properly? proguard has care about, right?

this error message while starting app:

10-25 00:29:04.600: e/androidruntime(3299): java.lang.runtimeexception: unable instantiate activity componentinfo{com.mydomain.myapp/com.mydomain.myapp.loadingactivity}: java.lang.classnotfoundexception: com.mydomain.myapp.loadingactivity in loader dalvik.system.pathclassloader[/data/app/com.mydomain.myapp-2.apk] 10-25 00:29:04.600: e/androidruntime(3299): @ android.app.activitythread.performlaunchactivity(activitythread.java:1680) 10-25 00:29:04.600: e/androidruntime(3299): @ android.app.activitythread.handlelaunchactivity(activitythread.java:1784) 10-25 00:29:04.600: e/androidruntime(3299): @ android.app.activitythread.access$1500(activitythread.java:123) 10-25 00:29:04.600: e/androidruntime(3299): @ android.app.activitythread$h.handlemessage(activitythread.java:939) 10-25 00:29:04.600: e/androidruntime(3299): @ android.os.handler.dispatchmessage(handler.java:99) 10-25 00:29:04.600: e/androidruntime(3299): @ android.os.looper.loop(looper.java:130) 10-25 00:29:04.600: e/androidruntime(3299): @ android.app.activitythread.main(activitythread.java:3835) 10-25 00:29:04.600: e/androidruntime(3299): @ java.lang.reflect.method.invokenative(native method) 10-25 00:29:04.600: e/androidruntime(3299): @ java.lang.reflect.method.invoke(method.java:507) 10-25 00:29:04.600: e/androidruntime(3299): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:864) 10-25 00:29:04.600: e/androidruntime(3299): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:622) 10-25 00:29:04.600: e/androidruntime(3299): @ dalvik.system.nativestart.main(native method) 10-25 00:29:04.600: e/androidruntime(3299): caused by: java.lang.classnotfoundexception: com.mydomain.myapp.loadingactivity in loader dalvik.system.pathclassloader[/data/app/com.mydomain.myapp-2.apk] 10-25 00:29:04.600: e/androidruntime(3299): @ dalvik.system.pathclassloader.findclass(pathclassloader.java:240) 10-25 00:29:04.600: e/androidruntime(3299): @ java.lang.classloader.loadclass(classloader.java:551) 10-25 00:29:04.600: e/androidruntime(3299): @ java.lang.classloader.loadclass(classloader.java:511) 10-25 00:29:04.600: e/androidruntime(3299): @ android.app.instrumentation.newactivity(instrumentation.java:1021) 10-25 00:29:04.600: e/androidruntime(3299): @ android.app.activitythread.performlaunchactivity(activitythread.java:1672) 10-25 00:29:04.600: e/androidruntime(3299): ... 11 more

[update] if add together

-keep public class com.mydomain.myapp.loadingactivity

it starts, doesn't find next activity, because searches in androidmanfest obfuscated activities?

10-25 13:20:16.159: e/androidruntime(3195): android.content.activitynotfoundexception: unable find explicit activity class {com.mydomain.myapp/com.mydomain.myapp.g}; have declared activity in androidmanifest.xml? 10-25 13:20:16.159: e/androidruntime(3195): @ com.mydomain.myapp.loadingactivity.a(unknown source) 10-25 13:20:16.159: e/androidruntime(3195): @ com.mydomain.myapp.e.a.a(unknown source) 10-25 13:20:16.159: e/androidruntime(3195): @ com.mydomain.myapp.e.a.onpostexecute(unknown source)

proguard.config parameter should be

proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

or optimization,

proguard.config=${sdk.dir}/tools/proguard/proguard-android-optimize.txt:proguard-project.txt

this way necessary settings included, such as:

# want maintain methods in activity used in xml attribute onclick -keepclassmembers class * extends android.app.activity { public void *(android.view.view); }

java android proguard obfuscation

No comments:

Post a Comment