Exclude one class file in gradle Android Studio

Viewed 24274

In my projects, I need to import third party jar file and Facebook SDK.

compile files('libs/SkinSDK.jar')
compile 'com.facebook.android:facebook-android-sdk:4.14.0'

Both include same BundleJSONConverter class. So, I cannot do generate signed APK. It always shows duplicate entry com/facebook/internal/BundleJSONConverter.

So, I want to exclude in Facebook or SkinSDK.jar. I tried like

compile ('com.facebook.android:facebook-android-sdk:4.14.0') {
    exclude group: 'com.facebook.internal', module: 'BundleJSONConverter'
}

It's not working and showing same error.

3 Answers

I had a similar problem with duplicated classes after importing a jar. In my case, the conflict was between a class in that jar and a class in my own project. Below I share the solution you can use to discard classes that you have available in your own source tree, assuming the one in the jar is the right one to use:

android {
   sourceSets {
     main {
       java {
            filter.excludes = [
                    "com/package/Duplicated.java",                      
            ]
       }
     }
   }
}
Related