Maxim Mileshin
Maxim Mileshin

Reputation: 71

I can't add google-play-services.jar in my project in android studio 0.4.6

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')
}

Upvotes: 0

Views: 1622

Answers (1)

Scott Barta
Scott Barta

Reputation: 80020

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.

Upvotes: 1

Related Questions