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’.
> 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

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

What happens when screen orientation changed?

I found good piece of information about what happens when screen orientation changes.

Here is a little diagram that shows what happens with different application parts during a configuration change or during an out-of-memory event. Every Android developer should know this data, however this data is surprisingly hard to find.

| Case 1 | Case 2 | Case 3
|A configuration| An activity | A process
| change | restart | restart
—————————————- | ————- | ———— | ————
Dialog | reset | reset | reset
Activity, View, Fragment | save/restore | save/restore | save/restore
Fragment with setRetainInstance(true) | no change | save/restore | save/restore
Static variables and threads | no change | no change | reset
Case 1: A configuration change normally happens when a user flips the screen, changes language settings, attaches an external monitor, etc. More on this event you can read here: configChanges.

Case 2: An Activity restart happens when a user has set “Don’t keep activities” checkbox in Developer’s settings and another activity becomes topmost.

Case 3: A process restart happens if there is not enough memory and the application is in the background.