android - 使用 proguard 规则排除文件

标签 android android-studio gradle proguard

我正在尝试使用 proguard 减小 apk 的大小。我在这样做时收到了这些警告消息,

Warning: can't write resource [META-INF/LICENSE.txt] (Duplicate zip entry [commons-lang-2.6.jar:META-INF/LICENSE.txt])
Warning: can't write resource [META-INF/NOTICE.txt] (Duplicate zip entry [commons-lang-2.6.jar:META-INF/NOTICE.txt])
Warning: can't write resource [.readme] (Duplicate zip entry [classes.jar:.readme])

除了保留类之外,还有什么方法可以排除这些文件吗?我已经在 gradle 文件中排除了这些,但这似乎不起作用。

最佳答案

如果你使用的是 Android Studio ,添加这个

到你的build.gradle

packagingOptions {
                exclude 'META-INF/LICENSE.txt'
                exclude 'META-INF/NOTICE.txt'
                exclude '.README'
            }

///完整示例

android {
    compileSdkVersion 23
    buildToolsVersion '22.0.1'
    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 22
        versionCode 1
        versionName '1.0'
        renderscriptTargetApi 22
    }
    buildTypes {
        debug {
            debuggable true
            minifyEnabled false
            renderscriptDebuggable true
            versionNameSuffix "-debug"
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        release {
            debuggable false
            minifyEnabled true
            shrinkResources false
            renderscriptDebuggable false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude '.README'
    }

}

关于android - 使用 proguard 规则排除文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28955887/

相关文章:

android - 保真警告渲染问题

android - Ionic 5 Capacitor Android 不显示地理定位结果

java - 如何将 gradle 项目的子模块安装或发布为 jar

android - 如何将外部库依赖项添加到我的库中?

android - com.android.tools.build:gradle:2.1.0及更高版本在构建时出错

android - 在 Activity 中绘制多个 View

android - 在绘制之后但在 onDraw() 完成之前修改位图

android - 如何渲染从 onPreExecute() 中的 AsyncTask 获取的 ArrayList<ImageView>?

android - 在 Android Studio 中导入图像作为背景

java - 错误: Could not find method SubmitRegister(View) in a parent or ancestor Context for android:onClick attribute defined on view class