如何在Android Studio中使用缩小的类构建.aar库? [英] How can I build an .aar library with shrunk classes in Android Studio?

查看:86
本文介绍了如何在Android Studio中使用缩小的类构建.aar库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想构建一个.aar库和proguard类,但是我的库proguard文件不起作用,并且可以看到清晰的类.

I want to build an .aar library and proguard classes, but my library proguard file doesn't work, and I can see clear classes.

这是我的保护文件:

android {
    buildTypes {
         release {
         minifyEnabled true
         useProguard true
         proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules-my-lib.pro'
                 }
           }
    }

和app/build.gradle:

and app/build.gradle:

  android {
    buildTypes {
       release {
       minifyEnabled true
       proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
             }
         }
    }

推荐答案

虽然您可以缩小和混淆库本身,但通常的做法是将 minifyEnabled 保留为 false ,并使用 consumerProguardFiles 而不是 proguardFiles 为应用程序提供proguard配置.

While you can probably shrink and obfuscate the library itself, the usual practice is to leave minifyEnabled as false and provide the proguard configuration to the application, using consumerProguardFiles instead of proguardFiles.

这意味着使用应用程序 proguardFiles 和库 consumerProguardFiles 中的合并配置,在整个应用程序中仅应用一次缩小.这通常会更有效,因为可以删除应用程序未实际使用的部分库.

This means that the minification is applied only once, on the whole application, using the merged configuration from the app's proguardFiles and the libraries consumerProguardFiles. This is usually more efficient because parts of the libraries not actually used by the application can be removed.

这篇关于如何在Android Studio中使用缩小的类构建.aar库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