我试图在Android Studio for Mac中的模拟器中添加Google地图服务。 我使用 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>
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;
}
答案 0 :(得分:5)
此错误通常意味着您已尝试多次将同一班级链接到您的项目,这是不允许的。违规类为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使用大型图书馆和较小图书馆的更多文档
答案 1 :(得分:1)
似乎你有一个jar文件或lib多次出现。因此,从lib文件夹Build&gt;中删除.jar文件。重建必须工作。