CLI LiveSync command conflicts with Android Studio
tns livesync android command creates a folder with the name of the package (ex. org.nativescript.TNSApp) in /data/local/tmp directory on the device:
shell@hammerhead:/data/local/tmp $ ls -l
drwxrwxrwx shell shell 2015-10-19 02:20 org.nativescript.TNSApp
After that if you try to run the same project on the same device by Android Studio, it tries to create a file with the same name and fails with:
Waiting for device.
Target device: lge-nexus_5-0925b76e031fa5f5
Uploading file
local path: /Work/TNS_App/platforms/android/build/outputs/apk/TNSApp-debug.apk
remote path: /data/local/tmp/org.nativescript.TNSApp
Adb Transfer Protocol Error.
Is a directory
As a result you are not able to run the project until you delete the folder in /data/local/tmp.
The opposite scenario: when successfully run the application by Android Studio, it creates a file with the name of the package (ex. org.nativescript.TNSApp) in /data/local/tmp directory on the device:
shell@hammerhead:/data/local/tmp $ ls -l
-rw-rw-rw- shell shell 9612872 2015-10-19 14:47 org.nativescript.TNSApp
After that if you try to execute tns livesync android command will not manage to sync the changes because it needs to create a folder with the name of the package in /data/local/tmp directory on the device.
As a result the livesync command does not work anymore until you you delete the file in /data/local/tmp.
I've done some research how best to fix this. If we rename the on-device path, we have to extensively refactor all AppBuilder clients keeping backwards and forwards compatibility.
Therefore, I propose to enhance the LiveSync process by letting android runtime delete the files at the end of livesync. So far these approaches were discussed:
- The CLI gives proper permissions on /data/local/tmp, and the runtime moves the temporary files and deletes the offending directory. This may not be possible on SELinux enabled devices, particularly Samsung Lollipop ones.
- The runtime signals the CLI that it has finished moving the files into the app private directory. The CLI deletes the offending directory.
At any rate, this bug is not critical and I postponed it for 1.6.
One caveat is that while the livesync is running we are taking up the name from Android Studio. Livesync is a "lengthy" running command. I think that's not big of a deal....
The scenario when the application runs by Android Studio, creates a file with the name of the package in /data/local/tmp directory and then tns livesync android command fail due to this file is fixed by https://github.com/NativeScript/nativescript-cli/pull/1560.
I need to delete the directory, as suggested, but I cannot access /data/local... does the device need to be rooted to do so?