Ask Your Question
1

Can an Android library module be Proguarded without Proguarding the application module?

asked 2021-06-29 11:00:00 +0000

woof gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2022-01-08 19:00:00 +0000

scrum gravatar image

Yes, it is possible to Proguard an Android library module without Proguarding the application module.

Proguarding an Android library module eliminates unused code and resources, reduces the APK size, and obfuscates the code to enhance security. It does not affect the application module, which can have its own Proguard configuration file that specifies which parts of the code should be excluded from obfuscation for compatibility or debug purposes.

To Proguard an Android library module without affecting the application module, you need to configure the library's Gradle build file to apply the Proguard rules only to the library module. This is done by adding the following line to the library module's build.gradle file:

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

By specifying minifyEnabled true and proguardFiles, you're telling Gradle to enable Proguarding for the release build type of the library module, and to use the specified Proguard configuration file (proguard-rules.pro) to define which parts of the code should be obfuscated, which classes and methods should be kept, and which resources should be processed.

You can also use the -dontwarn directive in the Proguard configuration file to suppress warnings and errors about missing classes or methods that are not used by the library module, but may be used by the application module.

Once you have configured the library module to use Proguard, you can build and export the module as an AAR file, which can be included in the application module as a dependency. The application module can have its own Proguard configuration file, which can exclude any classes or resources that are needed by the library module but are not used by the application module.

In summary, it is possible to Proguard an Android library module without affecting the application module, by configuring the library module's Gradle build file to enable Proguarding and use a separate Proguard configuration file, and by excluding any necessary classes or resources in the application module's Proguard configuration file.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-06-29 11:00:00 +0000

Seen: 13 times

Last updated: Jan 08 '22