Android的与摇篮和ProGuard的构建:"必须输入罐子后指定的输出罐子,或者它将是空的" [英] Android Build with Gradle and ProGuard : "The output jar must be specified after an input jar, or it will be empty"

查看:419
本文介绍了Android的与摇篮和ProGuard的构建:"必须输入罐子后指定的输出罐子,或者它将是空的"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建与摇篮不同口味的构建。它用来运行相当不错直到现在,直到我希望能够让的Proguard 。我启用 minifyEnabled 我的发布版本,现在我有一个例外,俗话说:

产生的原因:org.gradle.internal.UncheckedException:java.io.IOException异常:输出罐子[... /应用/建造/中间体/多DEX的/ dev /发行/ componentClasses的.jar]必须输入罐子之后指定,否则它将是空的。

有谁知道是什么原因造成这个异常?我基本上要启用的ProGuard之前,我松开我的申请。这里是我下面的摇篮文件。

  lintOptions {
    abortOnError假
}dexOptions {
    真正的增量
    javaMaxHeapSize4G
}defaultConfig {
        的applicationID...
        14的minSdkVersion
        targetSdkVersion 22
        版本code 1
        的versionName1.0
        multiDexEnabled真
    }buildTypes {    发布 {
        minifyEnabled真
        proguardFiles getDefaultProguardFile('proguard的-android.txt'),'proguard-rules.pro
        signingConfig signingConfigs.release
    }    调试{
        minifyEnabled假
        shrinkResources假
        proguardFiles getDefaultProguardFile('proguard的-android.txt'),'proguard-rules.pro
        signingConfig signingConfigs.debug
    }
}

ProGuard的规则文件。

 #加入项目的具体规则的ProGuard这里。
#默认情况下,此文件中的标志被附加到指定的标志
#在/Users/osayilgan/Development/Android/sdk/tool​​s/proguard/proguard-android.txt
#您可以编辑包含路径和秩序通过改变proguardFiles
在的build.gradle#指令。

#欲了解更多详情,请参阅
#http://developer.android.com/guide/developing/tool​​s/proguard.html#添加任何具体项目保持选择这里:#如果你的项目使用的WebView与JS,取消以下
#并指定完全限定类名给JavaScript接口
#类:
#-keepclassmembers类fqcn.of.javascript.interface.for.webview {
# 上市 *;
#}-keepnames公共类*扩展io.realm.RealmObject
-keep类io.realm ** {*。 }
-dontwarn的javax。**
-dontwarn io.realm。**

和这里是ProGuard的-Android文件。这是默认的从Android SDK中。

 #这是ProGuard的配置文件。
#http://proguard.sourceforge.net/index.html#manual/usage.html-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose#优化是默认关闭的。地塞米松不喜欢code运行
#通过ProGuard的优化和preverify步骤(并执行一些
#这些优化自身)的。
-dontoptimize
-dont preverify
#请注意,如果要启用优化,你不能只是
#在你自己的项目配置文件优化标志;
#相反,你需要将指向
#ProGuard的,Android的optimize.txt文件,而不是一个来自您的
#project.properties文件。-keepattributes *注释*
-keep公共类com.google.vending.licensing.ILicensingService
-keep公共类com.android.vending.licensing.ILicensingService#对于本地方法,请参阅http://proguard.sourceforge.net/manual/examples.html#native
-keepclasseswithmembernames类* {
    天然的所述;方法&gt ;;
}#制定者保持在视图中,这样的动画仍然可以正常工作。
#看到http://proguard.sourceforge.net/manual/examples.html#beans
-keepclassmembers公共类*宽android.view.View {
   空集*(***);
   ***获得*();
}#我们要保持活性的方法,可以在XML中使用属性的onClick
-keepclassmembers类*宽android.app.Activity {
   公共无效*(android.view.View);
}#对于枚举类,请参见http://proguard.sourceforge.net/manual/examples.html#enumerations
-keepclassmembers枚举* {
    公共静态** []值();
    公共静态**的valueOf(java.lang.String中);
}-keep类*实现android.os.Parcelable {
  公共静态最终android.os.Parcelable $造物主*;
}-keepclassmembers类**。R $ * {
    公共静态<领域取代;
}#支持库包含到新的平台的版本引用。
#不发出警告的情况下,在这个程序是链接到的一个老
#平台版本。我们了解他们,他们是安全的。
-dontwarn android.support。**


