0

There are my actions: 1) Add file google-play-services.jar from sdk directory in "libs" directory in my project. 2) Add dependency "compile files('libs/google-play-services.jar')" in build.gradle in my project (not in solution). Sync Project is complete succesfully, but after running application i see that error:

Execution failed for task ':TestMcSiRun:dexDebug'.

com.android.ide.common.internal.LoggedErrorException: Failed to run command: D:\SDK\sdk\sdk\build-tools\19.0.2\dx.bat --dex --output C:\Users\MCSIMUSIC\AndroidStudioProjects\TestMcSiRun\TestMcSiRun\build\dex\debug C:\Users\MCSIMUSIC\AndroidStudioProjects\TestMcSiRun\TestMcSiRun\build\classes\debug C:\Users\MCSIMUSIC\AndroidStudioProjects\TestMcSiRun\TestMcSiRun\build\dependency-cache\debug C:\Users\MCSIMUSIC\AndroidStudioProjects\TestMcSiRun\TestMcSiRun\build\pre-dexed\debug\classes-2b5c8c8b2a23992eb9323b131861658b5a6c4592.jar C:\Users\MCSIMUSIC\AndroidStudioProjects\TestMcSiRun\TestMcSiRun\build\pre-dexed\debug\classes-442363482f1c8783c26a5e38b6ee593d3f54a067.jar C:\Users\MCSIMUSIC\AndroidStudioProjects\TestMcSiRun\TestMcSiRun\build\pre-dexed\debug\google-play-services-da249c1d3c777ecbc074adaa5e3cd781485d270c.jar C:\Users\MCSIMUSIC\AndroidStudioProjects\TestMcSiRun\TestMcSiRun\build\pre-dexed\debug\support-v4-18.0.0-00a4eeb2a43f491f4d8b1d7286b2ebe4b40b994e.jar 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:594) at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552) at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:533) at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:170) at com.android.dx.merge.DexMerger.merge(DexMerger.java:188) at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439) at com.android.dx.command.dexer.Main.runMonoDex(Main.java:287) at com.android.dx.command.dexer.Main.run(Main.java:230) at com.android.dx.command.dexer.Main.main(Main.java:199) at com.android.dx.command.Main.main(Main.java:103)

What do I do wrong? my build.gradle:

apply plugin: 'android'


android {
    compileSdkVersion 18
    buildToolsVersion '19.0.2'

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 15
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'),
            'proguard-rules.txt'
        }
    }
}
dependencies {
    compile 'com.android.support:appcompat-v7:18.0.+'
    compile 'com.google.android.gms:play-services:4.0.30'
    //compile files('libs/google-play-services.jar')
}
  • You've included two libraries that have com.google.ads.AdRequest. Please add your build.gradle file to your question. Also, see http://stackoverflow.com/questions/22262344/error-package-com-google-android-gms-doesnt-exist – Scott Barta Mar 07 '14 at 23:32
  • Yes, you are right, there are a two same dependecies in build.gradle: compile 'com.google.android.gms:play-services:4.0.30' compile files('libs/google-play-services.jar'). I try to add google play service lib in project, because my application ask to download this files, but i want to send these libraries with apk file, it is possible? Sorry for my language=) – Maxim Mileshin Mar 08 '14 at 00:31

1 Answers1

1

You have something like this:

dependencies {
    compile 'com.google.android.gms:play-services:4.0.30'
    compile files('libs/google-play-services.jar')
}

But that's including the library twice. It's sufficient to have just this:

dependencies {
    compile 'com.google.android.gms:play-services:4.0.30'
}

It will compile correctly, and it will include the right library in your APK.

Scott Barta
  • 79,344
  • 24
  • 180
  • 163
  • My device asks to install the library when trying to display a map, it's okay? It's impossible without it? – Maxim Mileshin Mar 08 '14 at 01:01
  • Does it work okay if you let it install the library? This behavior is built-in to Play Services and is normal; it needs to have a compatible version of the Google Play Services app installed. On most people's devices, at least those who have the Google Play store app, this will be downloaded and installed and kept up-to-date automatically. – Scott Barta Mar 08 '14 at 01:03