Android:应用程序在登录发布模式后启动时崩溃

Android: app crashed when starting after signing in release mode

目前我遇到了在release模式下登录后启动时应用崩溃的问题, 但在调试模式下它工作正常。

我现在无法解决问题, 尽管我做了研究并一直在寻找解决方案,但我仍然无法让它发挥作用

当应用程序崩溃时,它不会显示在我的应用程序 logcat 中,但会显示在“无过滤器

错误是

java.lang.NoSuchFieldError: NO_ACTION
        at java.lang.reflect.Method.getDefaultValue(Native Method)
        at java.lang.reflect.Method.getDefaultValue(Method.java:353)
        at libcore.reflect.AnnotationFactory.getElementsDescription(AnnotationFactory.java:75)
        at libcore.reflect.AnnotationFactory.<init>(AnnotationFactory.java:112)
        at libcore.reflect.AnnotationFactory.createAnnotation(AnnotationFactory.java:94)
        at java.lang.reflect.Field.getAnnotation(Native Method)
        at java.lang.reflect.Field.getAnnotation(Field.java:209)
        at com.a.g.a(Unknown Source)
        at com.a.b.a(Unknown Source)
        at com.a.b.a(Unknown Source)
        at com.a.b.onCreate(Unknown Source)
        at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252)
        at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
        at com.a.h.c(Unknown Source)
        at com.a.h.a(Unknown Source)
        at com.a.a.a(Unknown Source)
        at com.socialproperty.app.service.AppController.onCreate(Unknown Source)
        at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)
        at com.lbe.security.service.core.client.b.x.callApplicationOnCreate(Unknown Source)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4361)
        at android.app.ActivityThread.access00(ActivityThread.java:138)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1259)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5034)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:805)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:621)
        at dalvik.system.NativeStart.main(Native Method)

渐变配置

apply plugin: 'android'

android {
    signingConfigs {
        config {
            keyAlias 'keyalias'
            keyPassword 'xxxxxxxxx'
            storeFile file('path to keystore')
            storePassword 'xxxxxxx'
        }
    }
    compileSdkVersion 19
    buildToolsVersion '19.1.0'
    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled true
            signingConfig signingConfigs.config
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.google.android.gms:play-services:6.1.+'
    compile 'com.android.support:appcompat-v7:20.+'
    compile 'com.android.support:support-v13:21.0.0'
    compile 'com.android.support:support-v4:21.0.0'

    compile 'com.squareup.retrofit:retrofit:1.8.0'
    compile 'com.squareup.picasso:picasso:2.4.0'
    compile 'com.squareup.okio:okio:1.0.1'
    compile 'com.squareup.okhttp:okhttp:2.1.0'
    compile 'com.squareup.okhttp:okhttp-urlconnection:2.1.0'
}

ProGuard

-dontwarn retrofit.**
-dontwarn okio.**
-dontwarn com.squareup.okhttp.**

您的问题是混淆器正在重命名您的代码并且您正在使用反射。

最简单的解决方法是禁用混淆器(在您的 build.gradle 文件中将 minifyEnabled 设置为 false)。

如果你想保持 proguard 启用,你需要在你的 proguard 规则文件中添加 -keep yourclass。 例如,如果我想保留 Activity class:

-keep class android.app.Activity

如果我想保留所有 android.app 包裹:

-keep class android.app.**

有关混淆器的更多信息 here