Android Studio Release版本给了我:不幸的是,“App Name”已停止

时间:2015-03-02 18:49:50

标签: android build android-studio release signing

我正在使用Android Studio 1.1.0。 构建变体debug工作正常,但是当我尝试运行release构建变体时,应用程序启动但是给了我一个"不幸的是,“应用程序名称”已停止。"

我过去已经签署了我的应用程序,也许我错过了一个我完全忘记的简单步骤,我错过了什么?

这是我的build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"
    defaultConfig {
        applicationId "com.madx.quiz.apf"
        minSdkVersion 14
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }

    signingConfigs {
        release {
            storeFile file('/Users/madx/Documents/Workspaces/Android/APF/app/keystore.keystore')
            storePassword ‘my_store_password’
            keyAlias ‘my_key_alias’
            keyPassword ‘my_key_password’
        }
        debug {}
    }

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

repositories{
// some repositories
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile 'com.android.support:support-v13:21.0.0'
    compile 'com.google.code.gson:gson:2.3.1'
}

事件日志给了我:

19:52:49 Gradle build finished in 3 sec
19:52:50 Session 'app': running

logcat的:

03-02 19:33:11.851  25913-25913/com.madx.quiz.apf I/art﹕ Late-enabling -Xcheck:jni
03-02 19:33:12.840  25913-25946/com.madx.quiz.apf D/OpenGLRenderer﹕ Render dirty regions requested: true
03-02 19:33:12.849  25913-25913/com.madx.quiz.apf D/Atlas﹕ Validating map...
03-02 19:33:12.922  25913-25946/com.madx.quiz.apf I/Adreno-EGL﹕ <qeglDrvAPI_eglInitialize:410>: QUALCOMM Build: 10/24/14, 167c270, I68fa98814b
03-02 19:33:12.924  25913-25946/com.madx.quiz.apf I/OpenGLRenderer﹕ Initialized EGL, version 1.4
03-02 19:33:12.936  25913-25946/com.madx.quiz.apf D/OpenGLRenderer﹕ Enabling debug mode 0

Gradle控制台:

Executing tasks: [:app:generateReleaseSources]

Configuration on demand is an incubating feature.
:app:preBuild
:app:preReleaseBuild
:app:checkReleaseManifest
:app:preDebugBuild
:app:prepareComAfollestadMaterialDialogs0612Library UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72103Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV132100Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42103Library UP-TO-DATE
:app:prepareComGithubDanielemaddalunoAndroidupdatecheckerLibrary102Library UP-TO-DATE
:app:prepareReleaseDependencies
:app:compileReleaseAidl UP-TO-DATE
:app:compileReleaseRenderscript UP-TO-DATE
:app:generateReleaseBuildConfig UP-TO-DATE
:app:generateReleaseAssets UP-TO-DATE
:app:mergeReleaseAssets UP-TO-DATE
:app:generateReleaseResValues UP-TO-DATE
:app:generateReleaseResources UP-TO-DATE
:app:mergeReleaseResources
:app:processReleaseManifest UP-TO-DATE
:app:processReleaseResources
:app:generateReleaseSources

BUILD SUCCESSFUL

Total time: 2.4 secs

1 个答案:

答案 0 :(得分:3)

尝试在发布版本中禁用ProGuard:

build.gradle

buildTypes {
    release {
        signingConfig signingConfigs.release
        zipAlignEnabled true
    }
    debug {
    }
}

问题可能是由ProGuard造成的,但如果没有堆栈跟踪,我无法解决您的问题。

我仍然想使用proguard我建议您查找有关错误的更多信息,您可以在发布字段中添加以下内容:

debuggable true
jniDebuggable true

因此,您可以更好地识别问题。 但是,问题可能与gson库有关,您应该在proguard-rules.pro文件中添加以下行(您可以查看更复杂的示例here):

# Add any classes the interact with gson
-keepclassmembers class com.madx.quiz.apf.apf.APFQuestion { *; }
-keepclassmembers class com.madx.quiz.apf.apf.APFSubCategory { *; }

###---------------Begin: proguard configuration for Gson  ----------
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature

# For using GSON @Expose annotation
-keepattributes *Annotation*

# Gson specific classes
-keep class sun.misc.Unsafe { *; }
#-keep class com.google.gson.stream.** { *; }

# Application classes that will be serialized/deserialized over Gson
-keep class com.google.gson.examples.android.model.** { *; }

##---------------End: proguard configuration for Gson  ----------