title: Kotlin,Java,multidex,Dagger 2,Butterknife and Realm: transformClassesWithJarMergingForDebug: duplicate entry: org/jetbrains/annotations/NotNull.class
body: <p>We have existing Java Android code. We want to painlessly slowly start moving to Kotlin. We use Dagger 2, Butterknife and Realm. We use Java 8 compiler (but our <code>targetCompatibility</code> and <code>sourceCompatibility</code> are 1.7).</p>
  <h3>I've been roaming the web for hours, seen SO, GitHub conversations and so on, and managed to solve all problems except one:</h3>
  <p>The build is successful, but when trying to debug, we get:</p>
  <pre><code>Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
  &gt; com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/jetbrains/annotations/NotNull.class
  </code></pre>
  <p>Is there a way to resolve duplicate entries in Gradle (maybe using <code>packagingOptions</code> or <code>resolutionStrategy</code>? as it's a duplication that comes from the plugins...?) ?</p>
  <h3>Again - <code>build project</code> goes without any error, only <code>transformClassesWithJarMergingForDebug</code> fails!</h3>
  <p>Here's the app's gradle:</p>
  <pre><code>apply plugin: 'com.android.application'
  apply plugin: 'kotlin-android'
  //apply plugin: 'com.neenbedankt.android-apt'
  apply plugin: 'realm-android'
  
  kapt { generateStubs = true }
  
  android {
      signingConfigs {
          config {
              keyAlias 'MyAndroidKey'
              keyPassword 'password'
              storeFile file('android.jks')
              storePassword 'password'
          }
      }
      compileSdkVersion 23
      buildToolsVersion '23.0.3'
      defaultConfig {
          vectorDrawables.useSupportLibrary = true
          applicationId &quot;com.acme.app&quot;
          minSdkVersion 15
          targetSdkVersion 23
          versionCode 1
          versionName &quot;1.0&quot;
          //testInstrumentationRunner &quot;android.support.test.runner.AndroidJUnitRunner&quot;
          testInstrumentationRunner &quot;com.acme.app.utils.CustomAndroidJUnitRunner&quot;
  
          // http://stackoverflow.com/a/26515860/587467:
          multiDexEnabled true
      }
      //dexOptions { incremental false }
      buildTypes {
          release {
              minifyEnabled true
              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
              signingConfig signingConfigs.config
          }
      }
      packagingOptions {
          exclude 'META-INF/services/javax.annotation.processing.Processor'
          exclude 'META-INF/DEPENDENCIES.txt'
          exclude 'META-INF/DEPENDENCIES'
          exclude 'META-INF/dependencies.txt'
          exclude 'META-INF/LICENSE.txt'
          exclude 'META-INF/LICENSE'
          exclude 'META-INF/license.txt'
          exclude 'META-INF/LGPL2.1'
          exclude 'META-INF/NOTICE.txt'
          exclude 'META-INF/NOTICE'
          exclude 'META-INF/notice.txt'
      }
  
      configurations.all {
          resolutionStrategy.force 'com.android.support:support-annotations:23.3.0', 'junit:junit:4.12'
      }
  
      targetCompatibility = 1.7
      sourceCompatibility = 1.7
      compileOptions {
          sourceCompatibility JavaVersion.VERSION_1_7
          targetCompatibility JavaVersion.VERSION_1_7
      }
      sourceSets { main.java.srcDirs += 'src/main/kotlin' }
  }
  
  dependencies {
      // http://stackoverflow.com/a/26515860/587467:
      compile 'com.android.support:multidex:1.0.1'
  
      compile fileTree(include: ['*.jar'], dir: 'libs')
  
      /// &lt;Firebase&gt; Cloud Messaging (FCM) - the Google Cloud Messaging (GCM) new version:
      compile 'com.google.firebase:firebase-messaging:9.0.2'
      /// &lt;/Firebase&gt;
  
      /// &lt;Dagger&gt;
      //provided 'javax.annotation:jsr250-api:1.0'
      //apt 'com.google.dagger:dagger-compiler:2.5'
      //compile 'com.google.dagger:dagger:2.5'
      //compile 'com.google.dagger:dagger-compiler:2.4'
      /// &lt;/Dagger&gt;
  
      /// &lt;KotlinDagger&gt;
      compile 'com.google.dagger:dagger:2.5'
      kapt 'com.google.dagger:dagger-compiler:2.5'
      kaptTest 'com.google.dagger:dagger-compiler:2.5'
      kaptAndroidTest 'com.google.dagger:dagger-compiler:2.5'
      //provided 'org.glassfish:javax.annotation:10.0-b28'
      /// &lt;/KotlinDagger&gt;
  
      /// &lt;JSON&gt;
      //testCompile 'javax.json:javax.json-api:1.0'
      testCompile 'org.glassfish:javax.json:1.0.4'
      // https://github.com/FasterXML/jackson-docs/wiki/Using-Jackson2-with-Maven
      // http://www.mkyong.com/java/jackson-2-convert-java-object-to-from-json/
      //testCompile 'com.fasterxml.jackson.core:jackson-core:2.6.3'
      testCompile 'com.fasterxml.jackson.core:jackson-databind:2.7.4'
      /// &lt;/JSON&gt;
  
      //apt 'com.jakewharton:butterknife-compiler:8.0.1'
      kapt 'com.jakewharton:butterknife-compiler:8.0.1'
  
      testCompile 'junit:junit:4.12'
      testCompile 'org.mockito:mockito-core:1.10.19'
      testCompile 'net.java.dev.jna:jna-platform:4.2.2'
  
      // &lt;InstrumentedTests&gt;
      // &lt;MutualExclusive&gt;
      // &lt;Or&gt;
            //androidTestCompile 'com.android.support.test:testing-support-lib:0.1'
      // &lt;/Or&gt;
      // &lt;Or&gt;
      //    androidTestCompile 'com.android.support:support-annotations:23.0.0'
          androidTestCompile 'com.android.support.test:runner:0.4'
          //androidTestCompile 'com.android.support.test:rules:0.4'
          // &lt;Espresso&gt;
          androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
          // &lt;/Espresso&gt;
          //androidTestCompile &quot;org.robolectric:robolectric:3.0&quot;
      // &lt;/Or&gt;
      // &lt;/MutualExclusive&gt;
      // &lt;/InstrumentedTests&gt;
  
      compile 'com.android.support:appcompat-v7:23.4.0'
      compile 'com.android.support:support-v13:23.4.0'
      compile 'com.android.support:design:23.4.0'
      compile 'com.jakewharton:butterknife:8.0.1'
      compile 'com.google.code.ksoap2-android:ksoap2-android:3.6.1'
      compile 'org.springframework.android:spring-android-rest-template:2.0.0.M3'
  
      compile 'com.squareup.retrofit2:retrofit:2.1.0'
      compile 'com.squareup.retrofit2:converter-gson:2.1.0'
      compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
  
      compile 'com.android.support:support-v4:23.3.0'
      compile 'com.android.support:recyclerview-v7:23.3.0'
      compile 'com.android.support:cardview-v7:23.3.0'
      compile 'io.reactivex:rxandroid:1.2.1'
      compile 'joda-time:joda-time:2.9.4'
      //compile 'io.reactivex:rxjava:1.1.6'
      compile 'io.reactivex:rxjava-async-util:0.21.0'
      //&lt;Floating Buttons&gt;
      compile 'com.github.clans:fab:1.6.4'
      //&lt;/Floating Buttons&gt;
  
      compile 'com.facebook.fresco:fresco:0.11.0'
      compile 'org.jetbrains:annotations-java5:15.0'
      compile 'com.fasterxml.jackson.core:jackson-databind:2.7.4'
      compile 'com.google.code.gson:gson:2.4'
      compile 'javax.annotation:javax.annotation-api:1.2'
      compile &quot;org.jetbrains.kotlin:kotlin-stdlib:1.0.3&quot;
  }
  
  // https://firebase.google.com/docs/android/setup#add_the_sdk
  // Firebase Cloud Messaging (FCM) - the Google Cloud Messaging (GCM) new version:
  apply plugin: 'com.google.gms.google-services'
  repositories {
      mavenCentral()
  }
  </code></pre>