androidproguardshrink

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


I added the shrink options to my gradle, while the following error always happens:

: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.

Here is my gradle config:

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

        minifyEnabled true
        shrinkResources true
 }

and I also enabled the multidex options as :

 multiDexEnabled = true

compile 'com.android.support:multidex:1.0.1'

By checking the generated component.flags file, whose path is app/build/intermediates/multi-dex/defaultConfig/debug/components.jar, I found the first line become :

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

The :

injars /Users/zcc/app/build/intermediates/multi-dex/anZhi/release/allclasses.jar

is missing which causes the IOException.

The proguard source code is as follows for your reference:

 /**
 * 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

How can I fix this? Thanks a lot.


Solution

  • Well, the correct way is to add the proguard rule file in the build type, rather than in the Flavors block. Then the problem solved.