Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuring play-services version on capacitor #588

Open
p-v-d-Veeken opened this issue Apr 14, 2021 · 2 comments
Open

Configuring play-services version on capacitor #588

p-v-d-Veeken opened this issue Apr 14, 2021 · 2 comments

Comments

@p-v-d-Veeken
Copy link

In the documentation it says:
Use the GMS_VERSION to align the required play-services version with other plugins.

cordova plugin add cordova-plugin-google-analytics --variable GMS_VERSION=11.0.1

However I'm working on a capacitor project and although it was fairly painless to install the plugin, I'm now having issues building the app due to version mismatches:

Error: All gms/firebase libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 17.0.0, 11.0.1. Examples include com.google.android.gms:play-services-base:17.0.0 and com.google.android.gms:play-services-analytics-impl:11.0.1 

It appears this problem could be trivially fixed by specifying the GMS_VERSION, but I don't know if that's possible with capacitor. Any help would be greatly appreciated. :)

@p-v-d-Veeken
Copy link
Author

For anyone having the same problem, the following hack solved it for me:

  1. Adding the following to your app's package.json
    "scripts": {
        "postinstall": "npx ts-node scripts/setGoogleAnalyticsVersion.ts"
    }
  1. Create scripts/setGoogleAnalyticsVersion.ts and add the following contents:
import * as fs from 'fs';

const GMS_VERSION = '17.0.0';
const PLUGIN_PATH = './node_modules/cordova-plugin-google-analytics/plugin.xml';

console.log(`Attempting to set $GMS_VERSION = ${GMS_VERSION} in ${PLUGIN_PATH}`);

const pluginContents = fs.readFileSync(PLUGIN_PATH).toString('utf8');
const pluginContentsUpdated = pluginContents.replace('$GMS_VERSION', GMS_VERSION);

fs.writeFileSync(PLUGIN_PATH, pluginContentsUpdated);

console.log('Success!');

No doubt there are better ways to achieve the same thing, but at least it works.

@victorsosa
Copy link
Collaborator

PR are welcome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants