Skip to main content

Adding Tags To Android Manifest File For Ionic / Cordova Apps

Share on FacebookTweet about this on TwitterShare on Google+Share on RedditShare on StumbleUponDigg thisFlattr the authorPin on PinterestShare on TumblrShare on LinkedInPrint this pageBuffer this page

In this post we will take a look at how you can edit the AndroidManifest file the correct way for your Ionic / Cordova apps while building for Android.

There are times when you need to edit the platform specific files in your project. This is perfectly normal. In fact, there are some plugins that you can only use if you edit the platform specific files, for example, the diagnostic plugin.

The problem with directly editing platform specific files is that these files are dynamically generated and often times need to be regenerated. Which means that you will have to keep track of all the edits that you did. This is a nightmare when it comes to maintaining your app in a team environment, also it is hard to maintain such apps over time.

For example, when editing the AndroidManifest.xml file, which is generated when we add android platform using the ionic cordova platform add android command. Now, if you remove the platform or update the platform to a newer version then the file will be created again and all the changes that you did will be lost.

As most of our configuration is in the config.xml file, it is natural to have other platform-specific configuration here as well.

In this example, we will take a look at how you can add a permissions tag to the AndroidManifest.xml file. You can edit other platform specific file as well. Also you can edit iOS files too. But I will be covering just Android and the AndroidManifest file in this post.

 

Step 1)

We will create a new project. You can work with the existing one. But, for the sake of being through I will create a new project running the following command.

For Cordova, you can use the following command.

 

Step 2)

Now we need to open up our config.xml file and make the following changes to the widget tag.

Here we have added the namespace for android so that we do not get an error.

Also, inside the config file, we will add the following code.

As you can see that we are using the config-file tag to add the user-permission tag to request for camera access. The above code will add the user-permission tag to the AndroidManifest.xml as we have target="AndroidManifest.xml" attribute. Also, we have parent="/manifest" attribute will place our user-permission inside the <manifest> tag of AndroidManifest.xml .

 

Step 3)

Now it’s time to check the code in action. The config file setting are applied during the prepare process. So you can just runĀ  cordova prepare to see that the user-permission tag has been added to the specified target.

Alternatively, you can run the build command as well which will execute the prepare command internally.

 

Conclusion

As you saw in this post, we can easily add tags to the AndroidManifest.xml file. You can do that for most platform files. There are times when this method will not be adequate for your needs, for that you can use the cordova-custom-config plugin. Check out the docs here to know more about when to use the plugin.

 

 

 

Consider Subscribing / Donating
Subscribe To Mailing List
Donate
If my site was helpful to you, then please consider donating via paypal:

Prantik Vaghela (pointdeveloper)

Hi my name is Prantik Vaghela. I have done my Bachelors and Masters in Computer Science and am a web developer and now a Tutor through my blog. :-)

%d bloggers like this: