diff --git a/lib/services/livesync/android-device-livesync-service.ts b/lib/services/livesync/android-device-livesync-service.ts index bf1c0edbd9..b50a35513e 100644 --- a/lib/services/livesync/android-device-livesync-service.ts +++ b/lib/services/livesync/android-device-livesync-service.ts @@ -36,14 +36,25 @@ export class AndroidDeviceLiveSyncService extends DeviceLiveSyncServiceBase impl `${deviceProjectRootDirname}/sync`] ); + await this.reloadResources(deviceAppData, localToDevicePaths); + const canExecuteFastSync = !liveSyncInfo.isFullSync && !_.some(localToDevicePaths, (localToDevicePath: Mobile.ILocalToDevicePathData) => !this.canExecuteFastSync(localToDevicePath.getLocalPath(), projectData, this.device.deviceInfo.platform)); - if (canExecuteFastSync) { - return this.reloadPage(deviceAppData, localToDevicePaths); + if (!canExecuteFastSync) { + return this.restartApplication(deviceAppData); } + } + + private async cleanLivesyncDirectories(deviceAppData: Mobile.IDeviceAppData): Promise { + const deviceRootPath = await this.$devicePathProvider.getDeviceProjectRootPath(deviceAppData.device, { + appIdentifier: deviceAppData.appIdentifier, + getDirname: true + }); - return this.restartApplication(deviceAppData); + await this.device.adb.executeShellCommand(["rm", "-rf", await this.$mobileHelper.buildDevicePath(deviceRootPath, LiveSyncPaths.FULLSYNC_DIR_NAME), + this.$mobileHelper.buildDevicePath(deviceRootPath, LiveSyncPaths.SYNC_DIR_NAME), + await this.$mobileHelper.buildDevicePath(deviceRootPath, LiveSyncPaths.REMOVEDSYNC_DIR_NAME)]); } private async restartApplication(deviceAppData: Mobile.IDeviceAppData): Promise { @@ -70,15 +81,16 @@ export class AndroidDeviceLiveSyncService extends DeviceLiveSyncServiceBase impl await this.device.adb.executeShellCommand(["rm", "-f", deviceRootPath]); } - this.device.adb.executeShellCommand(["rm", "-rf", this.$mobileHelper.buildDevicePath(deviceRootPath, LiveSyncPaths.FULLSYNC_DIR_NAME), - this.$mobileHelper.buildDevicePath(deviceRootPath, LiveSyncPaths.SYNC_DIR_NAME), - await this.$mobileHelper.buildDevicePath(deviceRootPath, LiveSyncPaths.REMOVEDSYNC_DIR_NAME)]); + await this.cleanLivesyncDirectories(deviceAppData); } - private async reloadPage(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[]): Promise { + private async reloadResources(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[]): Promise { await this.device.adb.executeCommand(["forward", `tcp:${AndroidDeviceLiveSyncService.BACKEND_PORT.toString()}`, `localabstract:${deviceAppData.appIdentifier}-livesync`]); - if (!await this.sendPageReloadMessage()) { - await this.restartApplication(deviceAppData); + + if (await this.sendPageReloadMessage()) { + await this.cleanLivesyncDirectories(deviceAppData); + } else { + await this.restartApplication(deviceAppData); //in case runtime socket error/close } } diff --git a/lib/services/livesync/platform-livesync-service-base.ts b/lib/services/livesync/platform-livesync-service-base.ts index c8beb26240..298d34c902 100644 --- a/lib/services/livesync/platform-livesync-service-base.ts +++ b/lib/services/livesync/platform-livesync-service-base.ts @@ -91,7 +91,7 @@ export abstract class PlatformLiveSyncServiceBase { modifiedLocalToDevicePaths.push(...localToDevicePaths); const deviceLiveSyncService = this.getDeviceLiveSyncService(device, projectData.projectId); - deviceLiveSyncService.removeFiles(deviceAppData, localToDevicePaths); + await deviceLiveSyncService.removeFiles(deviceAppData, localToDevicePaths); } return {