In Android Studio grade, duplicate entry: com/google/android/gms/ads/AdActivity.class
<p>I am developing Android app with Android Studio.</p>

<p>I am using google-play-services, however when I run my App in my Android device I encounter the following error.</p>

<p><strong><em>build.gradle</em></strong></p>

<pre><code>android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "net.myApp"
        minSdkVersion 14
        targetSdkVersion 21

        multiDexEnabled true
    }

    packagingOptions{
        exclude 'com/google/android/gms/ads/AdActivity'
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile project(':facebookSDK')
    compile 'com.jpardogo.materialtabstrip:library:1.1.0'
    compile 'com.android.support:support-v4:23.4.0'
    compile 'joda-time:joda-time:2.1'
    compile files('libs/google-play-services.jar')
    compile files('libs/twitter4j-core-4.0.2.jar')

    android {
        useLibrary 'org.apache.http.legacy'
    }
}
</code></pre>

<p><strong><em>error</em></strong></p>

<pre><code>FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':myApp:transformClassesWithJarMergingForDebug'.
&gt; com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/ads/AdActivity.class

* Try:
Run with --info or --debug option to get more log output.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':myApp:transformClassesWithJarMergingForDebug'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
    at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:203)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:185)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:66)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:50)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
    at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
Caused by: java.lang.RuntimeException: com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/ads/AdActivity.class
    at com.android.builder.profile.Recorder$Block.handleException(Recorder.java:54)
    at com.android.builder.profile.ThreadRecorder$1.record(ThreadRecorder.java:57)
    at com.android.builder.profile.ThreadRecorder$1.record(ThreadRecorder.java:47)
    at com.android.build.gradle.internal.pipeline.TransformTask.transform(TransformTask.java:173)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:75)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.doExecute(AnnotationProcessingTaskFactory.java:244)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:220)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.execute(AnnotationProcessingTaskFactory.java:231)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:209)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
    ... 14 more
Caused by: com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/ads/AdActivity.class
    at com.android.build.gradle.internal.transforms.JarMergingTransform.transform(JarMergingTransform.java:117)
    at com.android.build.gradle.internal.pipeline.TransformTask$3.call(TransformTask.java:178)
    at com.android.build.gradle.internal.pipeline.TransformTask$3.call(TransformTask.java:174)
    at com.android.builder.profile.ThreadRecorder$1.record(ThreadRecorder.java:55)
    ... 23 more
Caused by: java.util.zip.ZipException: duplicate entry: com/google/android/gms/ads/AdActivity.class
    at com.android.build.gradle.internal.transforms.JarMerger.addJar(JarMerger.java:161)
    at com.android.build.gradle.internal.transforms.JarMerger.addJar(JarMerger.java:121)
    at com.android.build.gradle.internal.transforms.JarMergingTransform.transform(JarMergingTransform.java:107)
    ... 26 more
    enter code here
</code></pre>

<p>I have no idea why com/google/android/gms/ads/AdActivity.class is duplicated.</p>

<p>Could you tell me how to solve this problem?</p>