Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Matheus_O_
Beginner
73 Views

Build fails using third-part plugins

Jump to solution

I had several problems when trying to use third-part plugins, specially small plugins (with short amount of contribuitors) on github. I point the git repo on "Cordova Hydrid Mobile App Settings" and try to build. I got this error:

Build Log

  • Building a Cordova 5.4.1 application.
  • Using platform cordova-ios 4.0.1.
  • The application name is "CS i9"
  • The package name is "com.compusoft.loginUI"
  • Plugin "cordova-plugin-statusbar" (2.1.0) installed.
  • Plugin "cordova-plugin-device" (1.1.1) installed.
  • Plugin "cordova-plugin-splashscreen" (3.2.0) installed.
  • Plugin "cordova-plugin-dialogs" (1.2.0) installed.
  • Error: Plugin cordova-plugin-gcmpushplugin cannot be added. The plugin contains Gradle scripts.

 

 If I download the plugin and install manually, I also get the same error. This follows for most of pluggins i'm using. The one with problem here is this: https://github.com/gonzaloaune/GCMPushPlugin.

I'm using Cordova 5.4.1 (also tried with 5.1.1), and using XDK build 3240. How can I install these plugins?

Tags (2)
0 Kudos
1 Solution
PaulF_IntelCorp
Employee
73 Views

Matheus -- our Android build system now includes a fix for an issue in the standard Cordova build system that allows the push plugin you are referencing to work, without a gradle script! This fix only works for plugins that include a gradle script designed to set the default App ID, like that one in the phonegap-plugin-push plugin.

In this particular example, the gradle script that's been added to the plugin looks like this (it is named push.gradle):

import java.util.regex.Pattern

def doExtractStringFromManifest(name) {
    def manifestFile = file(android.sourceSets.main.manifest.srcFile)
    def pattern = Pattern.compile(name + "=\"(.*?)\"")
    def matcher = pattern.matcher(manifestFile.getText())
    matcher.find()
    return matcher.group(1)
}

android {
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
        }
    }

    defaultConfig {
        applicationId = doExtractStringFromManifest("package")
    }
}

All this gradle script is doing is inserting your app's "package ID" (which is what you set in the Build Settings as the "App ID") into a variable called "applicationID" for use by the build system.

You're probably asking, how does this help me? What do I do now? Good question.

Here's what you need to do:

Screen Shot 2016-05-10 at 2.07.47 PM.png

In this case, you should also be prompted to define a variable that the plugin needs. If you know that variable's name (it's called SENDER_ID for this plugin), you can add it using the "+" icon in the image above, and avoid the prompt. If the plugin add was successful, you'll find something like this in the Projects tab:

Screen Shot 2016-05-10 at 2.55.52 PM.png

If you are really curious, you can inspect the AndroidManifest.xml file that is included inside your built APK file (you'll have to use a tool like apktool to extract and reconstruct it from you APK file). You should see something like the following in the highlighted line (which should match your App ID, in this example, the App ID was "io.cordova.hellocordova"):

Screen Shot 2016-05-10 at 4.08.05 PM.png

If you see the following App ID, it means something went wrong. This is a default App ID that ends up causing a collision on end-user devices when another app that is using Google Services use this same default App ID:

Screen Shot 2016-05-10 at 4.08.05 PM copy.png

 

View solution in original post

4 Replies
PaulF_IntelCorp
Employee
73 Views

Our build system does not support plugins that include gradle scripts. This is due to the security risk that gradle scripts present to a cloud-based system. Anything can be put in those scripts, which could then be used to compromise the build system and your account information. We are working on a more secure build system that would allow us to run gradle scripts. Unfortunately, we do not yet have such a system in place.

In the meantime, the only way around this is to clone the plugin to your local system and modify it so that it does not require the gradle script. This means that you must determine what the gradle script is doing and change the plugin so it includes those pieces and parts. Then you can add the plugin by importing it as a local plugin.

Matheus_O_
Beginner
73 Views

Any prediction when PhoneGap's PushPlugin version 1.6.0 will be supported? I need some new resources urgently for my application.

PaulF_IntelCorp
Employee
74 Views

Matheus -- our Android build system now includes a fix for an issue in the standard Cordova build system that allows the push plugin you are referencing to work, without a gradle script! This fix only works for plugins that include a gradle script designed to set the default App ID, like that one in the phonegap-plugin-push plugin.

In this particular example, the gradle script that's been added to the plugin looks like this (it is named push.gradle):

import java.util.regex.Pattern

def doExtractStringFromManifest(name) {
    def manifestFile = file(android.sourceSets.main.manifest.srcFile)
    def pattern = Pattern.compile(name + "=\"(.*?)\"")
    def matcher = pattern.matcher(manifestFile.getText())
    matcher.find()
    return matcher.group(1)
}

android {
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
        }
    }

    defaultConfig {
        applicationId = doExtractStringFromManifest("package")
    }
}

All this gradle script is doing is inserting your app's "package ID" (which is what you set in the Build Settings as the "App ID") into a variable called "applicationID" for use by the build system.

You're probably asking, how does this help me? What do I do now? Good question.

Here's what you need to do:

Screen Shot 2016-05-10 at 2.07.47 PM.png

In this case, you should also be prompted to define a variable that the plugin needs. If you know that variable's name (it's called SENDER_ID for this plugin), you can add it using the "+" icon in the image above, and avoid the prompt. If the plugin add was successful, you'll find something like this in the Projects tab:

Screen Shot 2016-05-10 at 2.55.52 PM.png

If you are really curious, you can inspect the AndroidManifest.xml file that is included inside your built APK file (you'll have to use a tool like apktool to extract and reconstruct it from you APK file). You should see something like the following in the highlighted line (which should match your App ID, in this example, the App ID was "io.cordova.hellocordova"):

Screen Shot 2016-05-10 at 4.08.05 PM.png

If you see the following App ID, it means something went wrong. This is a default App ID that ends up causing a collision on end-user devices when another app that is using Google Services use this same default App ID:

Screen Shot 2016-05-10 at 4.08.05 PM copy.png

 

View solution in original post

Matheus_O_
Beginner
73 Views

Thank you for your attention,Paul, that works!

Reply