android gradle shrinkresources在components.flags文件

时间:2015-10-09 10:13:06

标签: android proguard shrink

我将缩小选项添加到 gradle ,而以下错误总是发生:

:app:shrinkDefaultConfigDebugMultiDexComponents FAILED
Error:Execution failed for task    
:app:shrinkDefaultConfigDebugMultiDexComponents'.
java.io.IOException: The output jar [[mypath]/componentClasses.jar] must be specified after an input jar, or it will be empty.

这是我的 gradle cofig

debug{
        project.archivesBaseName = "zcctest131"
        signingConfig signingConfigs.myConfig

        minifyEnabled true
        shrinkResources true
 }

我还启用了multidex选项:

 multiDexEnabled = true

编译'com.android.support:multidex:1.0.1'

通过检查生成的component.flags文件,其路径为app/build/intermediates/multi-dex/defaultConfig/debug/components.jar,我发现第一行变为:

outjars /Users/zcc/app/build/intermediates/multi-dex/defaultConfig/debug/componentClasses.jar

injars /Users/zcc/app/build/intermediates/multi-dex/anZhi/release/allclasses.jar
缺少导致IOException

proguard源代码如下供您参考:

 /**
 * Reads the input jars (or directories).
 */
private void readInput() throws IOException
{
    if (configuration.verbose)
    {
        System.out.println("Reading jars...");
    }

    // Check if we have at least some program jars.
    if (configuration.programJars == null)
    {
        throw new IOException("The input is empty. You have to specify one or more '-injars' options.");
    }

    // Read the input program jars.
    readInput("Reading program ",
              configuration.programJars,
              createDataEntryClassPoolFiller(false));

...

http://proguard.sourceforge.net/quality/compatibility/code/proguard/ProGuard.html

我该如何解决这个问题? 非常感谢。

1 个答案:

答案 0 :(得分:0)

嗯,正确的方法是在构建类型中添加proguard规则文件,而不是在Flavors块中。然后问题就解决了。