title: Duplicate classes in same jars of different versions - Android
body: <p>I was trying to integrate iText in my Android Studio project when the sync successfully completed.<br />
  Then I wrote some code and tried to build and test it when it gave an error (A huge one) that duplicate classes were found in same jars of different versions. (I have removed some because there were a lot)</p>
  <pre><code>Duplicate class com.keypoint.PngEncoder found in modules jcommon-1.0.15.jar (jfree:jcommon:1.0.15) and jcommon-1.0.17.jar (org.jfree:jcommon:1.0.17)
  Duplicate class org.jfree.JCommon found in modules jcommon-1.0.15.jar (jfree:jcommon:1.0.15) and jcommon-1.0.17.jar (org.jfree:jcommon:1.0.17)
  Duplicate class org.jfree.JCommonInfo found in modules jcommon-1.0.15.jar (jfree:jcommon:1.0.15) and jcommon-1.0.17.jar (org.jfree:jcommon:1.0.17)
  Duplicate class org.jfree.base.AbstractBoot found in modules jcommon-1.0.15.jar (jfree:jcommon:1.0.15) and jcommon-1.0.17.jar (org.jfree:jcommon:1.0.17)
  Duplicate class org.jfree.base.BaseBoot found in modules jcommon-1.0.15.jar (jfree:jcommon:1.0.15) and jcommon-1.0.17.jar (org.jfree:jcommon:1.0.17)
  Duplicate class org.jfree.base.BasicProjectInfo found in modules jcommon-1.0.15.jar (jfree:jcommon:1.0.15) and jcommon-1.0.17.jar (org.jfree:jcommon:1.0.17)
  ...
  Duplicate class org.jfree.base.BasicProjectInfo$OptionalLibraryHolder found in modules jcommon-1.0.15.jar (jfree:jcommon:1.0.15) and jcommon-1.0.17.jar (org.jfree:jcommon:1.0.17)
  Duplicate class org.jfree.base.BootableProjectInfo found in modules jcommon-1.0.15.jar (jfree:jcommon:1.0.15) and jcommon-1.0.17.jar (org.jfree:jcommon:1.0.17)
  jcommon-1.0.17.jar (org.jfree:jcommon:1.0.17)
  Duplicate class org.jfree.util.WaitingImageObserver found in modules jcommon-1.0.15.jar (jfree:jcommon:1.0.15) and jcommon-1.0.17.jar (org.jfree:jcommon:1.0.17)
  
  Go to the documentation to learn how to Fix dependency resolution errors.
  
  </code></pre>
  <p>From this I Understand that the different versions of the same jar caused this issue. So I tried to remove the one with lower version (jcommon-1.0.15 and 1 more ) but when i synced the project with gradle, it again downloaded them and if i ran it offline it said that dependencies couldn't be resolved. Similar is the case with the jars of higher version.</p>
  <p><strong>Update:</strong>
  Here are my <code>build.gradle</code> files as requested:
  Project level:</p>
  <pre><code>// Top-level build file where you can add configuration options common to all sub-projects/modules.
  
  buildscript {
      repositories {
          google()
          jcenter()
          
      }
      dependencies {
          classpath 'com.android.tools.build:gradle:3.5.3'
  
          // NOTE: Do not place your application dependencies here; they belong
          // in the individual module build.gradle files
      }
  }
  
  allprojects {
      repositories {
          google()
          jcenter()
          maven { url 'https://jitpack.io' }
      }
  }
  
  task clean(type: Delete) {
      delete rootProject.buildDir
  }
  
  </code></pre>
  <p>App level:</p>
  <pre><code>apply plugin: 'com.android.application'
  
  android {
      compileSdkVersion 29
      buildToolsVersion &quot;29.0.2&quot;
      defaultConfig {
          applicationId &quot;com.nalin.app&quot;
          minSdkVersion 19
          targetSdkVersion 29
          versionCode 1
          versionName &quot;1.0&quot;
          testInstrumentationRunner &quot;androidx.test.runner.AndroidJUnitRunner&quot;
      }
      buildTypes {
          release {
              minifyEnabled false
              proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
          }
      }
  }
  
  dependencies {
      implementation fileTree(dir: 'libs', include: ['*.jar'])
      implementation 'androidx.appcompat:appcompat:1.2.0'
      implementation 'androidx.activity:activity:1.1.0'
      implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
      implementation 'com.google.android.material:material:1.2.0'
      testImplementation 'junit:junit:4.12'
      androidTestImplementation 'androidx.test.ext:junit:1.1.1'
      androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
      implementation project(path: ':libraries:OpenCV')
      implementation 'itext:itext:4.2.1'
  }
  
  </code></pre>
  <p>I Also have included OpenCV so here is the gradle file for OpenCV:</p>
  <pre><code>apply plugin: 'com.android.library'
  
  buildscript {
      repositories {
          mavenCentral()
          jcenter()
          google()
      }
      dependencies {
          classpath 'com.android.tools.build:gradle:3.5.3'
      }
  }
  
  android {
      compileSdkVersion 29
      buildToolsVersion &quot;29.0.2&quot;
  
      defaultConfig {
          minSdkVersion 19
          targetSdkVersion 29
          versionCode 2480
          versionName &quot;2.4.8&quot;
      }
  
      sourceSets {
          main {
              manifest.srcFile 'AndroidManifest.xml'
              java.srcDirs = ['src']
              resources.srcDirs = ['src']
              res.srcDirs = ['res']
              aidl.srcDirs = ['src']
          }
      }
  }
  </code></pre>