Is it possible to Proguard an Android library module, but not the application module?

679 views
Skip to first unread message

David

unread,
Aug 25, 2015, 4:41:07 PM8/25/15
to adt-dev

I'm hoping somebody can answer what I think is a basic Gradle/Proguard question.


I have a very basic Android project. This project contains the main app module, named app, and a library module for the Android Support libraries, named AndroidSupport.


I wish to run Proguard exclusively on AndroidSupport (i.e. NOT on the overall application) because I'm having trouble running instrumentation tests on the application when it is Proguard-ed. My hope is that I can minify AndroidSupport on its own so that I don't need to Proguard my application code (and thus, avoid the problem of tests not running).


Here's my app build.gradle. Note that Proguard is DISABLED:


apply plugin: 'com.android.application'
android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"
    defaultConfig {
        applicationId "com.example.androidsupportlibproject"
        minSdkVersion 9
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        debug {
            minifyEnabled false //Proguard DISABLED
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile project(':AndroidSupport')
}

My AndroidSupport module has Proguard ENABLED:

apply plugin: 'com.android.library'
android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"
    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 22
    }
    buildTypes {
        release {
            minifyEnabled true  //Proguard ENABLED
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:support-v4:22.2.0'
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.android.support:recyclerview-v7:22.2.0'
    compile 'com.android.support:support-annotations:22.2.0'
}

My AndroidSupport module's proguard-rules.pro looks like:

-dontobfuscate
-keep class android.support.v4.** { *; }
-keep interface android.support.v4.app.** { *; }

When the app application has Proguard enabled and AndroidSupport has Proguard disabled, I can use consumerProguardFiles proguard-rules.pro to minify AndroidSupport.


But when I use the above pasted configuration, I get the following error:

Error:Execution failed for task ':AndroidSupport:proguardRelease'.
java.io.IOException: The output jar is empty. Did you specify the proper '-keep' options?`


Does anyone know if this set up is possible? To enable Proguard ONLY on a dependent library module, but not on the application itself?


Thanks in advance!

Reply all
Reply to author
Forward
0 new messages