Cordova/Ionic CLI hooks for modifying AndroidManifest.xml or IOS PList file?


#1

Hello!!

I am using the Cordova CLI (not phonegap build) and I understand that it is best practice not to version control the platform folder.

I have been looking for a solution which uses a hook to modify the contents of the android manifest or ios plist file but have not come across anything. Does anyone know if there is one available? It seems that this need is so common that there should be something available that will either merge or copy these configuration files but can’t find anything. I’m sure I could create a hook to do this, however since I’m rather new to node and since it seems so common, I dont want to spend the time if it’s already done.

Anyone have any ideas/solutions/best practices regarding this?

Thanks!!


#2

This is a great place to start

http://devgirl.org/2013/11/12/three-hooks-your-cordovaphonegap-project-needs/

Knowing node is a big key. Also some good info can be found in the readme in the hooks directory.


#3

thanks @mhartington! I came across this site before but just wanted to make sure there wasnt anything available already before taking a stab at it :slight_smile:

thanks again,

Devin


#4

If anyone is interested in this hook, I have just submitted a pull request to the ionic yeoman generator that includes the new hook to modify contents of the android manifest and ios plist file similar to how you would in a plugin.xml file.

NOTE: this depends on elementree and plist npm modules, see _package.json for more info

You can view the hook in my forked repo at the following URL for more information/docs on how to use it

https://github.com/djett41/generator-ionic/blob/master/templates/hooks/after_prepare/update_platform_config.js

Enjoy!!


#5

That is interesting, is there a way to modify the android:theme attribute in the manifest with your hook?


#6

Yes @mirko77 . that is available as a preference. Look at the hook documentation and the mapping object which shows you all attributes available via preferences.


#7

Great hook. Thank you!
Sadly it merges tag and so I can’t configure intent-filter in this way.

I do two little changes to your hook for my purposes.
See here: http://stackoverflow.com/a/28217626/1756028


#8

:slight_smile: glad you found it useful to some extent @mcarnazzo . The only thing I would say about commenting out the lines that replace the xml rather than append is that it will break the functionality for tags that shouldn’t have more than one declaration such as supports-screens, application, or uses-sdk.

I think a good approach would be to first see if the tag can be uniquely defined (the same way I identified unique permissions in line 281), and if so, add some logic there that would uniquely select the child element and in your case, come up not found so it would append rather than replace.

If theres no way to uniquely identify an intent-filter, it may be useful to add some logic that checks a js object that stores tags/elements that CAN include multiples (such as permissions and intent-filters in your case) and always append those elements, otherwise replace.

This would satisfy all customers :slight_smile:


#9

You are right :smile:.
How about this patch? (works only for android)
http://pastie.org/9873459

(sorry but I’m a newbie node developer and I don’t have enough time :frowning:)


#10

looks good my man! thanks!


#11

This seems not to work with the option: in config.xml. I’m trying to add android:debuggable=“true” to AndroidManifest.xml


#12

@puzste it should work if configured right.

How are you adding the config to config.xml? If you paste your config.xml code I can check it out.


#13

@djett this is how i added it:

 <preference name="debuggable" value="true"/>

I’m having the same issue with the app-name in AndroidManifest.xml:

 <activity android:name="CordovaApp"> 

How can i change it in config.xml? I tried with :smile:

<name>MyApplication</name>

I’m also not sure if I have to update the hook update_platform_config.js …


#14

Thank you all for sharing these!
I wonder if ionic or cordova is going to have an easier way to make changes to the platform specific manifests. I find this extremely tedious.


#15

Yes, a more official and supported toolset for this would be great.

I just wrote a bunch of custom hook scripts to manage some plist customizations. The time to write > run/test > debug (feedback loop) is not fun. Wish I’d found these tools before I did it all myself.


#16

@puzste take a look at the hook’s documentation here. As you will see, debuggable is not available as a preference. Also any elements other than permission elements will be replaced, so include the nested elements as well when you add configuration for AndroidManifest in config.xml.

If you post your actual config.xml code I can help you out more. It’s not clear what exactly you are trying to accomplish based on your previous posts.


#17

How can i add debbugable = false to androidManifest.xml ? need it for deploy to google play


#18

I think you may want to build for release like so:

cordova build --release android

source: http://ionicframework.com/docs/guide/publishing.html


#19

Thanks for reply but i cant do this because after rellease build my rest api requests stop work…
I cry about this here Ionic run android works BUT apk does not access internet


#20

The solution from @djett was great but we needed the ability to add new intent-filters to the android manifest instead of merging with the current one. I found a slightly different version of the same hook which supports optional additions instead of merges. Maybe someone who is better than me at XML could try implement the mode=“add|merge|replace|etc” options from the cordova plugin docs in which this hook is based off

Here’s the hook:

If anyone has issues running ionic build android with an error about unbound prefix’s, then you need to add this to the widget element at the top of your config.xml

xmlns:android="http://schemas.android.com/apk/res/android"