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

apply plugin within ext.postBuildExtras block #358

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

christocracy
Copy link

@christocracy christocracy commented Jul 22, 2017

By performing apply plugin within ext.postBuildExtras block, other plugins can have the opportunity to provide their own play-services dependency overrides within their own build-extras.gradle.

Providing a build-extras.gradle allows one's Cordova app to have the final word on play-services dependencies to resolve conflicts with other plugins.

I am the author of one these plugins, cordova-background-geolocation-lt, which conflicts with cordova-plugin-fcm.

This method of providing your application's own custom build-extras.gradle goes like this:

Step 1. In your application's config.xml, define a <hook /> script

config.xml

<platform name="android">
    <hook src="scripts/android/copyGradleBuildExtras.js" type="before_build" />
    .
    .
    .
</platform>

Step 2. Create file scripts/android/copyGradleBuildExtras.js

scripts/android/copyBuildExtras.js

var fs = require ('fs');
var path = require('path');

var sourcePath = path.resolve(__dirname, 'build-extras.gradle');
var destPath = path.resolve(process.cwd(), 'platforms', 'android', 'build-extras.gradle');

// cp scripts/android/build-extras.gradle platforms/android/build-extras.gradle
fs.createReadStream(sourcePath).pipe(fs.createWriteStream(destPath));

Step 3. Define your custom scripts/android/build-extras.gradle overrides

This file allows your app to have the last word on any gradle dependencies -- no more need to fork plugins to "pin" play-services version. (insert your own desired play-services version, I chose latest 11.0.2, but you can choose to pin any desired version (the version must be the same for each dependency)

scripts/android/build-extras.gradle

ext.postBuildExtras {
    dependencies {
        // These are the play-services dependencies required by cordova-background-geolocation
        compile ("com.google.android.gms:play-services-base:11.0.2") {
            force = true;
    	}
    	compile ("com.google.android.gms:play-services-location:11.0.2") {
            force = true;
    	}
    
    	// These are the cordova-plugin-fcm dependency overrides
    	compile ("com.google.firebase:firebase-core:11.0.2") {
            force = true
    	}
    	compile ("com.google.firebase:firebase-messaging:11.0.2") {
            force = true
    	}
      
        /* uncomment when using maps (eg: cordova-plugin-googlemaps)
        compile ("com.google.android.gms:play-services-maps:11.0.2") {
            force = true;
        }
        */

        /* uncomment when using firebase-messaging (eg: phonegap-plugin-push)
        compile ("com.google.firebase:firebase-messaging:11.0.2"), {
            force: true;
        }
        */
    }       
}

I implemented this method by following the Cordova Guide Setting Gradle Properties

…adle overrides a change to provide play-services dependency overrides when having dependency conflicts with other plugins
@christocracy
Copy link
Author

Is there anyone alive maintaining this plugin or is it dead?

@dagrinchi
Copy link

Thanks a lot! @christocracy

@0xGerard
Copy link

this another solution more: here

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

Successfully merging this pull request may close these issues.

None yet

3 participants