Skip to content

fix: fix multiple installation on android device #4773

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,6 @@ $injector.require("applePortalSessionService", "./services/apple-portal/apple-po
$injector.require("applePortalCookieService", "./services/apple-portal/apple-portal-cookie-service");
$injector.require("applePortalApplicationService", "./services/apple-portal/apple-portal-application-service");

$injector.require("watchIgnoreListService", "./services/watch-ignore-list-service");

$injector.requirePublicClass("initializeService", "./services/initialize-service");
11 changes: 8 additions & 3 deletions lib/controllers/prepare-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export class PrepareController extends EventEmitter {
private $prepareNativePlatformService: IPrepareNativePlatformService,
private $projectChangesService: IProjectChangesService,
private $projectDataService: IProjectDataService,
private $webpackCompilerService: IWebpackCompilerService
private $webpackCompilerService: IWebpackCompilerService,
private $watchIgnoreListService: IWatchIgnoreListService
) { super(); }

@performanceLog()
Expand Down Expand Up @@ -131,8 +132,12 @@ export class PrepareController extends EventEmitter {
const watcher = choki.watch(patterns, watcherOptions)
.on("all", async (event: string, filePath: string) => {
filePath = path.join(projectData.projectDir, filePath);
this.$logger.trace(`Chokidar raised event ${event} for ${filePath}.`);
this.emitPrepareEvent({ files: [], hasOnlyHotUpdateFiles: false, hmrData: null, hasNativeChanges: true, platform: platformData.platformNameLowerCase });
if (this.$watchIgnoreListService.isFileInIgnoreList(filePath)) {
this.$watchIgnoreListService.removeFileFromIgnoreList(filePath);
} else {
this.$logger.info(`Chokidar raised event ${event} for ${filePath}.`);
this.emitPrepareEvent({ files: [], hasOnlyHotUpdateFiles: false, hmrData: null, hasNativeChanges: true, platform: platformData.platformNameLowerCase });
}
});

this.watchersData[projectData.projectDir][platformData.platformNameLowerCase].nativeFilesWatcher = watcher;
Expand Down
18 changes: 8 additions & 10 deletions lib/controllers/run-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { cache, performanceLog } from "../common/decorators";
import { EventEmitter } from "events";

export class RunController extends EventEmitter implements IRunController {
private rebuiltInformation: IDictionary<{ packageFilePath: string, platform: string, isEmulator: boolean }> = { };

constructor(
protected $analyticsService: IAnalyticsService,
private $buildController: IBuildController,
Expand Down Expand Up @@ -246,7 +244,7 @@ export class RunController extends EventEmitter implements IRunController {
}

private async syncInitialDataOnDevices(projectData: IProjectData, liveSyncInfo: ILiveSyncInfo, deviceDescriptors: ILiveSyncDeviceDescriptor[]): Promise<void> {
this.rebuiltInformation = {};
const rebuiltInformation: IDictionary<{ packageFilePath: string, platform: string, isEmulator: boolean }> = { };

const deviceAction = async (device: Mobile.IDevice) => {
const deviceDescriptor = _.find(deviceDescriptors, dd => dd.identifier === device.deviceInfo.identifier);
Expand All @@ -267,14 +265,14 @@ export class RunController extends EventEmitter implements IRunController {

// Case where we have three devices attached, a change that requires build is found,
// we'll rebuild the app only for the first device, but we should install new package on all three devices.
if (this.rebuiltInformation[platformData.platformNameLowerCase] && (this.$mobileHelper.isAndroidPlatform(platformData.platformNameLowerCase) || this.rebuiltInformation[platformData.platformNameLowerCase].isEmulator === device.isEmulator)) {
packageFilePath = this.rebuiltInformation[platformData.platformNameLowerCase].packageFilePath;
if (rebuiltInformation[platformData.platformNameLowerCase] && (this.$mobileHelper.isAndroidPlatform(platformData.platformNameLowerCase) || rebuiltInformation[platformData.platformNameLowerCase].isEmulator === device.isEmulator)) {
packageFilePath = rebuiltInformation[platformData.platformNameLowerCase].packageFilePath;
await this.$deviceInstallAppService.installOnDevice(device, buildData, packageFilePath);
} else {
const shouldBuild = prepareResultData.hasNativeChanges || await this.$buildController.shouldBuild(buildData);
if (shouldBuild) {
packageFilePath = await deviceDescriptor.buildAction();
this.rebuiltInformation[platformData.platformNameLowerCase] = { isEmulator: device.isEmulator, platform: platformData.platformNameLowerCase, packageFilePath };
rebuiltInformation[platformData.platformNameLowerCase] = { isEmulator: device.isEmulator, platform: platformData.platformNameLowerCase, packageFilePath };
} else {
await this.$analyticsService.trackEventActionInGoogleAnalytics({
action: TrackActionNames.LiveSync,
Expand Down Expand Up @@ -315,7 +313,7 @@ export class RunController extends EventEmitter implements IRunController {
}

private async syncChangedDataOnDevices(data: IFilesChangeEventData, projectData: IProjectData, liveSyncInfo: ILiveSyncInfo, deviceDescriptors: ILiveSyncDeviceDescriptor[]): Promise<void> {
this.rebuiltInformation = {};
const rebuiltInformation: IDictionary<{ packageFilePath: string, platform: string, isEmulator: boolean }> = { };

const deviceAction = async (device: Mobile.IDevice) => {
const deviceDescriptor = _.find(deviceDescriptors, dd => dd.identifier === device.deviceInfo.identifier);
Expand Down Expand Up @@ -343,14 +341,14 @@ export class RunController extends EventEmitter implements IRunController {
const deviceAppData = await platformLiveSyncService.getAppData(_.merge({ device, watch: true }, watchInfo));

if (data.hasNativeChanges) {
const rebuiltInfo = this.rebuiltInformation[platformData.platformNameLowerCase] && (this.$mobileHelper.isAndroidPlatform(platformData.platformNameLowerCase) || this.rebuiltInformation[platformData.platformNameLowerCase].isEmulator === device.isEmulator);
const rebuiltInfo = rebuiltInformation[platformData.platformNameLowerCase] && (this.$mobileHelper.isAndroidPlatform(platformData.platformNameLowerCase) || rebuiltInformation[platformData.platformNameLowerCase].isEmulator === device.isEmulator);
if (!rebuiltInfo) {
await this.$prepareNativePlatformService.prepareNativePlatform(platformData, projectData, prepareData);
await deviceDescriptor.buildAction();
this.rebuiltInformation[platformData.platformNameLowerCase] = { isEmulator: device.isEmulator, platform: platformData.platformNameLowerCase, packageFilePath: null };
rebuiltInformation[platformData.platformNameLowerCase] = { isEmulator: device.isEmulator, platform: platformData.platformNameLowerCase, packageFilePath: null };
}

await this.$deviceInstallAppService.installOnDevice(device, deviceDescriptor.buildData, this.rebuiltInformation[platformData.platformNameLowerCase].packageFilePath);
await this.$deviceInstallAppService.installOnDevice(device, deviceDescriptor.buildData, rebuiltInformation[platformData.platformNameLowerCase].packageFilePath);
await platformLiveSyncService.syncAfterInstall(device, watchInfo);
await platformLiveSyncService.restartApplication(projectData, { deviceAppData, modifiedFilesData: [], isFullSync: false, useHotModuleReload: liveSyncInfo.useHotModuleReload });
} else {
Expand Down
6 changes: 6 additions & 0 deletions lib/declarations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1049,4 +1049,10 @@ interface IPlatformCommandHelper {
getAvailablePlatforms(projectData: IProjectData): string[];
getPreparedPlatforms(projectData: IProjectData): string[];
getCurrentPlatformVersion(platform: string, projectData: IProjectData): string;
}

interface IWatchIgnoreListService {
addFileToIgnoreList(filePath: string): void;
removeFileFromIgnoreList(filePath: string): void;
isFileInIgnoreList(filePath: string): boolean;
}
4 changes: 3 additions & 1 deletion lib/services/android-plugin-build-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService {
private $errors: IErrors,
private $filesHashService: IFilesHashService,
public $hooksService: IHooksService,
private $injector: IInjector
private $injector: IInjector,
private $watchIgnoreListService: IWatchIgnoreListService
) { }

private static MANIFEST_ROOT = {
Expand Down Expand Up @@ -189,6 +190,7 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService {
this.copySourceSetDirectories(androidSourceDirectories, pluginTempMainSrcDir);
await this.setupGradle(pluginTempDir, options.platformsAndroidDirPath, options.projectDir);
await this.buildPlugin({ pluginDir: pluginTempDir, pluginName: options.pluginName });
this.$watchIgnoreListService.addFileToIgnoreList(path.join(options.aarOutputDir, `${shortPluginName}.aar`));
this.copyAar(shortPluginName, pluginTempDir, options.aarOutputDir);
this.writePluginHashInfo(pluginSourceFileHashesInfo, pluginTempDir);
}
Expand Down
16 changes: 16 additions & 0 deletions lib/services/watch-ignore-list-service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export class WatchIgnoreListService implements IWatchIgnoreListService {
private ignoreMap: IDictionary<boolean> = {};

public addFileToIgnoreList(filePath: string): void {
this.ignoreMap[filePath] = true;
}

public removeFileFromIgnoreList(filePath: string): void {
this.ignoreMap[filePath] = false;
}

public isFileInIgnoreList(filePath: string): boolean {
return !!this.ignoreMap[filePath];
}
}
$injector.register("watchIgnoreListService", WatchIgnoreListService);
5 changes: 5 additions & 0 deletions test/controllers/prepare-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ function createTestInjector(data: { hasNativeChanges: boolean }): IInjector {
getProductionDependencies: () => (<any>[])
});

injector.register("watchIgnoreListService", {
addFileToIgnoreList: () => ({}),
isFileInIgnoreList: () => false
});

const prepareController: PrepareController = injector.resolve("prepareController");
prepareController.emit = (eventName: string, eventData: any) => {
emittedEventNames.push(eventName);
Expand Down
4 changes: 4 additions & 0 deletions test/services/android-plugin-build-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ describe('androidPluginBuildService', () => {
hasChangesInShasums: (oldHashes: IStringDictionary, newHashes: IStringDictionary): boolean => !!options.hasChangesInShasums
});

testInjector.register("watchIgnoreListService", {
addFileToIgnoreList: () => ({})
});

fs = testInjector.resolve("fs");
androidBuildPluginService = testInjector.resolve<AndroidPluginBuildService>(AndroidPluginBuildService);
}
Expand Down