2

Background

Recently I've made a new app, and when I tried to generate a signed APK, I've noticed a weird behavior:

  • There was no mapping file anywhere in the project's folder.
  • When enabling the minimizing flags in the gradle file ("minifyEnabled" and "shrinkResources") , it showed an error:

Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'.

Job failed, see logs for details

The problem

Thing is, I didn't add anything special to the project that might cause the Proguard rules not to work. Everything is used in the default way they were set to be.

Here's the app gradle file (replaced some with "...") :

apply plugin: 'com.android.application'

android {
    signingConfigs {
        config {
            keyAlias '...'
            keyPassword '...'
            storeFile file(...)
            storePassword '...'
        }
    }
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId '...'
        minSdkVersion 14
        targetSdkVersion 25
        versionCode 21
        versionName "1.21"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
//        vectorDrawables.useSupportLibrary = true
    }
    packagingOptions {
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE-FIREBASE.txt'
        exclude 'META-INF/LICENSE-FIREBASE_jvm.txt'
    }
    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.config

        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    productFlavors {
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:25.1.1'
    compile 'com.android.support:design:25.1.1'  
    testCompile 'junit:junit:4.12'
    compile 'com.google.android.gms:play-services-plus:10.2.0'
    compile 'com.google.firebase:firebase-ads:10.2.0'
    ...
}

apply plugin: 'com.google.gms.google-services'

As you can see, it's about the same as the original one.

Here's the project gradle file:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.0-rc1'
        classpath 'com.google.gms:google-services:3.0.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        maven { url "https://jitpack.io" }
        maven {
            url 'https://dl.bintray.com/baole/maven'
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Nothing special here either.

What I've tried

I also tried to compare the project with another project I have, which doesn't have any issues with Proguard, but I can't find any special difference between them.

The question

Why doesn't Proguard get to work on the project when I sign the app? What should I do to make the special flags work too?

android developer
  • 114,585
  • 152
  • 739
  • 1,270
  • Down-voted for miss leading title. signing doesn't do anything with pro guard. you would probably face the issue if you enable Proguard on debug builds. – Alpha Mar 01 '17 at 08:11
  • @Alpha Signing, by default, does use Proguard. The issue in reality, is that the Proguard rules had a faulty line, which I've copied from one of the libraries I use. All the things I thought that caused the issue were ok. Only the Proguard rules were not. Anyway, I will now update the title. – android developer Mar 01 '17 at 08:38
  • updated my vote to upvote – Alpha Mar 01 '17 at 09:00
  • @Alpha Sorry and thank you. Just was confused about the reason for this issue, and it turned out I was looking in the wrong places, and had a very simple fix. – android developer Mar 01 '17 at 09:05

2 Answers2

1

Probably some of you dependency in app.gradle are causing this due to failing to import or referencing the classes. You can see the import or reference error before/after "Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'." line. The solution to this problem is NOT to minify such dependencies by modifying proguard-rule like this...

-keep class com.itextpdf.** { *; }
-dontwarn com.itextpdf.**

Here is a similar issue.

Community
  • 1
  • 1
MSC
  • 422
  • 5
  • 14
0

I've found what's causing it, in the proguard file:

-keep class com.google.android.gms.** {  ; }

And the solution is :

-keep class com.google.android.gms.** {  *; }
android developer
  • 114,585
  • 152
  • 739
  • 1,270