Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between proguard-android.txt and proguard-rules.pro ? - Android

In my buildType I see this:

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

I have some questions:

  1. Why there are two files?
  2. What is the difference between them?
  3. Where should I write my rules?
like image 705
MBH Avatar asked Jan 01 '16 06:01

MBH


People also ask

What is ProGuard-Android txt?

The getDefaultProguardFile('proguard-android.txt') will retrieve the ProGuard settings that are stored in the Android SDK in tools/proguard. The proguard-rules.pro is a file that is located at the root of the module. The purpose is to allow you to add custom rules (ProGuard) that are specific to the module.

What is Android ProGuard rules?

ProGuard is a tool to help minify, obfuscate, and optimize your code. It is not only especially useful for reducing the overall size of your Android application as well as removing unused classes and methods that contribute towards the intrinsic 64k method limit of Android applications.


1 Answers

The getDefaultProguardFile('proguard-android.txt') method obtains the default ProGuard settings from the Android SDK tools/proguard/ folder. The proguard-android-optimize.txt file is also available in this Android SDK folder with the same rules but with optimizations enabled. ProGuard optimizations perform analysis at the bytecode level, inside and across methods to help make your app smaller and run faster. Android Studio adds the proguard-rules.pro file at the root of the module, so you can also easily add custom ProGuard rules specific to the current module.

Please refer this: https://developer.android.com/studio/build/shrink-code

Meaning that you should add your custom proguard file into proguard-rules.pro,if you want to separate some rules to many files,you can do it and declare them after this:

proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
like image 110
starkshang Avatar answered Oct 11 '22 11:10

starkshang