More than one library with package name 'com.g

2019-08-25 04:00发布

问题:

Very weird bug appears in my Cordova project when I updated Cordova and Android SDK (all are in the last versions).

Since the update I got the following error with gradle : Error: more than one library with package name 'com.google.android.gms'

Cordova plugins have not changed and this was working well before the update. Removing/adding the Android platform or cleaning it doesn't fix this error.

It seems due to the version 8.1 of com.google.android.gms

I use the cordova-plugin-google-analytics which uses : com.google.android.gms:play-services-analytics:+ (I assume the + means last version?) Due to this line and with the update the project don't build anymore Replacing the + with a value (7.5.0, etc for example) works well

Does 8.x has a breaking change?

I saw this post too: https://code.google.com/p/android/issues/detail?id=187464

For now I will force a value but if you have a better solution you are welcome

Thanks

回答1:

I have solved this with a hook. Its not perfect but works.

In your after_platform_add add this script

#!/usr/bin/env node


var fs = require('fs');
var path = require('path');
var fork = require('child_process').fork,
    shell = require("shelljs");

var dir = './platforms/android/';

fs.writeFileSync(dir + 'build-extras.gradle', 'configurations { all*.exclude group: \'com.android.support\', module: \'support-v4\'}', 'utf8');