Skip to content

Commit a6d0c24

Browse files
committed
Speed up android livesync
1 parent 4db0a8e commit a6d0c24

File tree

4 files changed

+47
-13
lines changed

4 files changed

+47
-13
lines changed

lib/services/android-project-service.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
3030
private $npm: INodePackageManager,
3131
private $androidPluginBuildService: IAndroidPluginBuildService,
3232
private $platformEnvironmentRequirements: IPlatformEnvironmentRequirements,
33-
private $androidResourcesMigrationService: IAndroidResourcesMigrationService) {
33+
private $androidResourcesMigrationService: IAndroidResourcesMigrationService,
34+
private $filesHashService: IFilesHashService) {
3435
super($fs, $projectDataService);
3536
this.isAndroidStudioTemplate = false;
3637
}
@@ -332,6 +333,16 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
332333
message: "Gradle build..."
333334
})
334335
);
336+
337+
await this.generateHashes();
338+
}
339+
340+
private async generateHashes(): Promise<void> {
341+
const projectFilesPath = path.join(this._platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME);
342+
const files = this.$fs.enumerateFilesInDirectorySync(projectFilesPath);
343+
const hashes = await this.$filesHashService.generateHashes(files);
344+
const hashesFilePath = path.join(this._platformData.deviceBuildOutputPath, "hashes");
345+
this.$fs.writeJson(hashesFilePath, hashes);
335346
}
336347

337348
private getGradleBuildOptions(settings: IAndroidBuildOptionsSettings, projectData: IProjectData): Array<string> {

lib/services/livesync/android-device-livesync-sockets-service.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBa
106106
return transferredFiles;
107107
}
108108

109+
public getDeviceHashService(appIdentifier: string): Mobile.IAndroidDeviceHashService {
110+
const adb = this.$injector.resolve(DeviceAndroidDebugBridge, { identifier: this.device.deviceInfo.identifier });
111+
return this.$injector.resolve(AndroidDeviceHashService, { adb, appIdentifier });
112+
}
113+
109114
private async _transferFiles(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[]): Promise<Mobile.ILocalToDevicePathData[]> {
110115
await this.livesyncTool.sendFiles(localToDevicePaths.map(localToDevicePathData => localToDevicePathData.getLocalPath()));
111116

@@ -121,19 +126,19 @@ export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBa
121126
private async _transferDirectory(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectFilesPath: string): Promise<Mobile.ILocalToDevicePathData[]> {
122127
let transferredLocalToDevicePaths: Mobile.ILocalToDevicePathData[];
123128
const deviceHashService = this.getDeviceHashService(deviceAppData.appIdentifier);
124-
const currentShasums: IStringDictionary = await deviceHashService.generateHashesFromLocalToDevicePaths(localToDevicePaths);
125-
const oldShasums = await deviceHashService.getShasumsFromDevice();
129+
const currentHashes = await deviceHashService.generateHashesFromLocalToDevicePaths(localToDevicePaths);
130+
const oldHashes = await deviceHashService.getShasumsFromDevice();
126131

127-
if (this.$options.force || !oldShasums) {
132+
if (this.$options.force || !oldHashes) {
128133
await this.livesyncTool.sendDirectory(projectFilesPath);
129-
await deviceHashService.uploadHashFileToDevice(currentShasums);
134+
await deviceHashService.uploadHashFileToDevice(currentHashes);
130135
transferredLocalToDevicePaths = localToDevicePaths;
131136
} else {
132-
const changedShasums = deviceHashService.getChangedShasums(oldShasums, currentShasums);
137+
const changedShasums = deviceHashService.getChangedShasums(oldHashes, currentHashes);
133138
const changedFiles = _.keys(changedShasums);
134139
if (changedFiles.length) {
135140
await this.livesyncTool.sendFiles(changedFiles);
136-
await deviceHashService.uploadHashFileToDevice(currentShasums);
141+
await deviceHashService.uploadHashFileToDevice(currentHashes);
137142
transferredLocalToDevicePaths = localToDevicePaths.filter(localToDevicePathData => changedFiles.indexOf(localToDevicePathData.getLocalPath()) >= 0);
138143
} else {
139144
transferredLocalToDevicePaths = [];
@@ -150,9 +155,4 @@ export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBa
150155
appPlatformsPath: projectFilesPath
151156
});
152157
}
153-
154-
public getDeviceHashService(appIdentifier: string): Mobile.IAndroidDeviceHashService {
155-
const adb = this.$injector.resolve(DeviceAndroidDebugBridge, { identifier: this.device.deviceInfo.identifier });
156-
return this.$injector.resolve(AndroidDeviceHashService, { adb, appIdentifier });
157-
}
158158
}

lib/services/platform-service.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,8 @@ export class PlatformService extends EventEmitter implements IPlatformService {
481481

482482
await platformData.platformProjectService.cleanDeviceTempFolder(device.deviceInfo.identifier, projectData);
483483

484+
await this.uploadHashesToDevice(device, projectData, platformData);
485+
484486
await device.applicationManager.reinstallApplication(projectData.projectId, packageFile);
485487

486488
if (!buildConfig.release) {
@@ -496,6 +498,27 @@ export class PlatformService extends EventEmitter implements IPlatformService {
496498
this.$logger.out(`Successfully installed on device with identifier '${device.deviceInfo.identifier}'.`);
497499
}
498500

501+
private async uploadHashesToDevice(device: Mobile.IDevice, projectData: IProjectData, platformData: IPlatformData) {
502+
const isApplicationInstalled = await device.applicationManager.isApplicationInstalled(projectData.projectId);
503+
if (isApplicationInstalled) {
504+
const deviceAppData = {
505+
appIdentifier: projectData.projectId,
506+
device,
507+
platform: device.deviceInfo.platform,
508+
getDeviceProjectRootPath: () => this.$devicePathProvider.getDeviceProjectRootPath(device, { appIdentifier: projectData.projectId }),
509+
deviceSyncZipPath: this.$devicePathProvider.getDeviceSyncZipPath(device),
510+
isLiveSyncSupported: async () => true
511+
};
512+
await device.fileSystem.updateHashesOnDevice(deviceAppData, path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME));
513+
} else {
514+
const hashesFilePath = path.join(platformData.deviceBuildOutputPath, "hashes");
515+
if (this.$fs.exists(hashesFilePath)) {
516+
const hashes = this.$fs.readJson(hashesFilePath);
517+
await device.fileSystem.uploadHashesToDevice(hashes, projectData.projectId);
518+
}
519+
}
520+
}
521+
499522
public async deployPlatform(deployInfo: IDeployPlatformInfo): Promise<void> {
500523
await this.preparePlatform({
501524
platform: deployInfo.platform,

0 commit comments

Comments
 (0)