snowdream snowdream - 1 year ago 321
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'
}

Reference:
1.https://github.com/facebook/rebound/blob/master/build.gradle 2.https://github.com/keyboardsurfer/Crouton/blob/master/library/build.gradle 3.https://github.com/SnowdreamFramework/android-log/commit/4297a0244c972e3fcb9042b5e12181b21c33b524

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