在android studio中生成签名.apk显示错误很遗憾关闭

时间:2015-07-08 16:49:34

标签: android mobile android-studio

我将从 android studio 生成签名的apk,我正在尝试减少.apk文件大小。所以从某个地方我得到了使用Progaurd的解决方案,为此我必须在< strong> build.gradle 文件。 更改是make &#34; minifyEnabled true&#34; 而不是&#34; minifyEnabled false&#34; 。 这是build.gradle文件代码

apply plugin: 'com.android.application'

1android {
compileSdkVersion 22
buildToolsVersion "22.0.1"

defaultConfig {
    applicationId "com.rahu.createsomething"
    minSdkVersion 9
    targetSdkVersion 22
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'),   'proguard-rules.pro'
      }
   }
}

 dependencies {
  compile fileTree(dir: 'libs', include: ['*.jar'])
  compile 'com.android.support:appcompat-v7:22.1.1'
}

现在的问题是当我制造&#34; minifyEnabled为真&#34;我将文件大小减少1.47 GB到0.97 MB。 但是,当我运行该apk文件时,它显示错误消息&#34;不幸的是关闭应用程序&#34;。

当使用&#34; minifyEnable false&#34;生成apk时然后它生成1.47 GB .apk文件,它工作正常。 但我想要0.97 MB的apk这样我怎么能生成它?

这是我的错误logcat消息

07-08 23:18:21.983  29845-29845/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.AssertionError
        at com.abc.android.publish.i.b.a.bf.<init>(Unknown Source)
        at com.abc.android.publish.i.b.a.as.a(Unknown Source)
        at com.abc.android.publish.i.k.a(Unknown Source)
        at com.abc.android.publish.i.b.a.q.<init>(Unknown Source)
        at com.abc.android.publish.i.b.a.p.a(Unknown Source)
        at com.abc.android.publish.i.b.a.p.a(Unknown Source)
        at com.abc.android.publish.i.b.a.p.a(Unknown Source)
        at com.abc.android.publish.i.k.a(Unknown Source)
        at com.abc.android.publish.i.k.a(Unknown Source)
        at com.abc.android.publish.i.k.a(Unknown Source)
        at com.abc.android.publish.i.k.a(Unknown Source)
        at com.abc.android.publish.i.k.a(Unknown Source)
        at com.abc.android.publish.af.a(Unknown Source)
        at com.abc.android.publish.q.a(Unknown Source)
        at com.abc.android.publish.q.a(Unknown Source)
        at com.rahu.createsomething.CreateSomething.onCreate(Unknown Source)
        at android.app.Activity.performCreate(Activity.java:5283)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2209)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2299)
        at android.app.ActivityThread.access$700(ActivityThread.java:150)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:5283)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
        at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:2)

你能把详细的堆栈跟踪...我想问题是由于proguard优化。

有时候如果你使用外部库/ jars proguard会导致问题。

此外,如果您通过反射调用代码(代码中引用的类未在其他任何地方引用)并且proguard工具已删除该特定类,则您可能在运行时遇到异常。

有多种方法可以配置proguard - http://developer.android.com/tools/help/proguard.html#configuring