NativeScript: Keeping your AndroidManifest.xml easily editable and under version control.

So here I was again minding my own business on the forums again, and Ben posted he had been attempting to use this new feature of v1.5.x of NativeScript and it was failing.  I responded it didn't work like that.   Thankfully he was persistent and ignored my wrong response, and linked to the github issue a second time where they discuss the new feature.   Him, being persistent despite me telling him it doesn't work that way; is why we now have a way to make it work!   So thank you Ben!

So I went and looked at the new feature and found that by default it doesn't work as a normal person would expect.    It does exactly what I expected and why I said it doesn't work.    However, I decided to see if I could make it work the way any sane person would want it to and guess what, I have a method to make this work perfectly.

To make this work properly;  you need NativeScript v1.5.1 or later; so type tns --version and make sure you are running v1.5.1 and later, if not upgrade.

WARNING: changing things in your platforms folder can completely break your build; and if you totally break your build you can do a tns platform remove android and then a tns platform add android to reset it.

First, you will need to navigate to your /platforms/android/src/main and copy the AndroidManifest.xml file to your /app/App_Resources/Android/ folder.   This is going to be your primary manifest and the one you will edit to your hearts desire.  Make sure you COPY just your app manifest.

Next you will need to edit the /platforms/android/src/main/AndroidManifest.xml and basically deleted everything in it.   This file should end up looking like this:

<?xml version="1.0" encoding="utf-8"?>
<manifest  xmlns:android="http://schemas.android.com/apk/res/android"
package="YOUR_APP_PACKAGE" >
</manifest>

Do not copy the above as is; you need to make sure the "package" property contains your app package name, which is why I recommend you edit the one in their as it already has your app package in it.  If you copy the example above, it has YOUR_APP_PACKAGE which is an invalid package name.

Because the manifests are merged; and since the package name doesn't change the merging system is able to merge everything in your brand new App_Resources/Android/AndroidManifest.xml into the original AndroidManifest.xml file without any conflicts!

 

 

2 comments

  1. thank you.. your solution worked for me.
    I was facing an issue as "Project successfully built
    The system failed to delete the package for an unspecified reason.
    The package archive file is invalid."

    I removed and re installed android platform and my project worked fine. thanks (Y)

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.