BranchMetrics / phonegap-plugin

PhoneGap/Cordova plugin for Tune
https://developers.tune.com/sdk/phonegap-quick-start/
MIT License
8 stars 16 forks source link

Cordova plugin dependency issues. #11

Open sean-hill opened 9 years ago

sean-hill commented 9 years ago

This plugin and Cordova's Facebook Plugin here can not be built together due to conflicting android-support library files. When I try to build, I get this error:

UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/annotation/AnimRes;
    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)

 FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':dexArmv7Debug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
    /Users/Comfy-Blitz/Development/adt-bundle/sdk/build-tools/22.0.1/dx --dex --no-optimize --output /Users/Comfy-Blitz/Development/Unbill/mobile/platforms/android/build/intermediates/dex/armv7/debug --input-list=/Users/Comfy-Blitz/Development/Unbill/mobile/platforms/android/build/intermediates/tmp/dex/armv7/debug/inputList.txt
  Error Code:
    2
  Output:

    UNEXPECTED TOP-LEVEL EXCEPTION:
    com.android.dex.DexException: Multiple dex files define Landroid/support/annotation/AnimRes;
        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)

This issue is similar to this but in the Tune's plugin directory I do not see a android-suppport.jar file, and I assume it must be built into the MobileAppTracker-3.11.0.jar file.

john-gu commented 9 years ago

Hi Sean,

The issue is in that FB plugin, Cordova overrides and does not use the build.gradle (which specifies the support-v4 and bolts dependencies) in /platforms/android/FacebookLib. So those jars were also manually included in the /FacebookLib/libs folder. The android-support-v4 library then gets added twice, once from /FacebookLib/libs and once from the MAT plugin's framework dependency on Google Play Services.

The solution I found was to extend the build.gradle file like it describes here under "Extending build.gradle": https://cordova.apache.org/docs/en/4.0.0/guide/platforms/android/tools.html

where someone submitted the fix: https://github.com/Wizcorp/phonegap-facebook-plugin/pull/1081 but it was only merged into the "develop" branch.

You can add the build-extras.gradle file from their pull request to /platforms/android/FacebookLib so that Cordova actually uses the dependencies instead of the libs folder's jars: https://github.com/MSOpenTech/phonegap-facebook-plugin-1/blob/89e7156aa0ed04dd8ec7ffe92f8cabe2906cac12/platforms/android/FacebookLib/build-extras.gradle

That way, the library is included in the same way from both plugins and can be de-duped. After I added this build-extras.gradle file, my build compiled.

sean-hill commented 9 years ago

@john-gu Thanks for your response. The build-extras.gradle solution worked for me!

john-gu commented 9 years ago

I'll keep this issue open for visibility until the Facebook plugin's master branch is updated, thanks for bringing this to our attention.

Moghul commented 8 years ago

@sean-hill Please use this Facebook plugin instead: cordova-plugin-facebook4. No baked in jar.

EDIT: I am now aware that this is an old thread but this solution still stands for anyone looking for a fix.