android – 使用ProGuard进行模糊处理后,应用程序崩溃了

android – 使用ProGuard进行模糊处理后,应用程序崩溃了,第1张

概述过去3天我一直在解决这个问题. 我的应用程序已经完成,在一些设备和模拟器上进行了测试,并准备发布…或者我认为.在导出和签名之后(顺便说一句,我使用带ADT的Eclipse),它会在任何设备或模拟器中停止工作.我认为问题在于我的ProGuard配置,因为如果我在project.properties中禁用ProGuard,它在导出后会完美运行. 这是我的project.properties: # Pr 过去3天我一直在解决这个问题.

我的应用程序已经完成,在一些设备和模拟器上进行了测试,并准备发布…或者我认为.在导出和签名之后(顺便说一句,我使用带ADT的Eclipse),它会在任何设备或模拟器中停止工作.我认为问题在于我的ProGuard配置,因为如果我在project.propertIEs中禁用ProGuard,它在导出后会完美运行.

这是我的project.propertIEs:

# Project target.target=androID-23androID.library.reference.1=..\Google-play-services_libandroID.library.reference.2=..\androID-support-designproguard.config=proguard.cfg

(如果我jusst评论上面的proguard.config =行,那么导出后一切正常)

proguard.cfg:

-optimizationpasses 5-dontusemixedcaseclassnames-dontskipnonpubliclibraryclasses-dontskipnonpubliclibraryclassmembers-dontpreverify-verbose-dontwarn com.Google.androID.gms.**-dontwarn androID.support.v4.app.**-dontwarn androID.support.design.internal.**-allowaccessmodification-mergeinterfacesaggressively-overloadaggressively-optimizations !code/simplification/arithmetic-keepattributes *Annotation*-keep public class * extends androID.app.Fragment-keep public class * extends androID.support.v4.app.Fragment-keep public class * extends androID.support.v4.app.FragmentPagerAdapter-keep public class * extends androID.app.Fragment-keep public class * extends androID.Widget.**-keep public class * extends androID.vIEw.VIEw-keep class * extends androID.support.v7.**-dontwarn androID.support.v4.**-keep class androID.support.v4.** { *; }-dontwarn androID.support.v7.**-keep class androID.support.v7.internal.** { *; }-keep interface androID.support.internal.v7.** { *; }-keep class com.Google.androID.gms.**# For Google Play Services-keep public class com.Google.androID.gms.ads.**{   public *;}-keep public class com.Google.androID.gms.common.internal.safeparcel.SafeParcelable {    public static final *** NulL;}-keep class androID.support.**-keepnames class * implements androID.os.Parcelable-keepclassmembers class * implements androID.os.Parcelable {  public static final *** CREATOR;}-keep @interface androID.support.annotation.Keep-keep @androID.support.annotation.Keep class *-keepclasseswithmembers class * {  @androID.support.annotation.Keep <fIElds>;}-keepclasseswithmembers class * {  @androID.support.annotation.Keep <methods>;}-keep @interface com.Google.androID.gms.common.annotation.Keepname-keepnames @com.Google.androID.gms.common.annotation.Keepname class *-keepclassmembernames class * {  @com.Google.androID.gms.common.annotation.Keepname *;}-keep @interface com.Google.androID.gms.common.util.DynamiteAPI-keep public @com.Google.androID.gms.common.util.DynamiteAPI class * {  public <fIElds>;  public <methods>;}# Other required classes for Google Play Services# Read more at http://developer.androID.com/Google/play-services/setup.HTML-keep class * extends java.util.ListResourceBundle {   protected Object[][] getContents();}# Needed when building against pre-Marshmallow SDK.-dontwarn androID.security.NetworkSecurityPolicy# Keep Metadata about included modules.-keep public class com.Google.androID.gms.dynamite.descriptors.** {  public <fIElds>;}# Keep the implementation of the flags API for Google-play-services-flags-keep public class com.Google.androID.gms.flags.impl.FlagProvIDerImpl {  public <fIElds>; public <methods>;}-keep class org.apache.http.**-keep interface org.apache.http.**-dontwarn org.apache.**-keep public class androID.net.http.SslError-keep public class androID.webkit.WebVIEwClIEnt-dontwarn androID.webkit.WebVIEw-dontwarn androID.net.http.SslError-dontwarn androID.webkit.WebVIEwClIEnt-assumenosIDeeffects class androID.util.Log {    public static *** e(...);    public static *** w(...);    public static *** wtf(...);    public static *** d(...);    public static *** v(...);    public static *** i(...);}

最后,当我在真实设备上运行我的应用程序时,我得到的错误日志:

