Skip to content

Commit d9b910c

Browse files
Fatme HavaluovaFatme Havaluova
Fatme Havaluova
authored and
Fatme Havaluova
committed
Fix broken platform add android command
1 parent 07dfe3e commit d9b910c

File tree

3 files changed

+31
-23
lines changed

3 files changed

+31
-23
lines changed

lib/definitions/project.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ interface IBuildConfig {
3333
interface IPlatformProjectService {
3434
platformData: IPlatformData;
3535
validate(): IFuture<void>;
36-
createProject(projectRoot: string, frameworkDir: string): IFuture<void>;
36+
createProject(frameworkDir: string, frameworkVersion: string): IFuture<void>;
3737
interpolateData(projectRoot: string): IFuture<void>;
3838
afterCreateProject(projectRoot: string): IFuture<void>;
3939
buildProject(projectRoot: string, buildConfig?: IBuildConfig): IFuture<void>;

lib/services/android-project-service.ts

+29-21
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
6161
return this._platformData;
6262
}
6363

64-
public getAppResourcesDestinationDirectoryPath(): IFuture<string> {
64+
public getAppResourcesDestinationDirectoryPath(frameworkVersion?: string): IFuture<string> {
6565
return (() => {
66-
if(this.canUseGradle().wait()) {
66+
if(this.canUseGradle(frameworkVersion).wait()) {
6767
return path.join(this.platformData.projectRoot, "src", "main", "res");
6868
}
6969

@@ -81,7 +81,7 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
8181
}).future<void>()();
8282
}
8383

84-
public createProject(projectRoot: string, frameworkDir: string): IFuture<void> {
84+
public createProject(frameworkDir: string, frameworkVersion: string): IFuture<void> {
8585
return (() => {
8686
let frameworkVersion = this.$fs.readJson(path.join(frameworkDir, "../", "package.json")).wait().version;
8787
if(semver.lt(frameworkVersion, AndroidProjectService.MIN_RUNTIME_VERSION_WITH_GRADLE)) {
@@ -91,30 +91,30 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
9191
// TODO: Move these check to validate method once we do not support ant.
9292
this.checkGradle().wait();
9393

94-
this.$fs.ensureDirectoryExists(projectRoot).wait();
94+
this.$fs.ensureDirectoryExists(this.platformData.projectRoot).wait();
9595
let androidToolsInfo = this.$androidToolsInfo.getToolsInfo().wait();
96-
let newTarget = androidToolsInfo.targetSdkVersion;
97-
this.$logger.trace(`Using Android SDK '${newTarget}'.`);
96+
let targetSdkVersion = androidToolsInfo.targetSdkVersion;
97+
this.$logger.trace(`Using Android SDK '${targetSdkVersion}'.`);
9898
if(this.$options.symlink) {
99-
this.symlinkDirectory("build-tools", projectRoot, frameworkDir).wait();
100-
this.symlinkDirectory("libs", projectRoot, frameworkDir).wait();
101-
this.symlinkDirectory("src", projectRoot, frameworkDir).wait();
99+
this.symlinkDirectory("build-tools", this.platformData.projectRoot, frameworkDir).wait();
100+
this.symlinkDirectory("libs", this.platformData.projectRoot, frameworkDir).wait();
101+
this.symlinkDirectory("src", this.platformData.projectRoot, frameworkDir).wait();
102102

103-
this.$fs.symlink(path.join(frameworkDir, "build.gradle"), path.join(projectRoot, "build.gradle")).wait();
104-
this.$fs.symlink(path.join(frameworkDir, "settings.gradle"), path.join(projectRoot, "settings.gradle")).wait();
103+
this.$fs.symlink(path.join(frameworkDir, "build.gradle"), path.join(this.platformData.projectRoot, "build.gradle")).wait();
104+
this.$fs.symlink(path.join(frameworkDir, "settings.gradle"), path.join(this.platformData.projectRoot, "settings.gradle")).wait();
105105
} else {
106-
this.copy(projectRoot, frameworkDir, "build-tools libs src", "-R");
107-
this.copy(projectRoot, frameworkDir, "build.gradle settings.gradle", "-f");
106+
this.copy(this.platformData.projectRoot, frameworkDir, "build-tools libs src", "-R");
107+
this.copy(this.platformData.projectRoot, frameworkDir, "build.gradle settings.gradle", "-f");
108108
}
109109

110-
this.cleanResValues(newTarget).wait();
110+
this.cleanResValues(targetSdkVersion, frameworkVersion).wait();
111111

112112
}).future<any>()();
113113
}
114114

115-
private cleanResValues(versionNumber: number): IFuture<void> {
115+
private cleanResValues(targetSdkVersion: number, frameworkVersion: string): IFuture<void> {
116116
return (() => {
117-
let resDestinationDir = this.getAppResourcesDestinationDirectoryPath().wait();
117+
let resDestinationDir = this.getAppResourcesDestinationDirectoryPath(frameworkVersion).wait();
118118
let directoriesInResFolder = this.$fs.readDirectory(resDestinationDir).wait();
119119
let directoriesToClean = directoriesInResFolder
120120
.map(dir => { return {
@@ -124,7 +124,7 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
124124
})
125125
.filter(dir => dir.dirName.match(AndroidProjectService.VALUES_VERSION_DIRNAME_PREFIX)
126126
&& dir.sdkNum
127-
&& (!versionNumber || (versionNumber < dir.sdkNum)))
127+
&& (!targetSdkVersion || (targetSdkVersion < dir.sdkNum)))
128128
.map(dir => path.join(resDestinationDir, dir.dirName));
129129
this.$logger.trace("Directories to clean:");
130130
this.$logger.trace(directoriesToClean);
@@ -270,11 +270,19 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
270270
return Future.fromResult();
271271
}
272272

273-
private canUseGradle(): IFuture<boolean> {
273+
private _canUseGradle: boolean;
274+
private canUseGradle(frameworkVersion?: string): IFuture<boolean> {
274275
return (() => {
275-
this.$projectDataService.initialize(this.$projectData.projectDir);
276-
let frameworkVersion = this.$projectDataService.getValue(this.platformData.frameworkPackageName).wait().version;
277-
return semver.gte(frameworkVersion, AndroidProjectService.MIN_RUNTIME_VERSION_WITH_GRADLE);
276+
if(!this._canUseGradle) {
277+
if(!frameworkVersion) {
278+
this.$projectDataService.initialize(this.$projectData.projectDir);
279+
frameworkVersion = this.$projectDataService.getValue(this.platformData.frameworkPackageName).wait().version;
280+
}
281+
282+
this._canUseGradle = semver.gte(frameworkVersion, AndroidProjectService.MIN_RUNTIME_VERSION_WITH_GRADLE);
283+
}
284+
285+
return this._canUseGradle;
278286
}).future<boolean>()();
279287
}
280288

lib/services/platform-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ export class PlatformService implements IPlatformService {
9393

9494
private addPlatformCore(platformData: IPlatformData, frameworkDir: string): IFuture<void> {
9595
return (() => {
96-
platformData.platformProjectService.createProject(platformData.projectRoot, frameworkDir).wait();
9796
let installedVersion = this.$fs.readJson(path.join(frameworkDir, "../", "package.json")).wait().version;
97+
platformData.platformProjectService.createProject(frameworkDir, installedVersion).wait();
9898

9999
if(this.$options.frameworkPath && this.$fs.getFsStats(this.$options.frameworkPath).wait().isFile() && !this.$options.symlink) {
100100
// Need to remove unneeded node_modules folder

0 commit comments

Comments
 (0)