gpt4 book ai didi

debugging - 错误 :Execution failed for task ':app:dexDebug'

转载 作者:行者123 更新时间:2023-12-03 17:09:18 28 4
gpt4 key购买 nike

我试图在 Android Studio for Mac 的模拟器中添加谷歌地图服务。我用了 this 在我的模拟器中添加 google play 服务,现在我收到此错误。

我还在“libs”中添加了 Google play jar

构建错误

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>

应用构建.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 服务库中。

问题出在您的依赖项中:

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 服务,其中您只包含您需要的内容。

为了让生活更轻松,我建议使用第一个,如果遇到编译问题(例如最经典的 Unable to execute dex: method ID not in [0, 0xffff]: 65536 ,尽管它有不同的形式),那么您可以转到后一种格式。

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

关于debugging - 错误 :Execution failed for task ':app:dexDebug' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27561153/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com