1

I am trying to get a signed APK for my Android app. The app works perfectly when I install it through Android studio but when I generate a signed APK and install the app using that APK I get the following exception. Any idea on what could be going on?

    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.app.test/com.app.test.activities.MenuActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equalsIgnoreCase(java.lang.String)' on a null object reference
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2358)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2420)
            at android.app.ActivityThread.access$900(ActivityThread.java:154)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5292)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equalsIgnoreCase(java.lang.String)' on a null object reference
            at com.app.test.h.a.e(Unknown Source)
            at com.app.test.activities.MenuActivity.a(Unknown Source)
            at com.app.test.activities.MenuActivity.onCreate(Unknown Source)
            at android.app.Activity.performCreate(Activity.java:5990)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2311)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2420)
            at android.app.ActivityThread.access$900(ActivityThread.java:154)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5292)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)

This is what the gradle build file looks like

    buildscript {
    }
    apply plugin: 'com.android.application'

    android {
        compileSdkVersion 21
        buildToolsVersion "21.1.2"
        // that you installed in the SDK manager

        defaultConfig {
            applicationId "com.app.test"
            minSdkVersion 17
            targetSdkVersion 21
            versionCode 1
            versionName "1.0"
            multiDexEnabled true
        }
        buildTypes {
            release {
                minifyEnabled true
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }


    repositories {
        mavenCentral()
        flatDir {
            dirs 'libs'
        }

        maven { url 'http://maven.livotovlabs.pro/content/groups/public' }


    }

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'com.android.support:support-v4:21.0.3'
        compile 'com.google.android.gms:play-services:6.5.87'
        compile 'com.google.code.gson:gson:2.3.1'

        compile 'com.squareup.okhttp:okhttp:2.5.0'
        compile 'com.squareup.picasso:picasso:2.5.2'

    }
anonymous123
  • 1,271
  • 6
  • 19
  • 43
  • Can u post MenuActivity? – Raghavendra Jan 21 '16 at 05:31
  • Its a massive class, let me upload it to some other site and add the link here – anonymous123 Jan 21 '16 at 05:32
  • I think it is not about APK. Check if you are not accessing anything from Shared Preferences which you are not getting when you uninstall and reinstall the app using your signed apk. – DsD Jan 21 '16 at 05:37
  • Possible duplicate of [What is a Null Pointer Exception, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it) – 323go Jan 21 '16 at 05:41
  • Nope, this is not s duplicate of that. As answered by Rookie, this is very likely caused by ProGuard. – sfThomas Jan 21 '16 at 05:52

2 Answers2

4

You are using proguard and you have enables it by setting minifyEnabled to true.

buildTypes {
            release {
                minifyEnabled true
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }

If you dont want to use it make minifyEnabled false. Otherwise read about how to use proguard http://developer.android.com/tools/help/proguard.html here as it discards the class files and other resource that are not added in proguard-rules.pro.

Rookie
  • 304
  • 3
  • 16
1

I change minifyEnabled from true to false as follow:

minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
debuggable false

and it works fine.

BakaWaii
  • 6,732
  • 4
  • 29
  • 41
Noor Hossain
  • 1,620
  • 1
  • 18
  • 25