错误:执行失败的任务“:应用程序:dexDebug” [英] Error:Execution failed for task ':app:dexDebug'

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

问题描述

我是想在Android的Studio插件谷歌地图服务在仿真器为Mac。
我用的 添加谷歌在我的模拟器中播放服务,现在我收到此错误。

我还添加了谷歌在库

玩罐子

生成错误

 错误:执行失败的任务:应用程序:dexDebug。
> com.android.ide.common.internal.LoggedErrorException:无法运行命令:
            /应用/ Android的Studio.app/sdk/build-tools/21.0.0/dx --dex --num线程= 4 - 输出/用户/ BrijD /桌面/ Final_maps /应用程序/编译/中间体/ DEX /调试/用户/ BrijD /桌面/ Final_maps /应用程序/编译/中间体/班/调试/用户/ BrijD /桌面/ Final_maps /应用程序/编译/中间体/依赖缓存/调试/Users/BrijD/Desktop/Final_maps/app/build/intermediates/$p$p-dexed/debug/classes-0fd5fdfe526893278be8c195ce134eaf1d9f1e86.jar /Users/BrijD/Desktop/Final_maps/app/build/intermediates/$p$p-dexed/debug/classes-1c1ab6ce82c35aba8a1d88f2624cf1338444a247.jar /Users/BrijD/Desktop/Final_maps/app/build/intermediates/$p$p-dexed/debug/classes-3fa4a9ac8fa2216bad3a7f16c9a774b0dc355d43.jar /Users/BrijD/Desktop/Final_maps/app/build/intermediates/$p$p-dexed/debug/classes-8f6dc1447c1249308d36a8f93d1adf33837f8664.jar /Users/BrijD/Desktop/Final_maps/app/build/intermediates/$p$p-dexed/debug/internal_impl-21.0.0-fd4beb3682904051af27f723f6ba9423e4f00b8a.jar /Users/BrijD/Desktop/Final_maps/app/build/intermediates/$p$p-dexed/debug/support-annotations-21.0.0-ee576f91b45a6538d4156fc6e674b6f65034f74e.jar
          错误code:
            2
          输出:
            意外的顶级例外:
            com.android.dex.DexException:多DEX文件定义LCOM /谷歌/安卓/ GMS /动作/ ReserveIntents;
                在com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
                在com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
                在com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
                在com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
                在com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
                在com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
                在com.android.dx.command.dexer.Main.runMonoDex(Main.java:302)
                在com.android.dx.command.dexer.Main.run(Main.java:245)
                在com.android.dx.command.dexer.Main.main(Main.java:214)
                在com.android.dx.command.Main.main(Main.java:106)

AndroidMainefest.xml

 <?XML版本=1.0编码=UTF-8&GT?;
    <清单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
        包=dormroomdevelopers.final_maps>        <使用许可权的android:NAME =android.permission.INTERNET对/>
        <应用
            机器人:allowBackup =真
            机器人:图标=@绘制/ ic_launcher
            机器人:标签=@字符串/ APP_NAME
            机器人:主题=@风格/ AppTheme>
            <活动
                机器人:MyActivityNAME =
                机器人:标签=@字符串/ APP_NAME>
                &所述;意图滤光器>
                    <作用机器人:名字=android.intent.action.MAIN/>                    <类机器人:名字=android.intent.category.LAUNCHER/>
                &所述; /意图滤光器>
            < /活性GT;
            <活动机器人:名字=。MapsActivity>
                &所述;元数据
                    机器人:名字=com.google.android.maps.v2.API_KEY
                    机器人:值=****/>
            < /活性GT;
            <元数据机器人:名字=com.google.android.gms.version
                机器人:值=@整数/ GOOGLE_PLAY_SERVICES_VERSION/>
        < /用途>    < /清单>

应用的build.gradle

 应用插件:'com.android.application安卓{
    compileSdkVersion 21
    buildToolsVersion21    defaultConfig {
        的applicationIDdormroomdevelopers.final_maps
        18的minSdkVersion
        targetSdkVersion 21
        版本code 1
        的versionName1.0
    }
    buildTypes {
        发布 {
            runProguard假
            proguardFiles getDefaultProguardFile('proguard的-android.txt'),'proguard-rules.pro
        }
    }
}
依赖{
    编译文件树(导演:'库',包括:['的* .jar'])
    编译com.google.android.gms:游戏服务:87年6月5日
    编译com.google.android.gms:播放服务,地图:6.5 +。
}

proguard-rules.pro

  -keep类*宽java.util.ListResourceBundle {
    保护对象[] [] getContents();
}-keep公共类com.google.android.gms.common.internal.safeparcel.SafeParcelable {
    公共静态最终*** NULL;
}-keepnames @ com.google.android.gms.common.annotation.KeepName类*
-keepclassmembernames类* {
    @ * com.google.android.gms.common.annotation.KeepName;
}-keepnames类*实现android.os.Parcelable {
    公共静态最后的** CREATOR;
}


解决方案

这个错误在你已经尝试在同一类链接到你的项目超过一次,这是不允许的常规方法。违规类是 COM /谷歌/安卓/ GMS /动作/ ReserveIntents ,这是在谷歌Play服务库。

问题出在你的依赖:

 编译com.google.android.gms:发挥服务:87年6月5日
编译com.google.android.gms:播放服务,地图:6.5 +。

这是多余的。在播放服务:87年6月5日包括一切,如果你有,你不需要播放服务,地图:6.5。 + 依赖。究其原因,你可能需要后者是如果你的项目变得太大,你需要向下削减到更小,更精细的游戏服务,你只包含你所需要的。

为使生活更轻松,我建议你用第一个去,如果您遇到编译问题(如最经典的,<一个href=\"http://stackoverflow.com/questions/15209831/unable-to-execute-dex-method-id-not-in-0-0xffff-65536\">Unable执行DEX:不能在[0,0xFFFF的]方法ID:65536 ,尽管它不同的形式),那么你可以去后者格式

有一个关于如何使用大库的详细资料,并在<一个较小的库href=\"http://developer.android.com/google/play-services/setup.html\">http://developer.android.com/google/play-services/setup.html和<一个href=\"http://developer.android.com/google/play-services/setup.html#split\">http://developer.android.com/google/play-services/setup.html#split

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.

I also added Google play jar in "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;
}

解决方案

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.

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.+'

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.

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.

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

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

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