How to use ProGuard in Library Module

Viewed 4860

I want to enable ProGuard in library module but getting compilation error that package does not exists. Why package not exists after apply ProGuard in library module?

library module build.gradle

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

Log Error

 /home/hitesh/Documents/Android Studio Project/ALPR-Sample/app/src/main/java/com/alpr/sample/GalleryActivity.java
Error:(15, 32) error: package com.alprlib.alpr.doc does not exist
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

here doc class file exist in library module

ProGuard file rules

-keep class com.alprlib.alpr.** { *; }
-keepclassmembers class alprlib.alpr.** {*;}
2 Answers

It makes sense to me to specify proguard settings for a library (like which library files shouldn't be obfuscated) in the library project. I've found that I also need to include proguard configurations from my library modules in my application. To do this, I added the following to the defaultConfig section in my library's build.gradle

consumerProguardFiles 'proguard-rules.pro'

and then configured the proguard-rules.pro file in my library module to keep the names of important serialized classes.

See also consumerProguardFiles

Please see this post: https://stackoverflow.com/a/48636288/8770663

Related