Search code examples
javaandroidgradleandroid-gradle-plugincouchbase-lite

minifyEnabled for certain package or my files only


I am writing an android project, and trying to compile it for release. In my project i am using 3rd party projects such as couchbase-lite.

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

I want to use minifyEnabled=true in the gradle, but the signed APK fails to run, It appears to be a problem with couchbase using reflection and failing to find one of the properties...

  1. Is there a way to configure gradle to minifyEnabled only on my project files?
  2. Can i configure it to minifyEnabled only certain packages?

Thank you!


Solution

  • You can exclude classes that are using reflection and may cause troubles at run time using -keep rules in Proguard configuration file.

    -keep public class com.example.somepackage.*
    

    Using the rule above, all classes that match public class com.example.somepackage.* are excluded from being minified and obfuscated.