Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 662
ususer Avatar asked Apr 26 '15 13:04

ususer


1 Answers

The best is to see the libraries documentations and readme page (like Github).

but in genneral you can add -keep options to your proguard configuration file for the classes in those external jars. For instance:

-keep class example.** { *; }
like image 83
Shayan Amani Avatar answered Oct 18 '22 21:10

Shayan Amani