Skip to content

Commit bcd794e

Browse files
authored
Merge pull request #3367 from NativeScript/plamen5kov/update-find-apk-logic
refactor: add logic for finding apk name
2 parents 853eff6 + 427683e commit bcd794e

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

lib/services/android-project-service.ts

+19-2
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,15 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
8282
platformProjectService: this,
8383
emulatorServices: this.$androidEmulatorServices,
8484
projectRoot: projectRoot,
85-
deviceBuildOutputPath: path.join(...deviceBuildOutputArr),
85+
deviceBuildOutputPath: this.getDeviceBuildOutputPath(path.join(...deviceBuildOutputArr), projectData),
8686
getValidPackageNames: (buildOptions: { isReleaseBuild?: boolean, isForDevice?: boolean }): string[] => {
8787
const buildMode = buildOptions.isReleaseBuild ? Configurations.Release.toLowerCase() : Configurations.Debug.toLowerCase();
8888

8989
return [
9090
`${packageName}-${buildMode}.apk`,
9191
`${projectData.projectName}-${buildMode}.apk`,
92-
`${projectData.projectName}.apk`
92+
`${projectData.projectName}.apk`,
93+
`app-${buildMode}.apk`
9394
];
9495
},
9596
frameworkFilesExtensions: [".jar", ".dat", ".so"],
@@ -104,6 +105,22 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
104105
return this._platformData;
105106
}
106107

108+
private getDeviceBuildOutputPath(currentPath: string, projectData: IProjectData): string {
109+
const currentPlatformData: IDictionary<any> = this.$projectDataService.getNSValue(projectData.projectDir, constants.TNS_ANDROID_RUNTIME_NAME);
110+
const platformVersion = currentPlatformData && currentPlatformData[constants.VERSION_STRING];
111+
const normalizedPath = path.join(currentPath, "debug");
112+
113+
if (semver.valid(platformVersion)) {
114+
const gradleAndroidPluginVersion3xx = "4.0.0";
115+
const normalizedPlatformVersion = `${semver.major(platformVersion)}.${semver.minor(platformVersion)}.0`;
116+
if (semver.lt(normalizedPlatformVersion, gradleAndroidPluginVersion3xx)) {
117+
return currentPath;
118+
}
119+
}
120+
121+
return normalizedPath;
122+
}
123+
107124
// TODO: Remove prior to the 4.0 CLI release @Pip3r4o @PanayotCankov
108125
// Similar to the private method of the same name in platform-service.
109126
private getCurrentPlatformVersion(platformData: IPlatformData, projectData: IProjectData): string {

0 commit comments

Comments
 (0)