Skip to content

Commit 2f287ae

Browse files
Fix failing android build command by forcing use of gradle
When there's `platforms/android` directory, but in package.json there's no entry in `nativescript` for android platform, calling `tns build android` or any build related command will fail with error: `Cannot read property 'version' of undefined` The reason is that we are trying to check the version in package.json and check if it allows us to use gradle (previously Android builds required Ant). Prevent the error and force using gradle in such case.
1 parent cd07bbf commit 2f287ae

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lib/services/android-project-service.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,10 +445,11 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
445445
if (!this._canUseGradle) {
446446
if (!frameworkVersion) {
447447
this.$projectDataService.initialize(this.$projectData.projectDir);
448-
frameworkVersion = this.$projectDataService.getValue(this.platformData.frameworkPackageName).wait().version;
448+
let frameworkInfoInProjectFile = this.$projectDataService.getValue(this.platformData.frameworkPackageName).wait();
449+
frameworkVersion = frameworkInfoInProjectFile && frameworkInfoInProjectFile.version;
449450
}
450451

451-
this._canUseGradle = semver.gte(frameworkVersion, AndroidProjectService.MIN_RUNTIME_VERSION_WITH_GRADLE);
452+
this._canUseGradle = !frameworkVersion || semver.gte(frameworkVersion, AndroidProjectService.MIN_RUNTIME_VERSION_WITH_GRADLE);
452453
}
453454

454455
return this._canUseGradle;

0 commit comments

Comments
 (0)