Skip to content

Commit 69bc287

Browse files
authored
Merge pull request #3419 from NativeScript/plamen5kov/fix-apk-search-dir
fix: find correct apk name when --release passed
2 parents 283b31c + 40f5074 commit 69bc287

File tree

8 files changed

+39
-22
lines changed

8 files changed

+39
-22
lines changed

lib/definitions/platform.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ interface IPlatformService extends IBuildPlatformAction, NodeJS.EventEmitter {
8181
* @param {string} @optional outputPath Directory containing build information and artifacts.
8282
* @returns {Promise<boolean>} true indicates that the application should be installed.
8383
*/
84-
shouldInstall(device: Mobile.IDevice, projectData: IProjectData, outputPath?: string): Promise<boolean>;
84+
shouldInstall(device: Mobile.IDevice, projectData: IProjectData, release: IRelease, outputPath?: string): Promise<boolean>;
8585

8686
/**
8787
* Determines whether the project should undergo the prepare process.
@@ -260,7 +260,7 @@ interface IPlatformData {
260260
projectRoot: string;
261261
normalizedPlatformName: string;
262262
appDestinationDirectoryPath: string;
263-
deviceBuildOutputPath: string;
263+
getDeviceBuildOutputPath(options: IRelease): string;
264264
emulatorBuildOutputPath?: string;
265265
getValidPackageNames(buildOptions: { isReleaseBuild?: boolean, isForDevice?: boolean }): string[];
266266
frameworkFilesExtensions: string[];

lib/definitions/project.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ interface IBuildForDevice {
142142
buildForDevice: boolean;
143143
}
144144

145+
interface IShouldInstall extends IBuildForDevice, IRelease {
146+
147+
}
148+
145149
interface INativePrepare {
146150
skipNativePrepare: boolean;
147151
}

lib/services/android-project-service.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
8383
platformProjectService: this,
8484
emulatorServices: this.$androidEmulatorServices,
8585
projectRoot: projectRoot,
86-
deviceBuildOutputPath: this.getDeviceBuildOutputPath(path.join(...deviceBuildOutputArr), projectData),
86+
getDeviceBuildOutputPath: (options: IRelease): string => {
87+
return this.getDeviceBuildOutputPath(path.join(...deviceBuildOutputArr), projectData, options);
88+
},
8789
getValidPackageNames: (buildOptions: { isReleaseBuild?: boolean, isForDevice?: boolean }): string[] => {
8890
const buildMode = buildOptions.isReleaseBuild ? Configurations.Release.toLowerCase() : Configurations.Debug.toLowerCase();
8991

@@ -106,10 +108,11 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
106108
return this._platformData;
107109
}
108110

109-
private getDeviceBuildOutputPath(currentPath: string, projectData: IProjectData): string {
111+
private getDeviceBuildOutputPath(currentPath: string, projectData: IProjectData, options: IRelease): string {
110112
const currentPlatformData: IDictionary<any> = this.$projectDataService.getNSValue(projectData.projectDir, constants.TNS_ANDROID_RUNTIME_NAME);
111113
const platformVersion = currentPlatformData && currentPlatformData[constants.VERSION_STRING];
112-
const normalizedPath = path.join(currentPath, "debug");
114+
const buildType = options.release === true ? "release" : "debug";
115+
const normalizedPath = path.join(currentPath, buildType);
113116

114117
if (semver.valid(platformVersion)) {
115118
const gradleAndroidPluginVersion3xx = "4.0.0";

lib/services/ios-project-service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
7171
platformProjectService: this,
7272
emulatorServices: this.$iOSEmulatorServices,
7373
projectRoot: projectRoot,
74-
deviceBuildOutputPath: path.join(projectRoot, "build", "device"),
74+
getDeviceBuildOutputPath: (options: IRelease): string => {
75+
return path.join(projectRoot, "build", "device");
76+
},
7577
emulatorBuildOutputPath: path.join(projectRoot, "build", "emulator"),
7678
getValidPackageNames: (buildOptions: { isReleaseBuild?: boolean, isForDevice?: boolean }): string[] => {
7779
if (buildOptions.isForDevice) {

lib/services/livesync/livesync-service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
413413

414414
await this.trackAction(action, platform, options);
415415

416-
const shouldInstall = await this.$platformService.shouldInstall(options.device, options.projectData, options.deviceBuildInfoDescriptor.outputPath);
416+
const shouldInstall = await this.$platformService.shouldInstall(options.device, options.projectData, options, options.deviceBuildInfoDescriptor.outputPath);
417417
if (shouldInstall) {
418418
await this.$platformService.installApplication(options.device, { release: false }, options.projectData, pathToBuildItem, options.deviceBuildInfoDescriptor.outputPath);
419419
appInstalledOnDeviceResult.appInstalled = true;

lib/services/platform-service.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ export class PlatformService extends EventEmitter implements IPlatformService {
333333

334334
const platformData = this.$platformsData.getPlatformData(platform, projectData);
335335
const forDevice = !buildConfig || buildConfig.buildForDevice;
336-
outputPath = outputPath || (forDevice ? platformData.deviceBuildOutputPath : platformData.emulatorBuildOutputPath || platformData.deviceBuildOutputPath);
336+
outputPath = outputPath || (forDevice ? platformData.getDeviceBuildOutputPath(buildConfig) : platformData.emulatorBuildOutputPath || platformData.getDeviceBuildOutputPath(buildConfig));
337337
if (!this.$fs.exists(outputPath)) {
338338
return true;
339339
}
@@ -433,15 +433,15 @@ export class PlatformService extends EventEmitter implements IPlatformService {
433433
this.$fs.writeJson(buildInfoFile, buildInfo);
434434
}
435435

436-
public async shouldInstall(device: Mobile.IDevice, projectData: IProjectData, outputPath?: string): Promise<boolean> {
436+
public async shouldInstall(device: Mobile.IDevice, projectData: IProjectData, release: IBuildConfig, outputPath?: string): Promise<boolean> {
437437
const platform = device.deviceInfo.platform;
438438
if (!(await device.applicationManager.isApplicationInstalled(projectData.projectId))) {
439439
return true;
440440
}
441441

442442
const platformData = this.$platformsData.getPlatformData(platform, projectData);
443443
const deviceBuildInfo: IBuildInfo = await this.getDeviceBuildInfo(device, projectData);
444-
const localBuildInfo = this.getBuildInfo(platform, platformData, { buildForDevice: !device.isEmulator }, outputPath);
444+
const localBuildInfo = this.getBuildInfo(platform, platformData, { buildForDevice: !device.isEmulator, release: release.release }, outputPath);
445445
return !localBuildInfo || !deviceBuildInfo || deviceBuildInfo.buildTime !== localBuildInfo.buildTime;
446446
}
447447

@@ -469,7 +469,9 @@ export class PlatformService extends EventEmitter implements IPlatformService {
469469

470470
if (!buildConfig.release) {
471471
const deviceFilePath = await this.getDeviceBuildInfoFilePath(device, projectData);
472-
const buildInfoFilePath = outputFilePath || this.getBuildOutputPath(device.deviceInfo.platform, platformData, { buildForDevice: !device.isEmulator });
472+
const options = buildConfig;
473+
options.buildForDevice = !device.isEmulator;
474+
const buildInfoFilePath = outputFilePath || this.getBuildOutputPath(device.deviceInfo.platform, platformData, options);
473475
const appIdentifier = projectData.projectId;
474476

475477
await device.fileSystem.putFile(path.join(buildInfoFilePath, buildInfoFileName), deviceFilePath, appIdentifier);
@@ -515,8 +517,8 @@ export class PlatformService extends EventEmitter implements IPlatformService {
515517
this.$logger.out("Skipping package build. No changes detected on the native side. This will be fast!");
516518
}
517519

518-
if (deployInfo.deployOptions.forceInstall || shouldBuild || (await this.shouldInstall(device, deployInfo.projectData))) {
519-
await this.installApplication(device, buildConfig, deployInfo.projectData, installPackageFile, deployInfo.outputPath);
520+
if (deployInfo.deployOptions.forceInstall || shouldBuild || (await this.shouldInstall(device, deployInfo.projectData, buildConfig))) {
521+
await this.installApplication(device, buildConfig, deployInfo.projectData);
520522
} else {
521523
this.$logger.out("Skipping install.");
522524
}
@@ -550,12 +552,12 @@ export class PlatformService extends EventEmitter implements IPlatformService {
550552
await this.$devicesService.execute(action, this.getCanExecuteAction(platform, runOptions));
551553
}
552554

553-
private getBuildOutputPath(platform: string, platformData: IPlatformData, options: IBuildForDevice): string {
555+
private getBuildOutputPath(platform: string, platformData: IPlatformData, options: IShouldInstall): string {
554556
if (platform.toLowerCase() === this.$devicePlatformsConstants.iOS.toLowerCase()) {
555-
return options.buildForDevice ? platformData.deviceBuildOutputPath : platformData.emulatorBuildOutputPath;
557+
return options.buildForDevice ? platformData.getDeviceBuildOutputPath(options) : platformData.emulatorBuildOutputPath;
556558
}
557559

558-
return platformData.deviceBuildOutputPath;
560+
return platformData.getDeviceBuildOutputPath(options);
559561
}
560562

561563
private async getDeviceBuildInfoFilePath(device: Mobile.IDevice, projectData: IProjectData): Promise<string> {
@@ -575,7 +577,7 @@ export class PlatformService extends EventEmitter implements IPlatformService {
575577
}
576578
}
577579

578-
private getBuildInfo(platform: string, platformData: IPlatformData, options: IBuildForDevice, buildOutputPath?: string): IBuildInfo {
580+
private getBuildInfo(platform: string, platformData: IPlatformData, options: IShouldInstall, buildOutputPath?: string): IBuildInfo {
579581
buildOutputPath = buildOutputPath || this.getBuildOutputPath(platform, platformData, options);
580582
const buildInfoFile = path.join(buildOutputPath, buildInfoFileName);
581583
if (this.$fs.exists(buildInfoFile)) {
@@ -765,11 +767,11 @@ export class PlatformService extends EventEmitter implements IPlatformService {
765767
}
766768

767769
public getLatestApplicationPackageForDevice(platformData: IPlatformData, buildConfig: IBuildConfig, outputPath?: string): IApplicationPackage {
768-
return this.getLatestApplicationPackage(outputPath || platformData.deviceBuildOutputPath, platformData.getValidPackageNames({ isForDevice: true, isReleaseBuild: buildConfig.release }));
770+
return this.getLatestApplicationPackage(outputPath || platformData.getDeviceBuildOutputPath(buildConfig), platformData.getValidPackageNames({ isForDevice: true, isReleaseBuild: buildConfig.release }));
769771
}
770772

771773
public getLatestApplicationPackageForEmulator(platformData: IPlatformData, buildConfig: IBuildConfig, outputPath?: string): IApplicationPackage {
772-
return this.getLatestApplicationPackage(outputPath || platformData.emulatorBuildOutputPath || platformData.deviceBuildOutputPath, platformData.getValidPackageNames({ isForDevice: false, isReleaseBuild: buildConfig.release }));
774+
return this.getLatestApplicationPackage(outputPath || platformData.emulatorBuildOutputPath || platformData.getDeviceBuildOutputPath(buildConfig), platformData.getValidPackageNames({ isForDevice: false, isReleaseBuild: buildConfig.release }));
773775
}
774776

775777
private async updatePlatform(platform: string, version: string, platformTemplate: string, projectData: IProjectData, config: IPlatformOptions): Promise<void> {

test/platform-commands.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ class PlatformData implements IPlatformData {
3535
};
3636
emulatorServices: Mobile.IEmulatorPlatformServices = null;
3737
projectRoot = "";
38-
deviceBuildOutputPath = "";
38+
getDeviceBuildOutputPath = (buildTypeOption: IRelease) => {
39+
return "";
40+
}
3941
getValidPackageNames = (buildOptions: { isForDevice?: boolean, isReleaseBuild?: boolean }) => [""];
4042
validPackageNamesForDevice: string[] = [];
4143
frameworkFilesExtensions = [".jar", ".dat"];

test/stubs.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,9 @@ export class PlatformProjectServiceStub extends EventEmitter implements IPlatfor
304304
platformProjectService: this,
305305
emulatorServices: undefined,
306306
projectRoot: "",
307-
deviceBuildOutputPath: "",
307+
getDeviceBuildOutputPath: (buildTypeOption: IRelease) => {
308+
return "";
309+
},
308310
getValidPackageNames: (buildOptions: { isForDevice?: boolean, isReleaseBuild?: boolean }) => [],
309311
frameworkFilesExtensions: [],
310312
appDestinationDirectoryPath: "",
@@ -415,7 +417,9 @@ export class PlatformsDataStub extends EventEmitter implements IPlatformsData {
415417
projectRoot: "",
416418
normalizedPlatformName: "",
417419
appDestinationDirectoryPath: "",
418-
deviceBuildOutputPath: "",
420+
getDeviceBuildOutputPath: (buildTypeOption: IRelease) => {
421+
return "";
422+
},
419423
getValidPackageNames: (buildOptions: { isForDevice?: boolean, isReleaseBuild?: boolean }) => [],
420424
frameworkFilesExtensions: [],
421425
relativeToFrameworkConfigurationFilePath: "",

0 commit comments

Comments
 (0)