错误:任务 ':app:dexDebug' 执行失败 [英] Error:Execution failed for task ':app:dexDebug'

查看:42
本文介绍了错误:任务 ':app:dexDebug' 执行失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在 Android Studio for Mac 的模拟器中添加 Google 地图服务.我使用了这个 在我的模拟器中添加 google play 服务,现在我收到此错误.

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

我还在libs"中添加了 Google play jar

I also added Google play jar in "libs"

构建错误

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;
}

推荐答案

此错误通常意味着您已尝试多次将同一类中的链接链接到您的项目,这是不允许的.有问题的类是 com/google/android/gms/actions/ReserveIntents,它位于 Google Play 服务库中.

This error in general means that you've tried to link in the same class to your project more than once, which isn't allowed. The offending class is com/google/android/gms/actions/ReserveIntents, which is in the Google Play Services library.

问题在于您的依赖项:

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

这些都是多余的.play-services:6.5.87 包含所有内容,如果您拥有它,则不需要 play-services-maps:6.5.+ 依赖项.您可能想要后者的原因是,如果您的项目太大,而您需要缩减为更小、更精细的 Play 服务,其中您只包含您需要的内容.

These are redundant. The play-services:6.5.87 includes everything, and if you have that, you don't need the play-services-maps:6.5.+ dependency. The reason you might want the latter one is if your project gets too big and you need to pare down to a smaller, more granular Play Services where you only include what you need.

为了让生活更轻松,我建议使用第一个,如果您遇到编译问题(例如最经典的问题,无法执行 dex:方法 ID 不在 [0, 0xffff] 中:65536,尽管它采用不同的形式), 那么就可以转为后一种格式了.

To make life easier, I'd recommend going with the first one, and if you run into compile problems (such as the most classic one, Unable to execute dex: method ID not in [0, 0xffff]: 65536, though it takes different forms), then you can go to the latter format.

有更多关于如何使用大库和小库的文档http://developer.android.com/google/play-services/setup.htmlhttp://developer.android.com/google/play-services/setup.html#split

这篇关于错误:任务 ':app:dexDebug' 执行失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