Error: Execution failed for task ': app: dexDebug'

I was trying to add google maps service to emulator in Android Studio for Mac. I used this to add google play services to my emulator and now I am getting this error.

I also added google play banner to "libs"

Build error

Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
            /Applications/Android Studio.app/sdk/build-tools/21.0.0/dx --dex --num-threads=4 --output /Users/BrijD/Desktop/Final_maps/app/build/intermediates/dex/debug /Users/BrijD/Desktop/Final_maps/app/build/intermediates/classes/debug /Users/BrijD/Desktop/Final_maps/app/build/intermediates/dependency-cache/debug /Users/BrijD/Desktop/Final_maps/app/build/intermediates/pre-dexed/debug/classes-0fd5fdfe526893278be8c195ce134eaf1d9f1e86.jar /Users/BrijD/Desktop/Final_maps/app/build/intermediates/pre-dexed/debug/classes-1c1ab6ce82c35aba8a1d88f2624cf1338444a247.jar /Users/BrijD/Desktop/Final_maps/app/build/intermediates/pre-dexed/debug/classes-3fa4a9ac8fa2216bad3a7f16c9a774b0dc355d43.jar /Users/BrijD/Desktop/Final_maps/app/build/intermediates/pre-dexed/debug/classes-8f6dc1447c1249308d36a8f93d1adf33837f8664.jar /Users/BrijD/Desktop/Final_maps/app/build/intermediates/pre-dexed/debug/internal_impl-21.0.0-fd4beb3682904051af27f723f6ba9423e4f00b8a.jar /Users/BrijD/Desktop/Final_maps/app/build/intermediates/pre-dexed/debug/support-annotations-21.0.0-ee576f91b45a6538d4156fc6e674b6f65034f74e.jar
          Error Code:
            2
          Output:
            UNEXPECTED TOP-LEVEL EXCEPTION:
            com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/actions/ReserveIntents;
                at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
                at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
                at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
                at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
                at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
                at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
                at com.android.dx.command.dexer.Main.runMonoDex(Main.java:302)
                at com.android.dx.command.dexer.Main.run(Main.java:245)
                at com.android.dx.command.dexer.Main.main(Main.java:214)
                at com.android.dx.command.Main.main(Main.java:106)

      

AndroidMainefest.xml

<?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="dormroomdevelopers.final_maps" >

        <uses-permission android:name="android.permission.INTERNET"/>
        <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <activity
                android:name=".MyActivity"
                android:label="@string/app_name" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />

                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
            <activity android:name=".MapsActivity">
                <meta-data
                    android:name="com.google.android.maps.v2.API_KEY"
                    android:value="*****************************"/>
            </activity>
            <meta-data android:name="com.google.android.gms.version"
                android:value="@integer/google_play_services_version" />
        </application>

    </manifest>

      

app build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21"

    defaultConfig {
        applicationId "dormroomdevelopers.final_maps"
        minSdkVersion 18
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.google.android.gms:play-services:6.5.87'
    compile 'com.google.android.gms:play-services-maps:6.5.+'
}

      

proguard-rules.pro

-keep class * extends java.util.ListResourceBundle {
    protected Object[][] getContents();
}

-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
    public static final *** NULL;
}

-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
    @com.google.android.gms.common.annotation.KeepName *;
}

-keepnames class * implements android.os.Parcelable {
    public static final ** CREATOR;
}

      

+3


source to share


2 answers


This error generally means that you have tried to bind the same class to your project more than once, which is prohibited. The offending class com/google/android/gms/actions/ReserveIntents

that is in the Google Play Services library.

The problem is in your dependencies:

compile 'com.google.android.gms:play-services:6.5.87'
compile 'com.google.android.gms:play-services-maps:6.5.+'

      



This is redundant. play-services:6.5.87

includes everything and if you have it you don't need the addiction play-services-maps:6.5.+

. The reason you might want the latter is because your project is getting too big and you need to collapse into smaller and more literate Replay Services where you only include what you need.

To make life easier, I recommend going to the first one, and if you have any problems with compilation (for example, the most classic ones, It is not possible to execute the dex: method method identifier not in [0, 0xffff]: 65536 , although it takes different forms), then you you can go to the latest format.

There's more documentation on how to use large library and smaller libraries at http://developer.android.com/google/play-services/setup.html and http://developer.android.com/google/play-services /setup.html#split

+5


source


You seem to have a jar or lib file showing up multiple times. So remove the .jar file from lib folder Build> Rebuild Must work.



+1


source







All Articles