Why the build process ignore proguardFiles getDefa

2019-07-27 00:17发布

问题:

All the while, I don't have any issue with my build process. I'm using latest build.gradle. I'm using Android Studio 3.1.3.

build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.3'
        classpath 'com.google.gms:google-services:3.2.0'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven {
            url "https://jitpack.io"
        }
    }
}

However, when I build a release APK, I face the following problem which I had never face before : Android release APK crash with java.lang.AssertionError: impossible in java.lang.Enum

This is my app's build.gradle

buildTypes {
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt', 'proguard-google-api-client.txt'
        lintOptions {
            disable 'MissingTranslation'
        }
    }
}

I suspect the content of getDefaultProguardFile('proguard-android.txt') is not being picked up.

So, if I manual copy the content of C:\Users\yccheok\AppData\Local\Android\Sdk\tools\proguard\proguard-android.txt to my project proguard-project.txt. The problem will resolve.

May I know why it is so? The only change I did, is to introduce

def lifecycle_version = "1.1.1"
// ViewModel and LiveData
implementation "android.arch.lifecycle:extensions:$lifecycle_version"
// alternately - if using Java8, use the following instead of compiler
implementation "android.arch.lifecycle:common-java8:$lifecycle_version"

in build.gradle. But, I'm not sure how that related to my proguard rule.

回答1:

According to Android Documentation the default proguard file is copied to directory project-dir/build/intermediates/proguard-files/.

Check if this directory exists. If not, you may have no permissions to create it. This can cause the problem.