Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Gradle 2.2 Not Allowing ShrinkResources for Signed APK

As part of the Android Studio 2.2 roll out I updated my Gradle Build tools to v2.2. After doing that my signed APK build process fails because I have shrinkResources = true.

Once I switch back to Gradle v2.1.3 OR set shrinkResources = false everything works fine. Here's my app gradle build file:

    android {
    signingConfigs {

    }
    compileSdkVersion 24
    buildToolsVersion '24.0.0'
    defaultConfig {
        applicationId "com.sample.testapp"
        minSdkVersion 21
        targetSdkVersion 24
        versionCode 4
        versionName "0.0.4"
    }
    buildTypes {
        release {
            minifyEnabled false
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            proguardFile 'C:/Users/code/testapp/app/proguard-rules.pro'
        }
    }
    productFlavors {
    }
}

With Gradle set to v2.2 here's the build error I get when generating a signed APK

enter image description here

Does anyone know why this is occurring and if there's a work around? I've Googled around a bit and have seen some older Android Bug reports about alpha and beta Gradle builds having this issue, but the reports I found were >6 months old (and for previous Gradle versions).

P.S. I know that minifyEnabled = false currently, i have yet to investigate the correct set of proguard rules for my included libraries to prevent the Signed Build from erroring out due to missing libs.

like image 882
Matt Yoder Avatar asked Sep 22 '16 00:09

Matt Yoder


2 Answers

To use shrinkResources you have to use minifyEnabled

As per Android documentation:

Resource shrinking works only in conjunction with code shrinking. After the code shrinker removes all unused code, the resource shrinker can identify which resources the app still uses. This is especially true when you add code libraries that include resources—you must remove unused library code so the library resources become unreferenced and, thus, removable by the resource shrinker.

To enable resource shrinking, set the shrinkResources property to true in your build.gradle file (alongside minifyEnabled for code shrinking).

like image 174
Ivan Alburquerque Avatar answered Oct 05 '22 14:10

Ivan Alburquerque


use

minifyEnabled false
shrinkResources false

or

minifyEnabled true
shrinkResources true

may be a bug on android gradle plugin

wait google fix bugs

like image 22
jiechic Avatar answered Oct 05 '22 13:10

jiechic