android-studiogradleandroid-gradle-pluginproguardminify

How to EXCLUDE an external library jar from Proguard in Android Studio?


The build.gradle of one of the modules in my project is pretty simple:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 8
    buildToolsVersion "21.1.2"

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 8
    }

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

dependencies {
    compile project(':timsvc')
    compile files('libs/jsoup-1.8.2.jar')
}

However, when I build it, it fails to find symbols in the external library jsoup-1.8.2.jar.

Since timsvc is a module of mine, having its own build.gradle and proguard.cfg, I can control its minify level, and so I don't have any problems with it.

But I cannot do the same for jsoup-1.8.2.jar because it is an externally provided jar.

Is there a way to exclude it from Proguard in Android Studio?

If so, how do I accomplish that?


Solution

  • The best is to consult with the library documentation and README pages (like on Github).

    But in genneral you can add -keep option to your ProGuard configuration file "proguard-rules.pro" for the classes in those external jars. For instance:

    -keep class example.** { *; }