16

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)
Jordan Junior
  • 1,090
  • 10
  • 11

6 Answers6

4

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 .

.

IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
0
android{
  buildTypes{
     release{
        minifyEnabled false
     }
  }
}

Try this in your build.grade.

Or

Try to restart your Android Studio as well as your computer.As is known to all,Android Studio may perform stupid occasionally.

Qian Sijianhao
  • 564
  • 7
  • 19
0

if you are using proguard at release, decrease your gradle version to 2.1.2

classpath 'com.android.tools.build:gradle:2.1.2'
Eren Utku
  • 1,731
  • 1
  • 18
  • 27
0
buildTypes {
    release {
        minifyEnabled false
        shrinkResources false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

    }
}
lintOptions {
    abortOnError false
    checkReleaseBuilds false
    disable 'MissingTranslation'
}

Try this or just clean project and restart the project. Or Invalidate caches/restart From File Option. File>>Invalidate caches/restart

Jamil Hasnine Tamim
  • 4,389
  • 27
  • 43
0

Here are some steps you can take to fix these types of errors and make sure your app doesn't crash on future platform updates:

  • If your app uses private platform libraries, you should update it to include its own copy of those libraries or use the public NDK APIs.

  • If your app uses a third-party library that accesses private symbols, contact the library author to update the library.

  • Make sure you package all your non-NDK libraries with your APK.

  • Use standard JNI functions instead of getJavaVM and getJNIEnv from libandroid_runtime.so:

 AndroidRuntime::getJavaVM -> GetJavaVM from <jni.h>
    AndroidRuntime::getJNIEnv -> JavaVM::GetEnv or
    JavaVM::AttachCurrentThread from <jni.h>.

Use __system_property_get instead of the private property_get symbol from libcutils.so. To do this, use __system_property_get with the following include:

include

Note: The availability and contents of system properties is not tested through CTS. A better fix would be to avoid using these properties altogether. Use a local version of the SSL_ctrl symbol from libcrypto.so. For example, you should statically link libcyrpto.a in your .so file, or include a dynamically linked version of libcrypto.so from BoringSSL/OpenSSL and package it in your APK.

0

According to the android api reference - Android Developer Api Reference

If your layout configures more than one drawer view per vertical edge of the window, an exception will be thrown at runtime. I suspect your drawer layout is incorrect. Also check that the layout gravity of the drawer is set to "start"

android:layout_gravity="start"
koolkoda
  • 365
  • 3
  • 6