同时引用ButterKnife和Realm编译时可能会出现下述错误:
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\Администратор.gradle\caches\modules-2\files-2.1\com.jakewharton\butterknife\7.0.1\d5d13ea991eab0252e3710e5df3d6a9d4b21d461\butterknife-7.0.1.jar
File2: C:\Users\Администратор.gradle\caches\modules-2\files-2.1\io.realm\realm-android\0.86.0\e49a43bcbbc3d5e5491dd2f4d3799a504b618e6b\realm-android-0.86.0.jar
从stackoverflow看到解决方案,在gradle文件中做如下配置:
packagingOptions {
exclude 'META-INF/services/javax.annotation.processing.Processor'
}
这里记录下,方便大家排查