4

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.** {*;}
Pang
  • 9,564
  • 146
  • 81
  • 122
Hitesh Gehlot
  • 1,307
  • 1
  • 15
  • 30
  • 1
    The library knows nothing about its consumers. As far as the library is concerned nobody is using its code so everything is removed by proguard. You have to manually tell proguard not to remove any classes. Only then you can additionally tell it to obfuscate names that are not part of the library's public API. [I've been over this already here.](http://stackoverflow.com/a/42758629/2444099) – Eugen Pechanec May 19 '17 at 12:18
  • @EugenPechanec ohh wow! sounds like good. can you please explain me in detail – Hitesh Gehlot May 19 '17 at 12:21
  • https://www.guardsquare.com/en/proguard/manual/examples#library – Eugen Pechanec May 19 '17 at 12:47
  • Please see this post: [enter link description here](https://stackoverflow.com/a/48636288/8770663) – Masoud Mokhtari Feb 06 '18 at 05:55

2 Answers2

8

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

Masoud Mokhtari
  • 2,390
  • 1
  • 17
  • 45
0

you can write on your proguard file -

-keep public class * extends android.app.Activity 

Or what ever class you want to keep. Have a look on this - https://www.guardsquare.com/en/proguard/manual/examples

Deb S
  • 509
  • 5
  • 16