Files in file system removed when updating Android app


Hi. I have an app in the Android Play store that has some files bundled with it in sub folders inside the app folder. These files can be updated or new files added by the app users. I am about to release an update and while testing realised new files were being removed and updated files overwritten to their default version.

I’ve tried various ways of retaining the files including removing these folders from the new version and writing some code to only create these folders if they don’t already exists but this doesn’t work either.

I’ve also tried to find any reference to this in the documentation and the internet but no luck.

I’ve tested the update process in two ways…

  1. Using Airdroid to first install the original and then, after making changes, install the update on a physical device
  2. Using the Genymotion emulator I drag the original APK onto the emulator and then, after making changes, the updated APK

In both casses it’s as if the updated APK is being installed for the first time.

Any info or suggestions would be a huge help. Thanks!


Hey @stevegardner

We added that logic as a safeguard against caching previous, incompatible versions of the application/runtime files. At the time I was not aware of other use cases, where files need to actually be retained.

The logic where the removal happens is inside the RuntimeHelper, located inside your project’s platforms/android/src/main/java directory. You could edit the following boolean flag to false before building your release APK and releasing the app. -

PR with the change and reasoning behind it -


Hi Pete

Thanks so much for your prompt reply! I’ve implemented your suggestion and it sorted the issue out.

It’s a very hacky solution and prone to be missed when updating the platform code. What would you suggest as a better approach to avoid having to manually manipulate core code?


I don’t think there is a “right” way currently. Perhaps you could try saving the files to a directory above app/, where appName/files are, since that location does not have any special handling. Only files/app, files/internal, and files/metadata.

If that’s not feasible, you could download the NativeScript Android runtime from npm, make the modifications, and install the platform from the local installation, you might have to extract and save the tns-android package not managed by npm or a version control software, to make it persistent, perhaps in a directory next to node_modules and app in your project folder. Depending on the npm version, you may have to edit the tns-android json and remove all the npm meta information. This will prevent npm from using a cached tgz in place of your modified runtime package. At least that is how I’d do it:

npm i tns-android --save-dev

Modify tns-android/..../.../

Modify the tns-android/package.json to contain only the following:

  "name": "tns-android",
  "version": "3.3.0-10.10.modified"

(Optional) mv node_modules/tns-android .

tns platform add android --framework-path <path to the local copy of the runtime> (./tns-android)


Thanks Pete. That gives me some direction. At least now I have some time to plan a refactor.