1

I am trying to add WearableListenerService to my hand held when I add the dependency compile 'com.google.android.gms:play-services-wearable:6.5.87' I get this error in the gradle build

Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
    /Users/jshultz/android-sdks/build-tools/21.1.2/dx --dex --no-optimize --output /Users/jshultz/Documents/workspace/MayDay/app/build/intermediates/dex/debug --input-list=/Users/jshultz/Documents/workspace/MayDay/app/build/intermediates/tmp/dex/debug/inputList.txt
  Error Code:
    2
  Output:
    UNEXPECTED TOP-LEVEL EXCEPTION:
    com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompatIcs;
        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)

Here is the build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.mayday.md"
        minSdkVersion 18
        targetSdkVersion 21
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile files('libs/crashlytics.jar')
    compile files('libs/cup-v1.0.0.jar')
    compile files('libs/support-v4-r12.jar')
    compile files('libs/gson-2.2.4.jar')
    compile files('libs/google-play-services-0.6.0-sources.jar')
    compile 'com.google.android.gms:play-services-wearable:6.5.87'
}
Jack Shultz
  • 2,031
  • 2
  • 30
  • 53
  • 1
    You have Two play services you should be using either google-play-services-0.6.0 or :play-services-wearable:6.5.87. – Muthu Feb 14 '15 at 04:33
  • I have tried them both exclusively and using the google-play-services-0.6.0 is insufficient because I use the class WearableListenerService. When I used the play-service-wearable I get `Error:Execution failed for task ':app:dexDebug'.` posted above – Jack Shultz Feb 14 '15 at 05:16

1 Answers1

1

Your problem is your are compiling two libraries that are the same:

compile files('libs/google-play-services-0.6.0-sources.jar')
compile 'com.google.android.gms:play-services-wearable:6.5.87'

You need to chose one Google Play Services, preferably the Maven Dependency and not the .jar.

Try this:

dependencies {
    compile files('libs/crashlytics.jar') // couldn't find maven
    compile files('libs/cup-v1.0.0.jar')  // couldn't find maven
    compile 'com.android.support:support-v4:21.0.3'
    compile 'com.google.code.gson:gson:2.3.1'
    compile 'com.google.android.gms:play-services-wearable:6.5.87'
}
Jared Burrows
  • 54,294
  • 25
  • 151
  • 185
  • I need to use the wearable to use WearableListenerService. When I remove the `google-play-services-0.6.0-sources.jar` and use `play-services-wearable:6.5.87` I get the same error `:app:dexDebug'.` – Jack Shultz Feb 14 '15 at 05:14
  • I updated my answer, keep your libraries up to date and do not include a "sources" jar. – Jared Burrows Feb 14 '15 at 05:19
  • When I do the most up to date version of gson and support-v4 some of the activities don't run properly and crashes the app when I click on some menu items. – Jack Shultz Feb 14 '15 at 05:24
  • @user3116989 You need the updates. They are listed here:http://developer.android.com/tools/support-library/index.html. You were using a very old version. So it now compiles? – Jared Burrows Feb 14 '15 at 05:27
  • I was afraid of that. I spent many hours today trying to get this method to work without returning a NULL `Fragment fragment = getFragmentManager().findFragmentById(R.id.sms_message);` and the only way I could was to fall back to the JARs. – Jack Shultz Feb 14 '15 at 05:35
  • That should be `getSupportFragmentManager()` if you are using Support V4. So is everything good? – Jared Burrows Feb 14 '15 at 05:37
  • Its inside a fragment subclass and I believe you need to use `getFragmentManager` when I use `getSupportFragmentManager` it cannot resolve the method – Jack Shultz Feb 14 '15 at 05:43
  • Alright. I thought you were calling from an `Activity`. We are no longer talking about your original question. I helped you get past this error. What else is troubling you? – Jared Burrows Feb 14 '15 at 05:46
  • If I go the route of updating the libs then it breaks functionality but I need to do that to get the wearable features. So maybe I need to select the old libraries for that specific activity. Not sure if that is possible but yes, this should be an new post. – Jack Shultz Feb 14 '15 at 05:49
  • If you make a new post or discussion, I'd be glad to help. – Jared Burrows Feb 14 '15 at 05:51
  • sure I just posted http://stackoverflow.com/questions/28512939/how-can-i-use-set-fragment-inside-my-class-which-extends-the-fragment-class – Jack Shultz Feb 14 '15 at 06:02