解决方案

过了相当长一段时间,我的数字出来,但正如我已经猜到,这是所有关于Proguard的配置。

我开始通过在控制台的警告挖,意识到一些参考文献不能用Proguard的发现。因此,将其添加为 -dontwarn 来的ProGuard配置文件解决了这个问题。

在我而言,我不得不忽视以下套餐;

  -dontwarn java.lang.invoke **
-dontwarn org.apache.lang。**
-dontwarn org.apache.commons。**
-dontwarn com.nhaarman。**
-dontwarn se.emilsjolander。**

I'm creating a build with different flavors with Gradle. It used to run quite good until now, until I wanted to enable Proguard. I enabled minifyEnabled for my Release Build and now I'm having an exception saying :

"Caused by: org.gradle.internal.UncheckedException: java.io.IOException: The output jar [.../app/build/intermediates/multi-dex/dev/release/componentClasses.jar] must be specified after an input jar, or it will be empty."

Does anybody know what is causing this exception ? I basically want to enable ProGuard before I release my application. Here is my Gradle file below.

lintOptions {
    abortOnError false
}

dexOptions{
    incremental true
    javaMaxHeapSize "4g"
}

defaultConfig {
        applicationId "..."
        minSdkVersion 14
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }

buildTypes {

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

    debug {
        minifyEnabled false
        shrinkResources false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.debug
    }
}

ProGuard Rules file.

# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/osayilgan/Development/Android/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
#   http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;
#}

-keepnames public class * extends io.realm.RealmObject
-keep class io.realm.** { *; }
-dontwarn javax.**
-dontwarn io.realm.**

And Here is the proguard-android file. This is the default one from Android SDK.

# This is a configuration file for ProGuard.
# http://proguard.sourceforge.net/index.html#manual/usage.html

-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose

# Optimization is turned off by default. Dex does not like code run
# through the ProGuard optimize and preverify steps (and performs some
# of these optimizations on its own).
-dontoptimize
-dontpreverify
# Note that if you want to enable optimization, you cannot just
# include optimization flags in your own project configuration file;
# instead you will need to point to the
# "proguard-android-optimize.txt" file instead of this one from your
# project.properties file.

-keepattributes *Annotation*
-keep public class com.google.vending.licensing.ILicensingService
-keep public class com.android.vending.licensing.ILicensingService

# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native
-keepclasseswithmembernames class * {
    native <methods>;
}

# keep setters in Views so that animations can still work.
# see http://proguard.sourceforge.net/manual/examples.html#beans
-keepclassmembers public class * extends android.view.View {
   void set*(***);
   *** get*();
}

# We want to keep methods in Activity that could be used in the XML attribute onClick
-keepclassmembers class * extends android.app.Activity {
   public void *(android.view.View);
}

# For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations
-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}

-keepclassmembers class **.R$* {
    public static <fields>;
}

# The support library contains references to newer platform versions.
# Don't warn about those in case this app is linking against an older
# platform version.  We know about them, and they are safe.
-dontwarn android.support.**

解决方案

It took quite a while for me to figure it out but, as I had guessed, it was all about Proguard configuration.

I started to dig through the Warnings in the Console and realized that some of the References couldn't be found by Proguard. So adding them as -dontwarn to proguard configuration file solved the problem.

In my case, I had to ignore packages below;

-dontwarn java.lang.invoke**
-dontwarn org.apache.lang.**
-dontwarn org.apache.commons.**
-dontwarn com.nhaarman.**
-dontwarn se.emilsjolander.**

这篇关于Android的与摇篮和ProGuard的构建:&QUOT;必须输入罐子后指定的输出罐子,或者它将是空的&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