使用ProGuard在某些设备上本机崩溃

时间:2015-12-09 13:59:22

标签: android crash android-proguard

编辑:对于可能遇到同样问题的未来开发者,我担心自己无法使用。在应用程序的未来版本中,问题显然已经解决了,但我无法确定原因。

我使用我的朋友作为测试版测试人员,通过Google Play内测测试系统测试了一个应用程序。推送使用ProGuard对.apk进行模糊处理的更新后,两名测试人员开始报告崩溃事件。崩溃是不可预测和零星的,他们无法确定任何原因或模式。更糟糕的是,我在开发者控制台中获得的崩溃报告根本不包含任何信息,只是声明"本机崩溃(无可用位置)",没有堆栈跟踪,甚至没有设备信息。

我通过询问有问题的测试人员来了解设备信息,这两款设备都是索尼手机,Xperia Z3和Xperia Z3 Compact。但是,我还有一个可用于测试的Z3 Compact,并且在运行相同的混淆apk时无法重现崩溃。我们也运行相同的操作系统版本。

我已经发送了一个测试人员和未经模糊处理的apk,他无法重现运行该版本的崩溃。事实上,崩溃首先发生在引入ProGuard混淆的补丁之后,这让我相信这是原因。

首先,我只使用SDK中的默认配置文件运行ProGuard:

# This is a configuration file for ProGuard.
# LINK REMOVED

-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

# For native methods, see LINK REMOVED
-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);
}

-keepclassmembers class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator 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.**

我已经将以下行添加到proguard-project.txt中,该行也包含在项目的proguard配置变量中:

-keep class * extends java.util.ListResourceBundle {
    protected java.lang.Object[][] getContents();
}

# Keep SafeParcelable value, needed for reflection. This is required to support backwards
# compatibility of some classes.
-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
    public static final *** NULL;
}

# Keep the names of classes/members we need for client functionality.
-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
    @com.google.android.gms.common.annotation.KeepName *;
}

# Needed for Parcelable/SafeParcelable Creators to not get stripped
-keepnames class * implements android.os.Parcelable {
    public static final ** CREATOR;
}

# Needed when building against the Marshmallow SDK
-dontwarn org.apache.http.**

# Needed when building against pre-Marshmallow SDK.
-dontwarn android.security.NetworkSecurityPolicy

-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-libraryjars D:/Docs/Android/spaceprog/spaceprogr/libs/android-support-v4.jar
-keep class com.viewpagerindicator.** { *; }
-keep class com.google.android.gms.** { *; }
-keep class com.google.example.games.basegameutils.** { *; }
-printmapping out.map
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable

这些新增内容的上半部分(带注释)直接来自Google Play服务的自述文件,建议在使用该库时添加。其余的我在尝试研究和调试问题时加入了自己。

如果有人在我的ProGuard配置中发现任何遗漏或其他麻烦迹象,我很高兴知道。我也很高兴有关如何进一步调试问题的任何建议。请记住,在这种情况下,完全模块测试一次只能模拟一个模块是不可能的,因为我没有可以重现问题的设备,我也不能让志愿者测试人员安装30多个不同版本的.apk然后玩,直到它崩溃或直到它们确信它不会。

0 个答案:

没有答案