问题描述
我的应用程序崩溃的ProGuard后,我试图找到答案,但我没有发现任何东西。
logcat的堆栈跟踪
W / SupportMenuInflater(13657):无法实例化类:android.support.v7.widget.ShareActionProvider
W / SupportMenuInflater(13657):抛出java.lang.ClassNotFoundException:android.support.v7.widget.ShareActionProvider
W / SupportMenuInflater(13657):在dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
E / AndroidRuntime(13657):致命异常:主要
E / AndroidRuntime(13657):显示java.lang.NullPointerException
E / AndroidRuntime(13657):在com.mypack.app.MainActivity.onCreateOptionsMenu(来源不明)
E / AndroidRuntime(13657):在android.app.Activity.onCreatePanelMenu(Activity.java:2571)`
这是我的proguard.cfg文件,这是默认的版本,我并没有改变它
#这是ProGuard的配置文件。
#http://proguard.sourceforge.net/index.html#manual/usage.html
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose
#优化是默认关闭的。地塞米松不喜欢code运行
#通过ProGuard的优化和preverify步骤(并执行一些
#这些优化自身)的。
-dontoptimize
-dont preverify
#请注意,如果要启用优化,你不能只是
#在你自己的项目配置文件的优化参数;
#相反,你需要将指向
#ProGuard的,Android的optimize.txt的文件,而不是这一个从
#project.properties文件。
-keepattributes *注释*
-keep公共类com.google.vending.licensing.ILicensingService
-keep公共类com.android.vending.licensing.ILicensingService
#-keep公共类android.support.v7.widget.ShareActionProvider
#对于本地方法,请参阅http://proguard.sourceforge.net/manual/examples.html#native
-keepclasseswithmembernames类* {
天然的LT;方法&gt ;;
}
#守制定者的意见,使动画仍然可以正常工作。
#看到http://proguard.sourceforge.net/manual/examples.html#beans
-keepclassmembers公共类*扩展android.view.View {
无效套*(***);
*** 得到*();
}
#我们要保持活性的方法,可以在XML中使用属性的onClick
-keepclassmembers类*扩展android.app.Activity {
公共无效*(android.view.View);
}
#对于枚举类,请参见http://proguard.sourceforge.net/manual/examples.html#enumerations
-keepclassmembers枚举* {
公共静态** []值();
公共静态**的valueOf(java.lang.String中);
}
-keep类*实现android.os.Parcelable {
公共静态最终android.os.Parcelable $造物主*;
}
-keepclassmembers类** R $ * {
公共静态<领域取代;
}
#支持库包含对新版本的平台。
#不发出警告的情况下这个程序是针对连接的旧
#平台版本。我们了解他们,他们是安全的。
-dontwarn android.support。**
`
修改:问题是解决,我说这行proguard.cfg并没有错误。随着新生产线忽略来自ProGuard的支持库
-dontwarn android.support.v4。**
-keep类android.support.v4 ** {*。 }
-dontwarn android.support.v7。**
-keep类android.support.v7 ** {*。 }
在你的ProGuard的配置,你已经注释掉类,它无法找到的保持:
# - 保持公共类android.support.v7.widget.ShareActionProvider
你尝试再次取消注释和建筑?
编辑:由于没有解决不了你的问题,也许尝试这里描述的所有陷阱:
Android为V7支持库动作条 Proguard的配置。
具体,试着加入:
-keep类android.support.v7.internal ** {*。 }
-keep接口android.support.v7.internal ** {*。 }
-keep类android.support.v7 ** {*。 }
-keep接口android.support.v7 ** {*。 }
您就可以使之更具体是否可行,因为这显然只是让所有的支持库类,甚至你不要使用。
My application crashes after proguard, I tried to find answer for this but I did not find anything.
logcat stacktrace
W/SupportMenuInflater(13657): Cannot instantiate class: android.support.v7.widget.ShareActionProvider
W/SupportMenuInflater(13657): java.lang.ClassNotFoundException: android.support.v7.widget.ShareActionProvider
W/SupportMenuInflater(13657): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
E/AndroidRuntime(13657): FATAL EXCEPTION: main
E/AndroidRuntime(13657): java.lang.NullPointerException
E/AndroidRuntime(13657): at com.mypack.app.MainActivity.onCreateOptionsMenu(Unknown Source)
E/AndroidRuntime(13657): at android.app.Activity.onCreatePanelMenu(Activity.java:2571)`
This is my proguard.cfg file, this is default version, I have not changed it
# 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 android.support.v7.widget.ShareActionProvider
# 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.**
`
EDIT: the problem was solved, I added this lines to proguard.cfg and have no errors. With new lines ignored support libraries from proguard
-dontwarn android.support.v4.**
-keep class android.support.v4.** { *; }
-dontwarn android.support.v7.**
-keep class android.support.v7.** { *; }
In your proguard config, you have commented out the keep of the class that it can't find:
#-keep public class android.support.v7.widget.ShareActionProvider
Did you try uncommenting that and building again?
EDIT: since that didn't solve your problem, maybe try the catch all described here:
Android Proguard configuration for the v7 Support Library ActionBar
specifically, try adding:
-keep class android.support.v7.internal.** { *; }
-keep interface android.support.v7.internal.** { *; }
-keep class android.support.v7.** { *; }
-keep interface android.support.v7.** { *; }
You can then make it more specific if that works, because this obviously just keeps all the support library classes, even ones you don't use.
这篇关于ProGuard的后坠毁的Android应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!