我正在处理名为Google地方信息和地图的项目,该项目显示了当前位置和附近的地点。 我添加了四个jar文件: -
1.android-google-maps-api11.jar
2.google-api-client-1.10.3-beta.jar
3.google-http-client-1.10.3-beta.jar
4.google-play-services.jar
它在build-gradle期间工作正常,但在运行项目时抛出异常 这就是我得到的
Information:Gradle tasks [:app:assembleDebug]
:app:preBuild
:app:compileDebugNdk UP-TO-DATE
:app:preDebugBuild
:app:checkDebugManifest
:app:preReleaseBuild
:app:prepareComAndroidSupportAppcompatV72103Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42103Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServices6587Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:compileDebugJava UP-TO-DATE
:app:preDexDebug
:app:dexDebug
UNEXPECTED TOP-LEVEL EXCEPTION:
Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
C:\Users\abhi\AppData\Local\Android\sdk\build-tools\21.1.2\dx.bat --dex -- no-optimize --output C:\android\sdk\extras\google\m2repository\com\google\android\PlacesandMaps\app\b uild\intermediates\dex\debug --input- list=C:\android\sdk\extras\google\m2repository\com\google\android\PlacesandMaps\ app\build\intermediates\tmp\dex\debug\inputList.txt
Error Code:
2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lcom/google/ads/AdRequest$ErrorCode;
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:303)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)
Information:BUILD FAILED
Information:Total time: 1 mins 25.598 secs
Information:1 error
Information:0 warnings
Information:See complete output in console
这是我的Build.gradle,其中有依赖项
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.abhi.placesandmaps"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard- rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.android.gms:play-services:6.5.87'
compile files('libs/google-api-client-1.10.3-beta.jar')
compile files('libs/google-http-client-1.10.3-beta.jar')
compile files('libs/android-google-maps-api11.jar')
compile files('libs/google-play-services.jar')
}
答案 0 :(得分:1)
不要使用来自Google的jar文件。使用新的aar文件。这是错误:
compile 'com.google.android.gms:play-services:6.5.87'
compile files('libs/google-play-services.jar')
在那里你包括播放服务两次删除jar行。
依赖项中的第一行(compile fileTree(include: ['*.jar'], dir: 'libs')
)将第二次包含jar,因此也要从libs目录中删除jar文件。
一般来说,我不确定其他罐子的作用,但我猜他们是游戏服务的一部分。