Duplicate files while including butterknife with gradle

That's because you wrote compile for dagger-compiler, replace it with provided and the issue will be fixed.

compile 'com.squareup.dagger:dagger:1.2.1'
provided 'com.squareup.dagger:dagger-compiler:1.2.1'

Later versions of the plugin will tell you how to fix this. I think we introduced the fix in 0.8 so you should probably upgrade. Then the fix is to put this in your build.gradle

android {
    packagingOptions {
        exclude 'META-INF/services/javax.annotation.processing.Processor'
    }
}

This will exclude this file from the packaging which is fine since it's not actually needed in the APK.


If after applying above given solutions you still face the same issue as I was, then if you are using glide library then change the version of the glide to it's max. eg.

implementation 'com.github.bumptech.glide:glide:4.10.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0'

The best option in version >= 0.9.1 of Gradle build tools is probably:

android {
    packagingOptions {
        pickFirst 'META-INF/services/javax.annotation.processing.Processor'
    }
}

For more, see the Android Tools Project page: New Build System.

Edit: One last note here if you start having problems with generated code, make sure to structure your dependencies properly. I ended up removing any exclusion of the Processor line and structuring my annotation processed dependencies like:

compile "org.parceler:parceler-api:0.2.15"
apt "org.parceler:parceler:0.2.15"

and

provided 'com.squareup.dagger:dagger-compiler:1.2.2'
apt 'com.squareup.dagger:dagger-compiler:1.2.2'