06-08 21:19:23.448: E/AndroIDRuntime(12411): FATAL EXCEPTION: main06-08 21:19:23.448: E/AndroIDRuntime(12411): Process: com.alxdroIDdev.cchecker,PID: 1241106-08 21:19:23.448: E/AndroIDRuntime(12411): androID.vIEw.InflateException: Binary XML file line #12: Error inflating class button06-08 21:19:23.448: E/AndroIDRuntime(12411):    at androID.vIEw.LayoutInflater.createVIEwFromTag(LayoutInflater.java:770)06-08 21:19:23.448: E/AndroIDRuntime(12411):    at androID.vIEw.LayoutInflater.rInflate(LayoutInflater.java:813)06-08 21:19:23.448: E/AndroIDRuntime(12411):    at androID.vIEw.LayoutInflater.inflate(LayoutInflater.java:511)06-08 21:19:23.448: E/AndroIDRuntime(12411):    at androID.vIEw.LayoutInflater.inflate(LayoutInflater.java:415)06-08 21:19:23.448: E/AndroIDRuntime(12411):    at com.alxdroIDdev.cchecker.linksFragment.onCreateVIEw(UnkNown Source)06-08 21:19:23.448: E/AndroIDRuntime(12411):    at androID.support.v4.app.Fragment.performCreateVIEw(UnkNown Source)06-08 21:19:23.448: E/AndroIDRuntime(12411):    at androID.support.v4.app.FragmentManagerImpl.movetoState(UnkNown Source)06-08 21:19:23.448: E/AndroIDRuntime(12411):    at androID.support.v4.app.FragmentManagerImpl.movetoState(UnkNown Source)06-08 21:19:23.448: E/AndroIDRuntime(12411):    at androID.support.v4.app.BackStackRecord.run(UnkNown Source)06-08 21:19:23.448: E/AndroIDRuntime(12411):    at androID.support.v4.app.FragmentManagerImpl.execPendingActions(UnkNown Source)06-08 21:19:23.448: E/AndroIDRuntime(12411):    at androID.support.v4.app.FragmentManagerImpl.executePendingTransactions(UnkNown Source)06-08 21:19:23.448: E/AndroIDRuntime(12411):    at androID.support.v4.app.FragmentPagerAdapter.finishUpdate(UnkNown Source)06-08 21:19:23.448: E/AndroIDRuntime(12411):    at androID.support.v4.vIEw.VIEwPager.populate(UnkNown Source)06-08 21:19:23.448: E/AndroIDRuntime(12411):    at androID.support.v4.vIEw.VIEwPager.setCurrentItemInternal(UnkNown Source)06-08 21:19:23.448: E/AndroIDRuntime(12411):    at androID.support.v4.vIEw.VIEwPager.setCurrentItemInternal(UnkNown Source)06-08 21:19:23.448: E/AndroIDRuntime(12411):    at androID.support.v4.vIEw.VIEwPager.setCurrentItem(UnkNown Source)06-08 21:19:23.448: E/AndroIDRuntime(12411):    at androID.support.design.Widget.TabLayout$VIEwPagerOnTabSelectedListener.a(UnkNown Source)06-08 21:19:23.448: E/AndroIDRuntime(12411):    at androID.support.design.Widget.TabLayout.a(UnkNown Source)06-08 21:19:23.448: E/AndroIDRuntime(12411):    at androID.support.design.Widget.TabLayout$Tab.a(UnkNown Source)06-08 21:19:23.448: E/AndroIDRuntime(12411):    at androID.support.design.Widget.TabLayout$TabVIEw.performClick(UnkNown Source)06-08 21:19:23.448: E/AndroIDRuntime(12411):    at androID.vIEw.VIEw$PerformClick.run(VIEw.java:20916)06-08 21:19:23.448: E/AndroIDRuntime(12411):    at androID.os.Handler.handleCallback(Handler.java:739)06-08 21:19:23.448: E/AndroIDRuntime(12411):    at androID.os.Handler.dispatchMessage(Handler.java:95)06-08 21:19:23.448: E/AndroIDRuntime(12411):    at androID.os.Looper.loop(Looper.java:145)06-08 21:19:23.448: E/AndroIDRuntime(12411):    at androID.app.ActivityThread.main(ActivityThread.java:5944)06-08 21:19:23.448: E/AndroIDRuntime(12411):    at java.lang.reflect.Method.invoke(Native Method)06-08 21:19:23.448: E/AndroIDRuntime(12411):    at java.lang.reflect.Method.invoke(Method.java:372)06-08 21:19:23.448: E/AndroIDRuntime(12411):    at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)06-08 21:19:23.448: E/AndroIDRuntime(12411):    at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:1194)06-08 21:19:23.448: E/AndroIDRuntime(12411): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'voID androID.support.v7.Widget.AppCompatBackgroundHelper.b(androID.content.res.colorStateList)' on a null object reference06-08 21:19:23.448: E/AndroIDRuntime(12411):    at androID.support.v7.Widget.AppCompatbutton.setBackgroundDrawable(UnkNown Source)06-08 21:19:23.448: E/AndroIDRuntime(12411):    at androID.vIEw.VIEw.setBackground(VIEw.java:17237)06-08 21:19:23.448: E/AndroIDRuntime(12411):    at androID.vIEw.VIEw.<init>(VIEw.java:4335)06-08 21:19:23.448: E/AndroIDRuntime(12411):    at androID.Widget.TextVIEw.<init>(TextVIEw.java:1002)06-08 21:19:23.448: E/AndroIDRuntime(12411):    at androID.Widget.button.<init>(button.java:115)06-08 21:19:23.448: E/AndroIDRuntime(12411):    at androID.Widget.button.<init>(button.java:108)06-08 21:19:23.448: E/AndroIDRuntime(12411):    at androID.support.v7.Widget.AppCompatbutton.<init>(UnkNown Source)06-08 21:19:23.448: E/AndroIDRuntime(12411):    at androID.support.v7.Widget.AppCompatbutton.<init>(UnkNown Source)06-08 21:19:23.448: E/AndroIDRuntime(12411):    at androID.support.v7.app.AppCompatDelegateImplV7.onCreateVIEw(UnkNown Source)06-08 21:19:23.448: E/AndroIDRuntime(12411):    at androID.support.v4.vIEw.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateVIEw(UnkNown Source)06-08 21:19:23.448: E/AndroIDRuntime(12411):    at androID.vIEw.LayoutInflater$FactoryMerger.onCreateVIEw(LayoutInflater.java:181)06-08 21:19:23.448: E/AndroIDRuntime(12411):    at androID.vIEw.LayoutInflater.createVIEwFromTag(LayoutInflater.java:732)06-08 21:19:23.448: E/AndroIDRuntime(12411):    ... 28 more

