When you run the application in debug mode the app can't crash. But when generates the .apk file release the app crash. This error does not happen on all phones, in just a few that have the android 6.
The logcat shows that the problem is a NullPointerException in the class (android.support.v4.widget.drawerlayout). How can a NullPointerException launches only on release apk?
We already disable proguard, minify and shrinkResources. Didn't resolve this bug.
Here some logs:
Attempt to invoke virtual method 'int android.view.WindowInsets.getSystemWindowInsetLeft()' on a null object reference
at android.support.v4.widget.i.a(Unknown Source)
at android.support.v4.widget.DrawerLayout$d.a(Unknown Source)
at android.support.v4.widget.DrawerLayout.onMeasure(Unknown Source)
at android.view.View.measure(View.java:18799)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.support.v7.widget.ContentFrameLayout.onMeasure(Unknown Source)
at android.view.View.measure(View.java:18799)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
Apps on Android can crash because of low storage space, too many apps running simultaneously, a weak internet connection, or not having the proper app updates installed.
This can be caused by many factors, but most app issues can be fixed by updating the software or clearing the app data. App updates usually contain patches to fix problems identified with the app. Some app updates are delivered through Google Play Store , while others are in device software updates.
In debug mode the code in the if is not executed but in release mode p contains an undefined value, which is unlikely to be 0, so the code is executed often causing a crash. I would check your code for uninitialized variables. This can also apply to the contents of arrays.
Linking - is your release build pulling in the correct libraries. Minidump - really easy to use (just look it up in msdn) will give you a full crash dump for each thread. You just load the output into visual studio and it is as if you were debugging at the time of the crash. Hi - I've had an anonymous down vote on this answer.
When you can tell which function, change the message boxes to blocks of code or even individual lines within that function until you narrow it down to a few lines. Then you can start printing out the value of variables to see what state they are in at the point of crashing.
However, the underlying memory contents are often prefilled with 0x0000000 or 0xDEADBEEF or other recognisable patterns. No answer so far has tried to give a serious overview about the available techniques for debugging release applications: Release and Debug builds behave differently for many reasons. Here is an excellent overview.
You are getting NullPointerException at android.support.v4.widget.drawerlayout
NullPointerException is thrown when an application attempts to use an object reference that has the null value.
When you prepare your application for release, you configure, build, and test a release version of your application. The configuration tasks are straightforward, involving basic code cleanup and code modification tasks that help optimize your application.
Read Prepare for Release
set minifyEnabled false
You can customise your build.gradle
like this
buildTypes {
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
debuggable false
zipAlignEnabled true
jniDebuggable false
renderscriptDebuggable false
}
}
Make sure using stable support library and build tools .
compileSdkVersion 24
buildToolsVersion "24.0.2"
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'com.android.support:design:24.2.0'
Project Level
classpath 'com.android.tools.build:gradle:2.1.2' // or 2.2.2
Then
On the main menu, choose File | Invalidate Caches/Restart. The Invalidate Caches message appears informing you that the caches will be invalidated and rebuilt on the next start. Use buttons in the dialog to invalidate caches, restart Android Studio .
Note : You can provide us your build.gradle
. Disable "instant run"
Facility .
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With