Skip to content

Commit 5a692f2

Browse files
committed
fix: fix multiple installation on device when there is native java code in some plugin
When there is native java code in some plugin, CLI rebuilt the .aar file. As there is a watcher that watches the .aar file, CLI decides that there is a native change.
1 parent ed42427 commit 5a692f2

File tree

5 files changed

+35
-4
lines changed

5 files changed

+35
-4
lines changed

lib/bootstrap.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,4 +223,6 @@ $injector.require("applePortalSessionService", "./services/apple-portal/apple-po
223223
$injector.require("applePortalCookieService", "./services/apple-portal/apple-portal-cookie-service");
224224
$injector.require("applePortalApplicationService", "./services/apple-portal/apple-portal-application-service");
225225

226+
$injector.require("watchIgnoreListService", "./services/watch-ignore-list-service");
227+
226228
$injector.requirePublicClass("initializeService", "./services/initialize-service");

lib/controllers/prepare-controller.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ export class PrepareController extends EventEmitter {
2525
private $prepareNativePlatformService: IPrepareNativePlatformService,
2626
private $projectChangesService: IProjectChangesService,
2727
private $projectDataService: IProjectDataService,
28-
private $webpackCompilerService: IWebpackCompilerService
28+
private $webpackCompilerService: IWebpackCompilerService,
29+
private $watchIgnoreListService: IWatchIgnoreListService
2930
) { super(); }
3031

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

138143
this.watchersData[projectData.projectDir][platformData.platformNameLowerCase].nativeFilesWatcher = watcher;

lib/declarations.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,4 +1049,10 @@ interface IPlatformCommandHelper {
10491049
getAvailablePlatforms(projectData: IProjectData): string[];
10501050
getPreparedPlatforms(projectData: IProjectData): string[];
10511051
getCurrentPlatformVersion(platform: string, projectData: IProjectData): string;
1052+
}
1053+
1054+
interface IWatchIgnoreListService {
1055+
addFileToIgnoreList(filePath: string): void;
1056+
removeFileFromIgnoreList(filePath: string): void;
1057+
isFileInIgnoreList(filePath: string): boolean;
10521058
}

lib/services/android-plugin-build-service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService {
2020
private $errors: IErrors,
2121
private $filesHashService: IFilesHashService,
2222
public $hooksService: IHooksService,
23-
private $injector: IInjector
23+
private $injector: IInjector,
24+
private $watchIgnoreListService: IWatchIgnoreListService
2425
) { }
2526

2627
private static MANIFEST_ROOT = {
@@ -189,6 +190,7 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService {
189190
this.copySourceSetDirectories(androidSourceDirectories, pluginTempMainSrcDir);
190191
await this.setupGradle(pluginTempDir, options.platformsAndroidDirPath, options.projectDir);
191192
await this.buildPlugin({ pluginDir: pluginTempDir, pluginName: options.pluginName });
193+
this.$watchIgnoreListService.addFileToIgnoreList(path.join(options.aarOutputDir, `${shortPluginName}.aar`));
192194
this.copyAar(shortPluginName, pluginTempDir, options.aarOutputDir);
193195
this.writePluginHashInfo(pluginSourceFileHashesInfo, pluginTempDir);
194196
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export class WatchIgnoreListService implements IWatchIgnoreListService {
2+
private ignoreMap: IDictionary<boolean> = {};
3+
4+
public addFileToIgnoreList(filePath: string): void {
5+
this.ignoreMap[filePath] = true;
6+
}
7+
8+
public removeFileFromIgnoreList(filePath: string): void {
9+
this.ignoreMap[filePath] = false;
10+
}
11+
12+
public isFileInIgnoreList(filePath: string): boolean {
13+
return !!this.ignoreMap[filePath];
14+
}
15+
}
16+
$injector.register("watchIgnoreListService", WatchIgnoreListService);

0 commit comments

Comments
 (0)