我的应用有一个TabLayout和4个标签的活动.第一个选项卡始终成功打开.如果我切换到另一个选项卡(更改片段),我会得到上面的错误.即使切换到的片段中没有button视图,我也会得到相同的错误.

在此先感谢您的帮助.过去3天我一直在努力解决这个问题.

解决方法 我解决了问题.

这是我最终得到的最终proguard.cfg文件,它编译了几个优化并使我的应用程序顺利运行:

-optimizationpasses 5-dontusemixedcaseclassnames-dontskipnonpubliclibraryclasses-dontskipnonpubliclibraryclassmembers-verbose-dontpreverify-allowaccessmodification-mergeinterfacesaggressively-overloadaggressively-keepattributes *Annotation*####################################################################  KEEP ANDROID SUPPORT V7 AND DESIGN-dontwarn androID.support.design.**-keep class androID.support.design.** { *; }-keep interface androID.support.design.** { *; }-keep public class androID.support.design.R$* { *; }-keep public class androID.support.v7.Widget.** { *; }-keep public class androID.support.v7.internal.Widget.** { *; }-keep public class androID.support.v7.internal.vIEw.menu.** { *; }-keep public class * extends androID.support.v4.vIEw.ActionProvIDer {    public <init>(androID.content.Context);}-keep interface androID.support.v4.** { *; }-keep interface androID.support.v7.** { *; }-keep class androID.support.** { *; }####################################################################  REMOVE WARNINGS -dontwarn androID.support.design.internal.**-dontwarn com.Google.androID.gms.**-dontwarn androID.support.v4.**####################################################################  REMOVE LOGGING -assumenosIDeeffects class androID.util.Log {    public static *** e(...);    public static *** w(...);    public static *** wtf(...);    public static *** d(...);    public static *** v(...);    public static *** i(...);}####################################################################  ORG.APACHE.http -keep class org.apache.http.**-keep interface org.apache.http.**-dontwarn org.apache.**####################################################################  WEVVIEW -keep public class androID.net.http.SslError-keep public class androID.webkit.WebVIEwClIEnt-dontwarn androID.webkit.WebVIEw-dontwarn androID.net.http.SslError-dontwarn androID.webkit.WebVIEwClIEnt####################################################################  Google PLAY SERVICES liB - ADS-keep public class com.Google.androID.gms.* { public *; }#-keep class com.Google.androID.gms.**# For Google Play Services-keep public class com.Google.androID.gms.ads.**{   public *;}####################################################################  Google PLAY SERVICES liB-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.-keep @interface com.Google.androID.gms.common.annotation.Keepname-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 pre-Marshmallow SDK.-dontwarn androID.security.NetworkSecurityPolicy# Keep Metadata about included modules.-keep public class com.Google.androID.gms.dynamite.descriptors.** {  public <fIElds>;}# Keep the implementation of the flags API for Google-play-services-flags-keep public class com.Google.androID.gms.flags.impl.FlagProvIDerImpl {  public <fIElds>; public <methods>;}

我将这个放在这里作为我自己问题的答案,因为上面的配置可能会帮助那些也失去时间并且使用ProGuard睡觉的人.

部分优化是从此页面获取的:

https://github.com/krschultz/android-proguard-snippets/tree/master/libraries

上面的页面提供了几个特定于库的ProGuard配置的集合,包括androID.support.v7和androID.support.design.

总结

以上是内存溢出为你收集整理的android – 使用ProGuard进行模糊处理后,应用程序崩溃了全部内容,希望文章能够帮你解决android – 使用ProGuard进行模糊处理后,应用程序崩溃了所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1134895.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存