简体   繁体   中英

Android - app crashes when using a signed APK

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'

    }

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM