简体   繁体   English

Android-使用签名的APK时应用崩溃

[英]Android - app crashes when using a signed APK

I am trying to get a signed APK for my Android app. 我正在尝试为我的Android应用获取签名的APK。 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. 通过Android Studio安装该应用程序时,该应用程序运行完美,但是当我生成签名的APK并使用该APK安装应用程序时,出现以下异常。 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 这是gradle构建文件的样子

    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. 您正在使用proguard,并且已通过将minifyEnabled设置为true启用了它。

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

If you dont want to use it make minifyEnabled false. 如果您不想使用它,请将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. 否则,请在此处阅读有关如何使用proguard的信息http://developer.android.com/tools/help/proguard.html ,因为它会丢弃没有在proguard-rules.pro中添加的类文件和其他资源。

I change minifyEnabled from true to false as follow: 我将minifyEnabledtrue更改为false ,如下所示:

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

and it works fine. 而且效果很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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