0

I'm having some problems with the latest version of Android studio, combined with a Facebook SDK (used only for logging in) and the Google Maps API.

I've set up a project in Android studio with the Facebook integration which works fine. But a colleague of mine created the Google Maps part, which I am trying to copy/paste into my project. I've set up it like the Google documentation tells me to. So that's not the problem.

I am only having problems with the build.cradle from my project and build.cradle file of the facebook library if I'm correct. The error is:

UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl; 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)

FAILED

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':app:dexDebug'. com.android.ide.common.internal.LoggedErrorException: Failed to run command: C:\Program Files\android-studio\sdk\build-tools\android-4.4.2\dx.bat --dex --output D:\Armindo\Android studioProjects\Project4\app\build\dex\debug D:\Armindo\Android studioProjects\Project4\app\build\classes\debug D:\Armindo\Android studioProjects\Project4\app\build\dependency-cache\debug D:\Armindo\Android studioProjects\Project4\app\build\pre-dexed\debug\android-support-v13-f0554868bfbee0fc4abfdc11fd962734ae0c6d5f.jar D:\Armindo\Android studioProjects\Project4\app\build\pre-dexed\debug\android-support-v4-16277ee73bd8328d9fa6b95c79f131076fa8f4be.jar D:\Armindo\Android studioProjects\Project4\app\build\pre-dexed\debug\bolts-714d8ee0ce6246f4109e078b8cded1f42aea8693.jar D:\Armindo\Android studioProjects\Project4\app\build\pre-dexed\debug\classes-291c4de37af2df287d3f0bde38005eb4ecb484f4.jar D:\Armindo\Android studioProjects\Project4\app\build\pre-dexed\debug\classes-82c2a48def34cb7b1f99f973c27e1ef8562b4177.jar D:\Armindo\Android studioProjects\Project4\app\build\pre-dexed\debug\support-v4-19.0.1-9046a2105fe8ed5a830061a0f501bb9eb2dfd6b0.jar Error Code: 2 Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;
    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)

My dependencies in my cradle files are looking like this: project's build.cradle: (Note that the libs from the main project are imported in a folder, e.g. libraries/facebook )

dependencies { compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':libraries:facebook')
compile 'com.google.android.gms:play-services:+'
}

facebook's build.cradle:

dependencies { compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/bolts.jar')
compile files('libs/android-support-v4.jar')
}

The error only occurs when I add compile 'com.google.android.gms:play-services:+' to the project's cradle.

I've tried almost all the topics about this on here already and also tried to import the same lib in both cradle's. Any ideas?

Edit1: Tried what Scott said. But I believe it is caused by it still having 2 times Android-support. Using the latest 3.14.1 Facebook SDK. Error

Edit2: Changed depency of facebook's build cradle:

compile - Classpath for compiling the main sources. +--- Project4.libraries:facebook:unspecified
| \--- com.android.support:support-v13:13.0.+ -> 13.0.0 | \--- com.android.support:support-v4:13.0.0 -> 19.0.1 \--- com.google.android.gms:play-services:+ -> 4.4.52 \--- com.android.support:support-v4:19.0.1

So it looks like Facebook is still using v4 underneath..

Edit3: After the comment, changed the buildToolsVersion again to 19.0.1 on both versions. Also changed facebook.cradle compile 'com.android.support:support-v4:19.0.1'.

The terminal now provides me with this: +--- Project4.libraries:facebook:unspecified
| \--- com.android.support:support-v4:19.0.1 \--- com.google.android.gms:play-services:4.4.52 \--- com.android.support:support-v4:19.0.1
So I guess that that is correct now, but I am still receiving the same error. This is the full error log (i think it's the same as before. But just checking the walls). Error report2

Last and final edit: Fixed! my application build.cradle: dependencies { compile 'com.google.android.gms:play-services:4.4.52' compile fileTree(include: ['*.jar'], dir: 'libs') compile files('build/libs/Parse-1.5.1.jar') compile project(':libraries:facebook') }

my facebook's lib build.cradle: dependencies { compile 'com.google.android.gms:play-services:4.4.52' compile fileTree(include: ['*.jar'], dir: 'libs') compile files('build/libs/Parse-1.5.1.jar') }

To fix it I just had to import the play services into BOTH the libraries, derp

Armini0
  • 1
  • 4
  • Hmm, it's using both the v4 support library and the v13 support library. That's the new cause of the problem. – Scott Barta Jun 06 '14 at 19:28
  • Any Idea how to fix this? I ain't saying that it has to import it anywhere. Any place where I'm not looking right? – Armini0 Jun 06 '14 at 19:34
  • From the command line, at the project root directory, you can run the command `gradlew -p app dependencies` and it should give you a dependency tree that will shed more light on where things are coming from. Get everything on the same version of the support library; if your minSDK is 13 or later, you can use the v13 support library; if it's < 13, then use v4. – Scott Barta Jun 06 '14 at 19:41
  • It does give me what's up top in my firstpost back after changing the facebook's cradle to `compile 'com.android.support:support-v13:13.0.+'` because I'm using `minSdkVersion 15. – Armini0 Jun 06 '14 at 19:57
  • I amended my answer, have a look at the edit. I still think you don't have everything on consistent version numbers. – Scott Barta Jun 06 '14 at 20:37
  • I see that you have edited the post. I have tested, but it still results in a negative compile of the code. See my amended first post. – Armini0 Jun 06 '14 at 21:06

2 Answers2

0

Facebook shouldn't be including the v4 support library that way -- if you include it as a regular jar instead of using its Maven coordinates, the build system isn't able to disambiguate multiple copies of it (it's picking it up through its dependency on Play Services as well).

In Facebook's build file, change its dependencies to:

dependencies { 
    compile files('libs/bolts.jar')
    compile 'com.android.support:support-v4:19.0.+'
}

Note that the directive to auto-include all jars from the libs directory is removed as well.

I think you're using an old version of the Facebook SDK; in v3.14.1 of the SDK, at least, this is fixed up.

EDIT:

When I first answered the question, I had a statement to use support-v4:13.0.+ of the library since that's what Facebook specifies in v3.14.1 of the SDK. However, I amended it to use support-v4:19.0.+. In your case, you're including Play Services, which depends on a later version of the support library. Perhaps getting everything on the same version of the v4 support library may help.

Also note that your dependencies show that you have a dependency on the v13 support library as well. Please be aware that there are two version numbers here; the v4 support library has a number of releases (13.0.0, 18.0.0, 19.0.0, 19.0.1, and 19.1.0), and there's a v13 support library, which has those same set of releases as well. Make sure you don't confuse the two different version numbers.

Scott Barta
  • 79,344
  • 24
  • 180
  • 163
  • Thanks, I tried that. But it is not working. I was already thinking that is was working that way, but just kept it this way to be sure. I am now getting the same error, even when I use the Maven coordinates. – Armini0 Jun 06 '14 at 19:21
  • Fixed it Scott, see my latest edit! Fixed it by just importing the play services into both build.cradle files `compile 'com.google.android.gms:play-services:4.4.52'` – Armini0 Jun 08 '14 at 10:00
0

Fixed it by just importing the play services into both build.cradle files compile com.google.android.gms:play-services:4.4.52

Armini0
  • 1
  • 4