Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Application crashes only in release version

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)
like image 996
Jordan Junior Avatar asked Nov 01 '16 19:11

Jordan Junior


People also ask

Why do my applications keep crashing?

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.

Why does my app close as soon as I open it?

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.

Why does my if statement crash when I try to debug?

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.

How do I get a crash dump for a release build?

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.

How can I tell which function is running when a program crashes?

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.

Is it possible to debug release applications with 0x0000000 or 0xDEADBEEF?

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.


1 Answers

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.

How can a NullPointerException launches only on release apk?

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.

  1. Read Prepare for Release

  2. 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 .

.

like image 145
IntelliJ Amiya Avatar answered Oct 06 '22 01:10

IntelliJ Amiya