【问题标题】:Why the build process ignore proguardFiles getDefaultProguardFile('proguard-android.txt')为什么构建过程忽略 proguardFiles getDefaultProguardFile('proguard-android.txt')
【发布时间】:2019-01-12 14:18:36
【问题描述】:

一直以来,我的构建过程都没有任何问题。我正在使用最新的build.gradle。我正在使用 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"
        }
    }
}

但是,当我构建发布版 APK 时,我遇到了以下我从未遇到过的问题:Android release APK crash with java.lang.AssertionError: impossible in java.lang.Enum

这是我应用的build.gradle

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

我怀疑getDefaultProguardFile('proguard-android.txt')的内容没有被提取。

所以,如果我手动将C:\Users\yccheok\AppData\Local\Android\Sdk\tools\proguard\proguard-android.txt 的内容复制到我的项目proguard-project.txt。问题会解决的。

我可以知道为什么会这样吗?我做的唯一改变就是引入

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"

build.gradle。但是,我不确定这与我的 proguard 规则有什么关系。

【问题讨论】:

  • 我遇到了同样的问题,我也手动复制了文件。你找到真正的原因了吗?

标签: android crash build.gradle retrofit2


【解决方案1】:

根据Android Documentation默认的proguard文件复制到目录project-dir/build/intermediates/proguard-files/

检查此目录是否存在。如果没有,您可能没有创建它的权限。这可能会导致问题。

【讨论】:

  • 我在路径上手动创建了提到的目录,但它仍然没有正确加载文件。
猜你喜欢
  • 2016-04-05
  • 2012-08-30
  • 1970-01-01
  • 2022-06-16
  • 2019-11-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-07
相关资源
最近更新 更多