Proguard is a good Java tool to optimize and obfuscate the source code and the Android build tool includes it already. To apply Proguard in Android project is as easy as just changing false to true. However, its settings are a little complicated specifically for 3rd-party libraries. You might experience that when you want to apply Proguard to your projects, you have to look for the documents of the libraries the projects use or google that to see if there is information say how to apply Proguard for these libraries. This experience is kind of awful. To be kind to other developers who uses your libraries, you can provide the Proguard settings inside of your android libraries. Therefore, the projects that use your libraries automatically apply the settings.

Use consumerProguardFiles Option

Android build tool has the mechanism to merge Proguard settings. All you need are adding settings in a file and add consumerProguardFiles option pointing to the file in build.gradle. For example,

# proguard-rules.pro
-keep public class com.swarmnyc.fulton.android.Fulton { *; }
# build.gradle
android {
    defaultConfig {
        ...
        consumerProguardFiles 'proguard-rules.pro'
    }
}

You can see this manual to know how to use Proguard.

Debug

Applying Proguard is easy, but making it right is hard. I use JADX to decompile APKs which is applied Proguard to check Proguard does its job well or not.

This image shows a sample APK that build with merging the Proguard settings from Fulton-Android, a library I made, in a sample Android project and Proguard keeps the necessary classes.

image