gradle exclude group from compile

10,080

Looks like the exclude block syntax is incorrect. Try

compile ('com.ironsource.adapters:facebookadapter:4.0.3@jar') {
  exclude group: 'com.facebook.ads'
}

Update

So it looks like the facebookadapter contains this class inside. You can not exclude a class from a jar file, exclusion only works on per-dependency level.

If you absolutely need to have this adapter, you can try to exclude facebook ads transitive dependency from all the other dependencies.

configurations {
    all*.exclude group: 'com.facebook.ads'
}
Share:
10,080
Michael A
Author by

Michael A

Updated on June 09, 2022

Comments

  • Michael A
    Michael A almost 2 years

    I am getting this duplicate error when building my app:

    addJar(...facebookadapter-4.0.3.jar): entry
    duplicate entry: com/facebook/ads/AbstractAdListener.class

    The reason I am getting this is that my app compiles Facebook modules one belongs to an adapter and one to its original SDK:

    compile ('com.ironsource.adapters:facebookadapter:4.0.3@jar') compile 'com.facebook.android:audience-network-sdk:4.27.0' compile 'com.google.ads.mediation:facebook:4.27.0.0'

    So as a solution, I am trying to exclude this group from the module which contains the adapter jar compile statement:

    compile ('com.ironsource.adapters:facebookadapter:4.0.3@jar') {
        exclude (group: 'com/facebook/ads')
    }
    

    But, when I build my app again it fails to state the same reason from the same adapter

    Any idea why the classes are not being excluded?

    • Nikita Skvortsov
      Nikita Skvortsov over 6 years
      use gradlew :app:dependencyInsight --configuration compile --dependency com.facebook.ads to check where the dependency comes from
  • Michael A
    Michael A over 6 years
    That was my first try, both syntaxes give the same result
  • Nikita Skvortsov
    Nikita Skvortsov over 6 years
    oh, so the class is inside the jar. That makes problem tricker, please see my update
  • Michael A
    Michael A over 6 years
    Thanks, can you please elaborate on this line "You can not exclude a class from a jar file, exclusion only works on per-dependency level"
  • Nikita Skvortsov
    Nikita Skvortsov over 6 years
    Each dependecy declaration in Gradle defines a subtree:not only the actual library (a single jar file), but all the dependencies of this library as well (transitive dependencies, multiple jar files). The exclude directive allows you to exclude some of transitive dependencies (exclude several jar files). In case of com.ironsource.adapters:facebookadapter:4.0.3@jar the com/facebook/ads/AbstractAdListener.class is a part of library, not a transitive dependency, you can not exclude it this way