{"id":1419,"date":"2014-02-07T08:05:47","date_gmt":"2014-02-07T14:05:47","guid":{"rendered":"http:\/\/www.mooreds.com\/wordpress\/?p=1419"},"modified":"2014-02-07T08:05:47","modified_gmt":"2014-02-07T14:05:47","slug":"how-to-use-platform-specific-configuration-in-your-cordova-app","status":"publish","type":"post","link":"https:\/\/www.mooreds.com\/wordpress\/archives\/1419","title":{"rendered":"How to use platform specific configuration in your Cordova app"},"content":{"rendered":"<p>This post comes out of a question I answered over at the guest post I did on Devgirl&#8217;s blog, <a href=\"http:\/\/devgirl.org\/2013\/11\/12\/three-hooks-your-cordovaphonegap-project-needs\/\">&#8216;Three Hooks Your Cordova Project Needs&#8217;<\/a>.<\/p>\n<p>A commenter asked: <\/p>\n<blockquote><p>How do you retain the project level settings for cordova Android projects? Platforms folder removes project level setting when you run \u2018cordova platform rm android\u2019<\/p><\/blockquote>\n<p>I answered over there, but thought I&#8217;d expand a bit and write a post here.  <\/p>\n<p>When you are doing Cordova development, there are two main tooling paradigms.  You can use native tooling (Eclipse, XCode) to manage your source, edit your javascript and CSS, etc&#8211;this is called &#8216;Native Platform Dev&#8217;.  Or you can use tooling more typically used in web development (a text editor like Sublime or vi) plus Cordova CLI&#8211;this is called &#8216;Web Project Dev&#8217;.  Here&#8217;s <a href=\"https:\/\/github.com\/apache\/cordova-docs\/pull\/140#discussion_r7437249\">a bit more on the names of these paradigms<\/a>.<\/p>\n<p>In the first case, you are probably not removing the files under <code>platform<\/code> all that often&#8211;you are more likely to work out of that directory.  In the second case, everything under <code>platform<\/code> is derived from your <code>www<\/code> directory, plus your plugins, so you can remove the <code>platform<\/code> directory easily.<\/p>\n<p>I can&#8217;t really speak to Native Platform Dev, because it isn&#8217;t a Cordova workflow I&#8217;ve used.  My <a href=\"https:\/\/leanpub.com\/developingwithcordovacli\/\">book<\/a> is entirely about Web Project Dev and how to do it most efficiently.  If that is your paradigm, I imagine you won&#8217;t have much trouble with platform specific settings, because the native tooling is pretty good about capturing that in version control, so you can rely on it.<\/p>\n<p>If, on the other hand, you are using Web Project Dev, then if you want to modify platform specific settings, you have three options:<br \/>\nYou need to either:<\/p>\n<ol>\n<li>\nOnly modify your project in ways that can be expressed in <code>config.xml<\/code>.  Review the <a href=\"http:\/\/cordova.apache.org\/docs\/en\/3.3.0\/config_ref_index.md.html#The%20config.xml%20File\">config.xml reference<\/a> and the <a href=\"http:\/\/cordova.apache.org\/docs\/en\/3.3.0\/guide_platforms_index.md.html#Platform%20Guides\">platform guides<\/a> to figure out if your needed customization can be captured in this way.\n<\/li>\n<li>\nWrite an <code>after_platform_add<\/code> hook which copies your changes over from elsewhere in your source tree (if you have a modified .java file for example).\n<\/li>\n<li>\nWrite a plugin which modifies an XML files (<code>AndroidManifest.xml<\/code>) to insert your needed project level config, (an <a href=\"http:\/\/developer.android.com\/guide\/topics\/manifest\/intent-filter-element.html\">IntentFilter<\/a>, for example), and add that plugin to your project in an an <code>after_platform_add<\/code>.  Note you can <a href=\"http:\/\/cordova.apache.org\/docs\/en\/3.3.0\/plugin_ref_spec.md.html#Plugin%20Specification_config_file_element\">only add XML nodes to config files with plugins<\/a>, you can&#8217;t modify attributes or remove nodes.\n<\/li>\n<\/ol>\n<p>Which of these is correct for you depends on exactly which platform specific feature you are trying to modify.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This post comes out of a question I answered over at the guest post I did on Devgirl&#8217;s blog, &#8216;Three Hooks Your Cordova Project Needs&#8217;. A commenter asked: How do [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[64,37],"tags":[],"class_list":["post-1419","post","type-post","status-publish","format-standard","hentry","category-cordova-cli","category-tips"],"_links":{"self":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/1419","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/comments?post=1419"}],"version-history":[{"count":1,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/1419\/revisions"}],"predecessor-version":[{"id":1420,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/1419\/revisions\/1420"}],"wp:attachment":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/media?parent=1419"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/categories?post=1419"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/tags?post=1419"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}