【问题标题】:exporting APK with Proguard fails in real device install在真机安装中使用 Proguard 导出 APK 失败
【发布时间】:2014-12-13 08:08:06
【问题描述】:

如果我在 runProguard=true 时在 android studio 中导出我的应用并将 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,我的应用可以完美安装和运行。

【问题讨论】:

  • 好吧,也许您正在使用库或 java 反射代码,proguard 有时会从您的代码中缩小.. 检查 proguard 站点以获取 android 的推荐设置.. 使用 -KeepClassmembers

标签: java android proguard


【解决方案1】:

你可以这样做

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-08
    • 2018-01-29
    相关资源
    最近更新 更多