我有一个Android应用程序,在调试模式下可以正常工作,但是在发布模式下开始出现问题。将项目绑定到recyclerview时崩溃。
最初,我认为这将是一个proguard问题,但是在为调试模式启用proguard之后,很明显只有发行版才存在此问题。只是尝试一下,我将发布版本设置为debuggable true
,问题就消失了。
有没有人知道只有当apk无法调试时才可能导致崩溃的原因?或以任何方式调试它并查看到底出了什么问题?
这些是我的构建类型:
buildTypes {
debug {
multiDexEnabled true
shrinkResources true
minifyEnabled true
useProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
multiDexEnabled true
shrinkResources true
minifyEnabled true
useProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
因此,如果我将debuggable true
添加到release
,则发行版本有效。如果我将debuggable false
添加到debug
,调试版本将停止工作...
Logcat:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: __, PID: _
a.a
at ___.overview.dashboard.m.a(Unknown Source)
at ___.overview.dashboard.c.a(Unknown Source)
at android.support.v7.widget.RecyclerView$a.a(Unknown Source)
at android.support.v7.widget.RecyclerView$a.b(Unknown Source)
at android.support.v7.widget.RecyclerView$p.a(Unknown Source)
at android.support.v7.widget.RecyclerView$p.a(Unknown Source)
at android.support.v7.widget.RecyclerView$p.a(Unknown Source)
at android.support.v7.widget.RecyclerView$p.c(Unknown Source)
at android.support.v7.widget.LinearLayoutManager$c.a(Unknown Source)
at android.support.v7.widget.LinearLayoutManager.a(Unknown Source)
at android.support.v7.widget.LinearLayoutManager.a(Unknown Source)
at android.support.v7.widget.LinearLayoutManager.c(Unknown Source)
at android.support.v7.widget.RecyclerView.N(Unknown Source)
at android.support.v7.widget.RecyclerView.q(Unknown Source)
at android.support.v7.widget.RecyclerView.onLayout(Unknown Source)
at android.view.View.layout(View.java:18798)
at android.view.ViewGroup.layout(ViewGroup.java:5951)
at android.support.constraint.ConstraintLayout.onLayout(Unknown Source)
at android.view.View.layout(View.java:18798)
at android.view.ViewGroup.layout(ViewGroup.java:5951)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:18798)
at android.view.ViewGroup.layout(ViewGroup.java:5951)
at android.support.constraint.ConstraintLayout.onLayout(Unknown Source)
at android.view.View.layout(View.java:18798)
at android.view.ViewGroup.layout(ViewGroup.java:5951)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:18798)
at android.view.ViewGroup.layout(ViewGroup.java:5951)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1741)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1585)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1494)
at android.view.View.layout(View.java:18798)
at android.view.ViewGroup.layout(ViewGroup.java:5951)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:18798)
at android.view.ViewGroup.layout(ViewGroup.java:5951)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1741)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1585)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1494)
at android.view.View.layout(View.java:18798)
at android.view.ViewGroup.layout(ViewGroup.java:5951)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at com.android.internal.policy.DecorView.onLayout(DecorView.java:887)
at android.view.View.layout(View.java:18798)
at android.view.ViewGroup.layout(ViewGroup.java:5951)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2648)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2364)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1515)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7091)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:927)
at android.view.Choreographer.doCallbacks(Choreographer.java:702)
at android.view.Choreographer.doFrame(Choreographer.java:638)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:913)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
答案 0 :(得分:1)
对我来说,问题在于我正在测试发行版,并禁用了Crashlytics,以使其无法跟踪我的活动。 将“ debuggable”设置为true可以正常工作,但是一旦将其设置为false,我就会在应用启动时立即崩溃。 所以基本上我忘了打开Crashlytics,并从中收到一些内部错误。
答案 1 :(得分:0)
如@laalto所说,有一个堆栈跟踪可能会有所帮助
将其放入我的proguard文件中:
-keepattributes SourceFile,LineNumberTable
帮助我找到错误所在。这将显示堆栈跟踪中的原始类名和行号。我仍然不确定为什么调试模式下不会发生错误,但是至少我能够解决它。再次感谢!