android - "Application stopped working"启用 Proguard 后

标签 android proguard

无论是在模拟器上还是在我正在测试的设备上,它都是一个有效的应用程序。

但现在,我启用了 Proguard 并使用 Android-Tools > Export signed application 导出了签名的应用程序

然后我将这个 .apk 复制到 SD 卡上并尝试在设备上安装。但是应用程序停止工作,如果我尝试打开它,会要求强制关闭。

如果我从 Eclipse 运行,它可以在设备上运行。

因为它说:

Proguard 仅在您导出发布 .apk 文件时有效。我检查了一下,bin 文件夹中的 apk 文件大小是 1.8mb,而我导出后得到的 1 是 1.4mb。似乎 Proguard 已经完成了它的工作。但是应用程序不工作。可悲的是我看不到任何日志等..,

编辑:

如果我禁用 Proguard 然后导出,发布的 apk 文件现在可以正常工作。那么,Proguard 有什么问题吗?

我的文件夹结构

enter image description here

proguard-project.txt

# This is a configuration file for ProGuard.
# http://proguard.sourceforge.net/index.html#manual/usage.html

-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose

# Optimization is turned off by default. Dex does not like code run
# through the ProGuard optimize and preverify steps (and performs some
# of these optimizations on its own).
-dontoptimize
-dontpreverify
# Note that if you want to enable optimization, you cannot just
# include optimization flags in your own project configuration file;
# instead you will need to point to the
# "proguard-android-optimize.txt" file instead of this one from your
# project.properties file.

-keepattributes *Annotation*
-keep public class com.google.vending.licensing.ILicensingService
-keep public class com.android.vending.licensing.ILicensingService
-keep public class * extends android.app.Application
-keep public class * extends android.app.Activity
-keep public class * extends android.app.PreferenceActivity
-keep public class * extends android.view.View
-keep public class * extends android.widget.BaseAdapter
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * implements android.view.View.OnTouchListener
-keep public class * implements android.view.View.OnClickListener
-keep public class * extends com.actionbarsherlock.app.SherlockActivity
-keep public class * extends com.actionbarsherlock.app.SherlockFragmentActivity
-keep public class * extends com.actionbarsherlock.app.SherlockMapActivity
-keep public class * extends com.readystatesoftware.mapviewballoons.BalloonItemizedOverlay<OverlayItem>
-keep public class * extends com.actionbarsherlock.app.SherlockFragment


-libraryjars libs/android-support-v4.jar
-libraryjars libs/apache-mime4j-0.6.jar
-libraryjars libs/httpmime-4.0.1.jar
-libraryjars libs/libGoogleAnalyticsV2.jar  



-assumenosideeffects class android.util.Log {
    public static *** v(...);
    public static *** i(...);
    public static *** d(...);
    public static *** w(...);
    public static *** e(...);
}

# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native
-keepclasseswithmembernames class * {
    native <methods>;
}

# keep setters in Views so that animations can still work.
# see http://proguard.sourceforge.net/manual/examples.html#beans
-keepclassmembers public class * extends android.view.View {
   void set*(***);
   *** get*();
}

# 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);
}

# For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations
-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}

-keepclassmembers class **.R$* {
    public static <fields>;
}

# The support library contains references to newer platform versions.
# Don't warn about those in case this app is linking against an older
# platform version.  We know about them, and they are safe.
-dontwarn android.support.**
-dontwarn org.apache.**

我今天才开始使用它,我不确定我是否以正确的方式使用它。所以,如果我有任何错误,请纠正我。

这是 LogCat 错误:

01-02 13:18:54.711: E/AndroidRuntime(585): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xApp.app/com.xApp.app.LandingActivity}: java.lang.RuntimeException: java.lang.NoSuchMethodException: a(Activity,int)
01-02 13:18:54.711: E/AndroidRuntime(585):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
01-02 13:18:54.711: E/AndroidRuntime(585):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
01-02 13:18:54.711: E/AndroidRuntime(585):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
01-02 13:18:54.711: E/AndroidRuntime(585):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
01-02 13:18:54.711: E/AndroidRuntime(585):  at android.os.Handler.dispatchMessage(Handler.java:99)
01-02 13:18:54.711: E/AndroidRuntime(585):  at android.os.Looper.loop(Looper.java:130)
01-02 13:18:54.711: E/AndroidRuntime(585):  at android.app.ActivityThread.main(ActivityThread.java:3683)
01-02 13:18:54.711: E/AndroidRuntime(585):  at java.lang.reflect.Method.invokeNative(Native Method)
01-02 13:18:54.711: E/AndroidRuntime(585):  at java.lang.reflect.Method.invoke(Method.java:507)
01-02 13:18:54.711: E/AndroidRuntime(585):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-02 13:18:54.711: E/AndroidRuntime(585):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-02 13:18:54.711: E/AndroidRuntime(585):  at dalvik.system.NativeStart.main(Native Method)
01-02 13:18:54.711: E/AndroidRuntime(585): Caused by: java.lang.RuntimeException: java.lang.NoSuchMethodException: a(Activity,int)
01-02 13:18:54.711: E/AndroidRuntime(585):  at com.actionbarsherlock.a.a(Unknown Source)
01-02 13:18:54.711: E/AndroidRuntime(585):  at com.actionbarsherlock.app.SherlockActivity.a(Unknown Source)
01-02 13:18:54.711: E/AndroidRuntime(585):  at com.actionbarsherlock.app.SherlockActivity.setContentView(Unknown Source)
01-02 13:18:54.711: E/AndroidRuntime(585):  at com.xApp.app.LandingActivity.onCreate(Unknown Source)
01-02 13:18:54.711: E/AndroidRuntime(585):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-02 13:18:54.711: E/AndroidRuntime(585):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
01-02 13:18:54.711: E/AndroidRuntime(585):  ... 11 more
01-02 13:18:54.711: E/AndroidRuntime(585): Caused by: java.lang.NoSuchMethodException: a(Activity,int)
01-02 13:18:54.711: E/AndroidRuntime(585):  at java.lang.Class.getMatchingConstructor(Class.java:643)
01-02 13:18:54.711: E/AndroidRuntime(585):  at java.lang.Class.getConstructor(Class.java:472)
01-02 13:18:54.711: E/AndroidRuntime(585):  ... 17 more

谢谢

最佳答案

堆栈跟踪显示 ActionBarSherlock 无法使用反射找到构造函数“a(Activity,int)”。它的文档确实指定了 ActionBarSherlock 的每个扩展都应该有这样一个构造函数。 ProGuard 不知道(不能)知道这一点并删除了构造函数,因为它在代码中似乎未被使用。因此,您必须明确告诉 ProGuard 保留它:

-keepclassmembers class * extends com.actionbarsherlock.ActionBarSherlock {
    <init>(android.app.Activity, int);
}

一般情况下,如果您在代码或其库中获得此​​类与反射相关的堆栈跟踪,则需要添加相应的配置。

关于android - "Application stopped working"启用 Proguard 后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14111150/

相关文章:

android - 使用 maxLines 选取框

Android SDKTools r21 库错误

java - 尝试更新 cocos OpenSSL 时出错

android - 使用 EnumTypeAdapter 时,将 proguard 与 GSON 和 RoboGuice 结合使用会失败

java - 错误 :Execution. .. ':app:packageRelease' 。> 无法计算 ..\app\build\intermediates\classes-proguard\..\release\classes.jar 的哈希值

java - 启用 Proguard 后应用程序崩溃

Android MapView 试图添加 View ,但已经有父 View

android - 插入具有复合主键的android sqlite3表的问题

android - Proguard 混淆枚举问题

java - LibGDX 混淆器