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

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

1 Like

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!!

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

1 Like

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.

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

1 Like

: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:

1 Like

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:)

looks good my man! thanks!

1 Like

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

@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.

@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 …

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.

1 Like

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.

1 Like

@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.

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

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

cordova build --release android

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

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

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"
3 Likes

Help! I am trying to insert intent filters into AndroidManifest.xml using this hook but I am getting a syntax error.

This is what I’m trying to add to AndroidManifest.xml

<activity ...>

    <intent-filter android:autoVerify="true">
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="http" android:host="www.android.com" />
        <data android:scheme="https" android:host="www.android.com" />
    </intent-filter>

</activity>

How would I add inside the config.xml or is there another way to modify AndroidManifest.xml with a plugin?

Thank you

And here is how I was adding it to the config.xml

    <platform name="android">
    <config-file target="AndroidManifest.xml" parent="./application/activity/[@android:name='MainActivity']">
    <intent-filter android:autoVerify="true">
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="http" android:host="www.android.com" />
        <data android:scheme="https" android:host="www.android.com" />
    </intent-filter>	
    </config-file>
	       <config-file target="AndroidManifest.xml" parent="./" mode="add">
            <application android:name="customApplication"></application>
        </config-file>
    </platform>