ToM
ToM

Reputation: 393

Cordova com.danielcwilson.plugins.googleanalytics with com.admob.google

I use Apache Cordova 4 to build my Android project with two Cordova plugins added: com.admob.google 4.0.7 and com.danielcwilson.plugins.googleanalytics

when I execute

$cordova build 

I get the following error:

UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/analytics/internal/Command$1; 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)

:dexDebug FAILED

I found out that this is a problem with multiple dependency, but can I solve this in anyway? When I remove one of the plugins build works ok.

Thanks!

Upvotes: 0

Views: 2289

Answers (4)

galgo
galgo

Reputation: 764

For me it happened because I updated my whole project and had the cordova-plugin-googleplayservices installed from previous versions.

Removing the plugin fixed my issue (make sure it does not reinstall on build as I had that issue several times until I realized):

cordova plugin rm cordova-plugin-googleplayservices

Upvotes: 0

Miquel
Miquel

Reputation: 8989

I'm the developer of com.admob.google (which now has been moved to cordova-admob and is the one that will be mantained)

You can also use this analytics plugin which has no conflict with cordova-admob: https://github.com/appfeel/analytics-google

cordova plugin add cordova-plugin-analytics

And if you would like to use adId: https://github.com/appfeel/analytics-google-adid

cordova plugin add cordova-plugin-analytics-adid

Upvotes: 2

ToM
ToM

Reputation: 393

I managed to solve this in another way:

  1. I extracted platforms/android/com.google.play.services/[App Name]-google-play-services_lib/libs/google-play-services.jar
  2. I removed conflicting classes
  3. I used CLI jar to recreate the jar again
  4. I replaced google-play-services.jar with the new version

Upvotes: 1

Diego Link
Diego Link

Reputation: 241

I had the same Multiple Dex problem with the Facebook plugin and com.danielcwilson.plugins.googleanalytics

I was able to solve the problem by creating a custom rule in danielcwilson's plugin.xml:

In order to have your changes take effect, you have to add and remove the analytics plugin, which will stomp over any local changes you make. To prevent that, pull from the source and make the changes below or use my fork of the branch:

My fork: https://github.com/diego-link-eggy/google-analytics-plugin

Solution: In plugins/cordova-plugin-google-analytics I created a pixme-play-services-analytics-exclude-v4.gradle file which contains:

dependencies {
   compile ('com.google.android.gms:play-services-analytics:+') {       
       exclude module: 'support-v4'
   }
}

In the plugin.xml comment out the old framework reference and replace it with the gradle rule you just created:

 <platform name="android">
      <!-- <framework src="com.google.android.gms:play-services-analytics:+" /> -->
      <framework src="play-services-analytics-exclude-v4.gradle" custom="true" type="gradleReference" />

Then remove and add the analytics plugin to have the change take effect.

  cordova plugin rm cordova-plugin-google-analytics
  cordova plugin add https://github.com/diego-link-eggy/google-analytics-plugin
     OR
   cordova plugin add <path to where you cloned source>

This answer came from reading the solution posted here: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat

and the Cordova plugin spec found here: http://cordova.apache.org/docs/en/5.1.1/plugin_ref_spec.md.html#Plugin%20Specification

Upvotes: 2

Related Questions