snowdream snowdream - 1 year ago 295
Android Question

Exclude BuildConfig.class and R.class from Android library jar in Gradle

When building an Android Library Project with Gradle, what's the correct way to exclude BuildConfig.class and R.class from the resulting .jar?

Answer Source

Add a custom task:

task androidReleaseJar(type: Jar, dependsOn: assembleRelease) {
    from "$buildDir/intermediates/classes/release/"
    exclude '**/BuildConfig.class'
    exclude '**/R.class'
    exclude '**/R$*.class'

1. 2. 3.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download