Using Common Proguard File in Multi-Application-Module Android Project

Viewed 33

I have created a Wear OS module in our existing Android mobile application. Both application modules remain in the project like following:

Project/app
Project/wear/wear_presentation
Project/otherLibModule/other_lib_module_presentation

and we have a common.gradle that is used by app and wear_presentation:

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

        debug {
            debuggable true
            minifyEnabled false
        }
    }

Before Wear OS module, we had a single proguard file inside app module that handles all minifying work, but now we have 2 application modules that have separate proguard files. That forces me to copy/paste all content from app proguard file into wear_presentation proguard file and this approach seems amateurish.

I want to use a single common proguard file that is used by both app and wear_presentation modules.

Is it possible?

1 Answers

Importing from Libraries is supported already.

https://developer.android.com/studio/build/shrink-code#configuration-files

/proguard.txt - If an AAR library is published with its own ProGuard rules file, and you include that AAR as a compile-time dependency, R8 automatically applies its rules when compiling your project.

Using rules files that are packaged with AAR libraries is useful if certain keep rules are required for the library to function properly—that is, the library developer has performed the troubleshooting steps for you.

However, you should be aware that, because ProGuard rules are additive, certain rules that an AAR library dependency includes cannot be removed and might impact the compilation of other parts of your app. For example, if a library includes a rule to disable code optimizations, that rule disables optimizations for your entire project. /META-INF/proguard/ - for JAR libraries

It's commonly used by libraries like OkHttp https://github.com/square/okhttp/blob/okhttp_4.10.x/okhttp/src/main/resources/META-INF/proguard/okhttp3.pro

Related