Nativescript-cli: Tns build android generates apk with old code Angular2 nativescript

Created on 21 Apr 2017  路  9Comments  路  Source: NativeScript/nativescript-cli

Please, provide the details below:

Did you verify this is a real problem by searching [Stack Overflow]

Yes. This was reported once here , but was supposed to be fixed.

Which platform(s) does your issue occur on?

Have checked this for android and it happens regularly.

Please provide the following version numbers that your issue occurs with:

  • CLI: 2.5.0
  • Cross-platform modules: 2.4.4
  • Runtime(s): "tns-android": {
    "version": "2.5.0"
    },
    "tns-ios": {
    "version": "2.5.0"
    }
  • Plugin(s):
    "dependencies": {
    "@angular/common": "2.3.1",
    "@angular/compiler": "2.3.1",
    "@angular/core": "2.3.1",
    "@angular/forms": "2.3.1",
    "@angular/http": "2.3.1",
    "@angular/platform-browser": "2.3.1",
    "@angular/platform-browser-dynamic": "2.3.1",
    "@angular/router": "3.3.1",
    "nativescript-angular": "1.3.0",
    "nativescript-dom": "^1.0.9",
    "nativescript-iqkeyboardmanager": "^1.0.1",
    "nativescript-loading-indicator": "^2.2.2",
    "nativescript-platform-css": "^1.4.0",
    "nativescript-plugin-firebase": "3.11.2",
    "nativescript-telerik-ui": "^1.6.1",
    "nativescript-theme-core": "^0.2.1",
    "reflect-metadata": "~0.1.8",
    "rxjs": "5.0.0-rc.4",
    "tns-core-modules": "2.4.4"
    },
    "devDependencies": {
    "babel-traverse": "6.22.1",
    "babel-types": "6.22.0",
    "babylon": "6.15.0",
    "lazy": "1.0.11",
    "nativescript-dev-android-snapshot": "^0..",
    "nativescript-dev-typescript": "^0.3.2",
    "typescript": "~2.0.10",
    "zone.js": "~0.7.2"
    }

Please tell us how to recreate the issue in as much detail as possible.

As mentioned after building the project once subsequent changes to the code are not reflected in future builds. As a workaround I clone into a new directory, install node modules and add platform again and the project builds fine from this directory.

bug android

Most helpful comment

Hey @anuragd7 ,
Thanks for the report and the description. In fact this issue is related to this one. The problem is that during livesync (tns run android), CLI copies project files to /data/loca/tmp/<appid>/ directory of the device. When the application is restarted, the files should be copied from the mentioned dir to the sandbox of the application. However, on some devices, we are unable to delete the files from /data/local/tmp/<appid> and after copying them to the sandbox, they remain there. Next time when you build .apk in debug mode and deploy it on device, once the application is started, it checks the /data/loca/tmp/<appid>/ for any files that have to be synced. It finds the old files (from your last livesync operation) and deploys gets them in the sandbox of the application. This overwrites the files included in the .apk and that's why you see an old version of your app. There are two ways to verify this is the problem:
1) Build an .apk in release mode and deploy it on device. When application is built in release, it will not check the /data/loca/tmp/<appid>/ directory and will not sync files from there.
2) Remove the /data/loca/tmp/<appid>/ from device. In order to do this, execute:

$ $ANDROID_HOME/platform-tools/adb shell
$ cd /data/local/tmp
$ rm -rf <your app id>

And deploy the built .apk again.

Can you try these and inform us if this workaround works on your side?

All 9 comments

Hey @anuragd7 ,
Thanks for the report and the description. In fact this issue is related to this one. The problem is that during livesync (tns run android), CLI copies project files to /data/loca/tmp/<appid>/ directory of the device. When the application is restarted, the files should be copied from the mentioned dir to the sandbox of the application. However, on some devices, we are unable to delete the files from /data/local/tmp/<appid> and after copying them to the sandbox, they remain there. Next time when you build .apk in debug mode and deploy it on device, once the application is started, it checks the /data/loca/tmp/<appid>/ for any files that have to be synced. It finds the old files (from your last livesync operation) and deploys gets them in the sandbox of the application. This overwrites the files included in the .apk and that's why you see an old version of your app. There are two ways to verify this is the problem:
1) Build an .apk in release mode and deploy it on device. When application is built in release, it will not check the /data/loca/tmp/<appid>/ directory and will not sync files from there.
2) Remove the /data/loca/tmp/<appid>/ from device. In order to do this, execute:

$ $ANDROID_HOME/platform-tools/adb shell
$ cd /data/local/tmp
$ rm -rf <your app id>

And deploy the built .apk again.

Can you try these and inform us if this workaround works on your side?

Closing due to inactivity.

This is a workaround right?. How about straight forward fix. is anyone working on it?

Hi @rajasekarsp

What is the issue you encounter, can you provide

  • More detailed description
  • Steps to reproduce
  • Version of nativescript, node, npm, android version of device/emulator you use
  • package.json of your project

Description

When I plug my phone in my system and do debugging, and then later when i install a different version of my app through apk stored in my memory card, it overwrites and gets installed. But after installation if i open the application, the application still retains the version which i have installed during debugging in computer.

Steps to reproduce:

  1. Plug your android device into system
  2. Do debugging of some app say "App1" with version 2.
  3. Plug out your phone and install version 1 of "App1" through apk from internal memory/sd card
  4. when you open the app you can only see App1 version 2.

Node version v6.10.2
Npm version v3.10.10
All android version

I've just experienced the same issue as @rajasekarsp where running tns run android followed by tns build android and then installing the built apk on the device doesn't overwrite previous files from the debug session. I can also confirm that @rosen-vladimirov's suggestion of building with the --release flag seems to mitigate the issue. Using tns 3.4.

in a debug app , i know that you have to remove the platform and build it for the apk to be updated

@devyaz that is unnecessary, tns build android will also produce a fresh APK. The original problem, and a workaround are described by Rosen - https://github.com/NativeScript/nativescript-cli/issues/2730#issuecomment-298851960

Closing as the issue seems not to be reproducible with the next and latest CLI.

Was this page helpful?
0 / 5 - 0 ratings