在实际设备安装中导出APK与Proguard失败

时间:2014-10-17 17:15:18

标签: java android proguard

如果我在android studio中导出我的应用程序而runProguard = true并将APK安装到真实设备我的应用程序停止并说:不幸的是[yourapp]已停止。

问题是什么? 我将proguard-rules.txt文件保留为默认状态:

# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Applications/Android Studio.app/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
#   http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;
#}

如果没有Proguard,我的应用会安装并完美运行。

1 个答案:

答案 0 :(得分:0)

你可以这样做

-keep public class * extends android.view.View {
   public <init>(android.content.Context);
   public <init>(android.content.Context, android.util.AttributeSet);
   public <init>(android.content.Context, android.util.AttributeSet, int);
   public void set*(...);
}

-keepclasseswithmembers class * {
   public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembers class * {
   public <init>(android.content.Context, android.util.AttributeSet, int);
}

-keepclassmembers class * implements android.os.Parcelable {
   static android.os.Parcelable$Creator CREATOR;
}

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