Skip to content

Commit 56c72a4

Browse files
committed
Fix prepare for android when building with webpack
When switching between release, debug and bundle builds, the android build artifacts should be cleaned. fixes NativeScript/android#759
1 parent 756af30 commit 56c72a4

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

lib/services/platform-service.ts

+21-9
Original file line numberDiff line numberDiff line change
@@ -239,16 +239,9 @@ export class PlatformService extends EventEmitter implements IPlatformService {
239239
this.$logger.trace("Changes info in prepare platform:", changesInfo);
240240

241241
if (changesInfo.hasChanges) {
242-
// android build artifacts need to be cleaned up when switching from release to debug builds
243-
if (platform.toLowerCase() === "android") {
244-
let previousPrepareInfo = this.$projectChangesService.getPrepareInfo(platform, projectData);
245-
// clean up prepared plugins when not building for release
246-
if (previousPrepareInfo && previousPrepareInfo.release !== appFilesUpdaterOptions.release) {
247-
await platformData.platformProjectService.cleanProject(platformData.projectRoot, projectData);
248-
}
249-
}
250-
242+
await this.cleanProject(platform, appFilesUpdaterOptions, platformData, projectData);
251243
await this.preparePlatformCore(platform, appFilesUpdaterOptions, projectData, platformSpecificData, changesInfo, filesToSync);
244+
252245
this.$projectChangesService.savePrepareInfo(platform, projectData);
253246
} else {
254247
this.$logger.out("Skipping prepare.");
@@ -275,6 +268,25 @@ export class PlatformService extends EventEmitter implements IPlatformService {
275268
}
276269
}
277270

271+
private async cleanProject(platform: string, appFilesUpdaterOptions: IAppFilesUpdaterOptions, platformData: IPlatformData, projectData: IProjectData): Promise<void> {
272+
// android build artifacts need to be cleaned up
273+
// when switching between debug, release and webpack builds
274+
if (platform.toLowerCase() !== "android") {
275+
return;
276+
}
277+
278+
const previousPrepareInfo = this.$projectChangesService.getPrepareInfo(platform, projectData);
279+
if (!previousPrepareInfo) {
280+
return;
281+
}
282+
283+
const { release: previousWasRelease, bundle: previousWasBundle } = previousPrepareInfo;
284+
const { release: currentIsRelease, bundle: currentIsBundle } = appFilesUpdaterOptions;
285+
if ((previousWasRelease !== currentIsRelease) || (previousWasBundle !== currentIsBundle)) {
286+
await platformData.platformProjectService.cleanProject(platformData.projectRoot, projectData);
287+
}
288+
}
289+
278290
/* Hooks are expected to use "filesToSync" parameter, as to give plugin authors additional information about the sync process.*/
279291
@helpers.hook('prepare')
280292
private async preparePlatformCore(platform: string, appFilesUpdaterOptions: IAppFilesUpdaterOptions, projectData: IProjectData, platformSpecificData: IPlatformSpecificData, changesInfo?: IProjectChangesInfo, filesToSync?: Array<String>): Promise<void> {

0 commit comments

Comments
 (0)