title: Android/Cordova build dependency error with google-play-services (more than one library with package name 'com.google.android.gms')
body: <p>Note: I know there are a thousand questions about this error on SO, and I swear I've read all of them, but none of the solutions have worked. (More detail on my many unsuccessful attempts below.)</p>
  
  <p>When I try to build my cordova app for Android, I get the following error:</p>
  
  <pre><code>:processDebugResources FAILED
  
  FAILURE: Build failed with an exception.
  
  * What went wrong:
  Execution failed for task ':processDebugResources'.
  &gt; Error: more than one library with package name 'com.google.android.gms'
    You can temporarily disable this error with android.enforceUniquePackageName=false
    However, this is temporary and will be enforced in 1.0
  </code></pre>
  
  <p>My question: How can I fix this and build my app?</p>
  
  <p><strong>Background</strong></p>
  
  <p>From the many SO answers I've read, I know this is almost certainly a problem with plugins adding duplicate Google Play dependencies. My app (and all its plugins) were working great until my most recent plugin addition: the <a href="https://github.com/urbanairship/phonegap-ua-push" rel="nofollow">Urban Airship cordova plugin</a>. Here is my current plugin list:</p>
  
  <pre><code>cc.fovea.cordova.purchase 4.0.0 "Purchase"
  com.xmartlabs.cordova.market 1.1 "Market"
  cordova-google-play-services 25.0.0 "Google Play Services for Android"
  cordova-plugin-analytics 1.3.3 "Google Analytics Plugin"
  cordova-plugin-console 1.0.2 "Console"
  cordova-plugin-device 1.1.0 "Device"
  cordova-plugin-dialogs 1.2.0 "Notification"
  cordova-plugin-file 3.0.0 "File"
  cordova-plugin-inappbrowser 1.1.1 "InAppBrowser"
  cordova-plugin-network-information 1.1.0 "Network Information"
  cordova-plugin-splashscreen 3.0.0 "Splashscreen"
  cordova-plugin-statusbar 2.0.0 "StatusBar"
  cordova-plugin-whitelist 1.2.0 "Whitelist"
  cordova-plugin-x-socialsharing 5.0.7.1 "SocialSharing"
  cordova-plugin-x-toast 2.3.1 "Toast"
  urbanairship-cordova 4.0.1 "Urban Airship"
  </code></pre>
  
  <p>I've read through every plugin's plugin.xml, and the only other one which references Google Play Services is <a href="https://github.com/appfeel/analytics-google/blob/master/plugin.xml" rel="nofollow">Appfeel's cordova-plugin-analytics</a>. </p>
  
  <p>I'm using cordova 5.4.1 and cordova-android@4.1.1. Here is <a href="http://pastebin.com/XBrAJPnK" rel="nofollow">my config.xml</a>. I'm not using an IDE.</p>
  
  <p>Also, another answer recommended investigating the compile dependencies and looking for duplicates using <code>./gradlew dependencies</code>. Doing so gave me <a href="http://pastebin.com/GGwM3LYj" rel="nofollow">this output</a>. As you can see, it has many duplicates: lots of com.google.android.gms and lots of com.android.support and lots of CordovaLib. </p>
  
  <p><strong>What I've tried</strong></p>
  
  <ol>
  <li>Removing and re-adding the Android platform. It changed nothing. </li>
  <li><p>Removing and re-adding cordova-google-play-services. I was unable to remove it and got the following error:</p>
  
  <pre><code>Error: The plugin 'cordova-google-play-services' is required by (cordova-plugin-analytics), skipping uninstallation.
  </code></pre>
  
  <p>(I did not install cordova-google-play-services explicitly – it was installed automatically by cordova-plugin-analytics.)</p>
  
  <p>Earlier in my project I tried to use the more common analytics plugins by <a href="https://github.com/danwilson/google-analytics-plugin" rel="nofollow">danwilson</a> and <a href="https://github.com/cmackay/google-analytics-plugin" rel="nofollow">cmackay</a>, but I ran into similar issues just <em>installing</em> those plugins, which is why I'm now using Appfeel's Google Analytics plugin (which installed without problems and works great).</p></li>
  <li><p>Adding a build-extras.gradle in /platforms/android with the following code:</p>
  
  <pre><code>configurations {
    all*.exclude group: 'com.android.support', module: 'support-v4'
    all*.exclude group: 'com.google.android.gms', module: 'play-services-analytics'
  }
  </code></pre>
  
  <p>When I run this, I <em>do</em> avoid the "more than one library" error, but instead I get dozens of package-does-not-exist errors like this one:</p>
  
  <pre><code>:compileDebugJava
  /Users/sarah/Development/app/platforms/android/src/com/urbanairship/cordova/CordovaAutopilot.java:31: error: package android.support.v4.app does not exist
  import android.support.v4.app.NotificationCompat;
                           ^
  </code></pre>
  
  <p>I've also tried a variety of other exclusion combinations that were motivated from the <code>./gradlew dependencies</code> output I mentioned above.</p></li>
  <li><p>Updating the Android platform, updating cordova</p></li>
  <li><p>Making sure I have the most current version of gradle</p></li>
  <li><p>Updating everything I can in the Android SDK Manager. Here's a <a href="https://cl.ly/122L1r3v3R0s" rel="nofollow">screenshot of the Extras I have installed</a>. And a <a href="http://cl.ly/332K1m1O1k3X" rel="nofollow">screenshot of Tools</a>. And <a href="http://cl.ly/323D04462x0t" rel="nofollow">other SDK packages</a>.</p></li>
  <li><p>Adding a build-extras.gradle that uses <code>dependencies</code> with exclusions instead of <code>configurations</code>. I've tried about twenty different combinations of packages and groups and modules (again motivated by the <code>./gradlew dependencies</code> output) . Sometimes I try excluding only groups or only modules. Sometimes I try excluding with or without the version numbers. (As you can see, I don't really know what I'm doing re:gradle.) Here's one attempt:</p>
  
  <pre><code>dependencies {
      compile('com.urbanairship.android:urbanairship-sdk:6.4.1') {
          exclude group: 'com.google.android.gms', module: 'play-services-base'
          exclude group: 'com.google.android.gms', module: 'play-services-basement'
          exclude group: 'com.android.support', module: 'support-v4'
      }
  }
  </code></pre>
  
  <p>Here's another:</p>
  
  <pre><code>dependencies {
      compile('com.urbanairship.android:urbanairship-sdk:6.4.1') {
          exclude group: 'com.google.android.gms', module: 'play-services-base'
          exclude group: 'com.google.android.gms', module: 'play-services-maps'
          exclude group: 'com.google.android.gms', module: 'play-services-basement'
          exclude group: 'com.android.support', module: 'support-v4'
      }
  
      compile('com.google.android.gms:play-services-location:8.1.0') {
          exclude group: 'com.google.android.gms', module: 'play-services-base'
          exclude group: 'com.google.android.gms', module: 'play-services-maps'
          exclude group: 'com.google.android.gms', module: 'play-services-basement'
          exclude group: 'com.android.support', module: 'support-v4'
      }
  
      compile('com.android.support:cardview-v7:23.1.0') {
          exclude group: 'com.android.support', module: 'support-v4'
      }
  }
  </code></pre></li>
  <li><p>In my research I discovered that the Urban Airship plugin has <a href="https://github.com/urbanairship/phonegap-ua-push/blob/master/src/android/build-extras.gradle" rel="nofollow">its own build-extras.gradle</a> in /platforms/android/urbainairship-cordova. So I tried adding compile exclusions to <em>that</em> build-extras.gradle instead using a zillion combinations like those I mentioned in #7. Eventually I exclude too much and end up with package-does-not-exist errors like those shown in #3, but backing off results in the same more-than-one-library error.</p></li>
  <li><p>Commenting out <code>&lt;dependency id="cordova-google-play-services" /&gt;</code> in the <a href="https://github.com/appfeel/analytics-google/blob/master/plugin.xml#L40" rel="nofollow">analytics plugin's plugin.xml</a>.</p></li>
  </ol>
  
  <p><strong>My question</strong></p>
  
  <p>Sorry for the long post, but this all seems like relevant troubleshooting info! To restate my question from the beginning: how do I fix this error and build successfully?</p>