android gradle shrinkresources 没有在 components.flags 文件中生成 injars

android gradle shrinkresources no injars is generated in components.flags file

我在 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 配置:

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

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

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