项目作者: krschultz

项目描述 :
普通Android库的Proguard配置
高级语言: IDL
项目地址: git://github.com/krschultz/android-proguard-snippets.git
创建时间: 2013-10-22T16:44:36Z
项目社区:https://github.com/krschultz/android-proguard-snippets

开源协议:Apache License 2.0

下载


android-proguard-snippets

Example Proguard configurations for common Android libraries.

This project assumes that your ProGuard configuration is based off of the latest official proguard-android.txt config as shown below. Each library configuration should only be the rules required for that specific library, not a complete Android ProGuard configuration. The various library configurations are combined by the Gradle build system. The library rules should be universal, any app specific rules (such as preserving model classes) should be added in a custom proguard-project.pro file.

Request additional libraries through issues. Pull requests are welcome.

Android Arsenal

Usage

  1. android {
  2. buildTypes {
  3. release {
  4. minifyEnabled true
  5. // Library specific proguard files
  6. proguardFile 'proguard-google-play-services.pro'
  7. proguardFile 'proguard-gson.pro'
  8. ...
  9. // Default proguard files & project app specific rules,
  10. // see examples folder for more information
  11. proguardFile 'proguard-project-app.pro'
  12. proguardFile getDefaultProguardFile('proguard-android.txt')
  13. // As of Gradle Android plugin 1.1.0, the test APK has a separate config
  14. testProguardFile 'proguard-project-test.pro'
  15. }
  16. }
  17. }

Instead of declaring each configuration file manually, you could also store them in a seperate directory and include them all at once:

  1. FileCollection proGuardFileCollection = files { file('./proguard').listFiles() }
  2. proguardFiles(proGuardFileCollection)

Libraries

ProGuard tip for android libraries developers

The android libraries developers can include the proguard directives in the libraries. The Android Plugin for Gradle automatically appends ProGuard configuration files in an AAR (Android ARchive) package and appends that package to your ProGuard configuration

The developers only need to specify the Proguard file with consumerProguardFiles instead of proguardFiles:

  1. defaultConfig {
  2. consumerProguardFiles 'proguard-file.pro'
  3. }