Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include a proguard configuration in my Android library (AAR)

Android libraries, per the AAR file spec, includes a 'proguard.txt' file. My understanding is that this file declares how the library correctly can be obfuscated and minified. In my case I need to preserve some API-classes.

How can I declare the library's proguard.txt file in the library's build.gradle? And will this file be automatically read when creating an application (APK) that uses my library?

I didn't find this information in Android's Gradle Plugin User Guide.

like image 705
Per Christian Henden Avatar asked May 12 '15 21:05

Per Christian Henden


People also ask

How do I add AAR library?

Add your AAR or JAR as a dependency To use your Android library's code in another app module, proceed as follows: Navigate to File > Project Structure > Dependencies. In the Declared Dependencies tab, click and select Jar Dependency in the dropdown. In the Add Jar/Aar Dependency dialog, first enter the path to your .

Where do I put ProGuard file?

You can manually create the file in the \StudioProjects\your_project\app folder and you can add the custom rules.

What is ProGuard config file in Android Studio?

The proguard-rules.pro file is where you can add custom ProGuard rules. By default, this file is located at the root of the module (next to the build.


1 Answers

In your Gradle file's default configuration closure, specify your Proguard file with consumerProguardFiles instead of proguardFiles. For example:

defaultConfig {     consumerProguardFiles 'proguard.txt' } 
like image 119
Johan Halin Avatar answered Sep 22 '22 13:09

Johan Halin