Solution for DuplicateFileException: Duplicate files copied

I got error while using Dagger and Butterknife library at the same time.

Error:Execution failed for task ‘:app:transformResourcesWithMergeJavaResForDebug’.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/services/javax.annotation.processing.Processor
File1: C:\Users\Joe\.gradle\caches\modules-2\files-2.1\com.squareup.dagger\dagger-compiler\1.2.2\fa9b2f9ae597cedf2a66ef3e60662ff36bb60e57\dagger-compiler-1.2.2.jar
File2: C:\Users\Joe\.gradle\caches\modules-2\files-2.1\com.jakewharton\butterknife\6.0.0\3a10b25b6820e19102e118711afe6a66c0bae123\butterknife-6.0.0.jar

In order to solve this problem, put this on gradle.build(app):

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