Make changes to build.gradle persistent

759 views
Skip to first unread message

Victor Bjelkholm

unread,
Feb 8, 2016, 8:16:15 AM2/8/16
to phonegap
We're building an application including push notifications from Pushwoosh and recently we had a couple of devices that cannot install the app because of conflicting provider.

We discovered that Pushwoosh requires us to do the following changes:

VERY IMPORTANT: If your version of Cordova is lower than 6.0.0, you will be unable to install more than one application with Pushwoosh plugin on the same Android device:
https://code.google.com/p/analytics-issues/issues/detail?id=784

As a workaround you can add the following code to your build.gradle:

android {
    defaultConfig.applicationId = "your.package.id"
}

This bug was fixed in Cordova 6.0.0.



As soon as I manually did these changes, the app is getting installed correctly.

However, these changes are not persistent since firstly, the build.gradle is generated and shouldn't be edited.
Secondly, our platforms/ directory is not in scm either.


How can I add things to the build.gradle without manually entering it there all the time?

Tried having a build.json looking like this:

{
  "android": {
    "defaultConfig": {
      "applicationId": "com.company.appName"
    }
  }
}

And running `phonegap run android --device --verbose --buildConfig build.json`

But the changes are not there in the build.gradle.


Any pointers and/or help is appreciated!

Simon MacDonald

unread,
Feb 8, 2016, 8:22:00 AM2/8/16
to phonegap
You can fix it but adding a gradle file to the plugin. That's what I did for the phonegap-plugin-push repo:

--
-- You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to
phonegap+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en
 
For more info on PhoneGap or to download the code go to www.phonegap.com
---
You received this message because you are subscribed to the Google Groups "phonegap" group.
To unsubscribe from this group and stop receiving emails from it, send an email to phonegap+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Victor Bjelkholm

unread,
Feb 8, 2016, 8:35:55 AM2/8/16
to phonegap
Thanks Simon for the proposed fix!

Seems however this is for a plugin if I'm not wrong. You know it would be similar to fix it for an application in the config.xml?

How would the syntax be in that case? Phonegaps documentation is lousy at listing how the structure works in the config.xml...

Simon MacDonald

unread,
Feb 8, 2016, 8:40:24 AM2/8/16
to phonegap
Well, it's fixed in the latest version of Cordova Android so you could just upgrade that part of your project. Alternatively, just write your own plugin that only delivers the gradle file. That would be a 5 minute job.

Victor Bjelkholm

unread,
Feb 8, 2016, 8:42:31 AM2/8/16
to phon...@googlegroups.com
Yeah, tried upgrading the cordova to 6 or later but Phonegap seems to locked at version < 5.

Also, could you give me some guidance on what you mean with writing my own plugin for this? I would have to wrap the PushWoosh plugin in my own plugin? Or I would have to add a plugin that goes to the build.gradle to overwrite it?

Pretty new with Phonegap so I'm sorry for any confusion from my side...
You received this message because you are subscribed to a topic in the Google Groups "phonegap" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/phonegap/bIef9FU1RJY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to phonegap+u...@googlegroups.com.

jcesarmobile

unread,
Feb 8, 2016, 8:46:52 AM2/8/16
to phonegap
It's not possible from the config.xml

On the docs I found this:

Extending build.gradle

If you need to customize build.gradle, rather than edit directly, you should create a sibling file named build-extras.gradle. This file will be included by the main build.gradle when present. Here's an example:

# Example build-extras.gradle
# This file is included at the beginning of `build.gradle`
ext.cdvDebugSigningPropertiesFile = '../../android-debug-keys.properties'
# When set, this function allows code to run at the end of `build.gradle`
ext.postBuildExtras = {
    android.buildTypes.debug.applicationIdSuffix = '.debug'
}

Note that plugins can also include build-extras.gradle files via:

<framework src="some.gradle" custom="true" type="gradleReference" />


So you can try that or create a simple plugin that doesn't have any code, just the gradleReference part.

Simon MacDonald

unread,
Feb 8, 2016, 8:51:36 AM2/8/16
to phonegap
Oh you could just create a plugin.xml that only has something like the
following:

<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:amazon="http://schemas.android.com/apk/lib/com.amazon.device.ads"
xmlns:rim="http://www.blackberry.com/ns/widgets"
id="phonegap-plugin-gradle-fix"
version="0.0.1">
<name>Gradle Fix</name>
<!-- android -->
<platform name="android">
<framework src="push.gradle" custom="true" type="gradleReference" />
</platform>
</plugin>

and include the above plugin.xml and the push.gradle from my repo in a
new git repo. Then you can just add that plugin to your app for a temp
fix.

Simon Mac Donald
http://hi.im/simonmacdonald


Victor Bjelkholm

unread,
Feb 8, 2016, 9:16:35 AM2/8/16
to phonegap
Hey jcesarmobile!

I just tried adding the following build-extras.gradle to my root folder:

android {
    defaultConfig.applicationId = "com.typeform.antelope"
}
But doesn't seem to be setting the parameter at all. Probably doing something wrong on my end...

Victor Bjelkholm

unread,
Feb 8, 2016, 9:17:52 AM2/8/16
to phonegap
Hey Simon! Thanks for this and for having the patience with me!

I created https://github.com/VictorBjelkholm/phonegap-application-id-fix-plugin to be included in my application.

Included it with "<plugin name="phonegap-plugin-gradle-fix" spec="https://github.com/VictorBjelkholm/phonegap-application-id-fix-plugin" />"

but still no changes in the build.gradle

Simon MacDonald

unread,
Feb 8, 2016, 9:32:00 AM2/8/16
to phonegap
Whoops sorry, I cut too much stuff. You would need to adding something
like the following but it will conflict with the PushWoosh plugin. I
think the best options are to a) fix PushWoosh plugin or b) upgrade
android version


<config-file target="AndroidManifest.xml" parent="/manifest">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="${applicationId}.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="${applicationId}.permission.C2D_MESSAGE" />
</config-file>
<config-file target="AndroidManifest.xml" parent="/manifest/application">
<activity android:name="com.adobe.phonegap.push.PushHandlerActivity"
android:exported="true"/>
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="${applicationId}" />
</intent-filter>
</receiver>
<service
android:name="com.adobe.phonegap.push.GCMIntentService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
<service
android:name="com.adobe.phonegap.push.PushInstanceIDListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID"/>
</intent-filter>
</service>
<service
android:name="com.adobe.phonegap.push.RegistrationIntentService"
android:exported="false">
</service>
</config-file>
Simon Mac Donald
http://hi.im/simonmacdonald


Victor Bjelkholm

unread,
Feb 8, 2016, 10:29:17 AM2/8/16
to phon...@googlegroups.com, phonegap
Hey Simon!

Thanks for the help, I submitted a PR to Pushwoosh for them to fix it for all their users instead of just writing a solution for myself.

Thanks for all the pointers and examples, helps us enormously! 
Reply all
Reply to author
Forward
0 new messages