同时使用parceler/butterknife/dagger2出现DuplicateFileException的解决方法

  同时使用parceler、butterknife和dagger2这几个库时,可能是因为都用到了annotation,gradle报错:

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\xxx\.gradle\caches\modules-2\files-2.1\org.parceler\parceler\0.2.16\37438b5c380d8eb22bd3ae616077561b7f906ff3\parceler-0.2.16.jar
	File2: C:\Users\xxx\.gradle\caches\modules-2\files-2.1\com.jakewharton\butterknife\7.0.1\d5d13ea991eab0252e3710e5df3d6a9d4b21d461\butterknife-7.0.1.jar

  解决方法为,在build.gradle中加入packagingOptions排除annotation,annotation不需要被打包进APK:
android {
    ...
    packagingOptions {
        exclude 'META-INF/services/javax.annotation.processing.Processor'
    }
}