Skip to content

Fix broken platform add android command #881

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/common
2 changes: 1 addition & 1 deletion lib/definitions/project.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ interface IBuildConfig {
interface IPlatformProjectService {
platformData: IPlatformData;
validate(): IFuture<void>;
createProject(projectRoot: string, frameworkDir: string): IFuture<void>;
createProject(frameworkDir: string, frameworkVersion: string): IFuture<void>;
interpolateData(projectRoot: string): IFuture<void>;
afterCreateProject(projectRoot: string): IFuture<void>;
buildProject(projectRoot: string, buildConfig?: IBuildConfig): IFuture<void>;
Expand Down
51 changes: 29 additions & 22 deletions lib/services/android-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
return this._platformData;
}

public getAppResourcesDestinationDirectoryPath(): IFuture<string> {
public getAppResourcesDestinationDirectoryPath(frameworkVersion?: string): IFuture<string> {
return (() => {
if(this.canUseGradle().wait()) {
if(this.canUseGradle(frameworkVersion).wait()) {
return path.join(this.platformData.projectRoot, "src", "main", "res");
}

Expand All @@ -81,40 +81,39 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
}).future<void>()();
}

public createProject(projectRoot: string, frameworkDir: string): IFuture<void> {
public createProject(frameworkDir: string, frameworkVersion: string): IFuture<void> {
return (() => {
let frameworkVersion = this.$fs.readJson(path.join(frameworkDir, "../", "package.json")).wait().version;
if(semver.lt(frameworkVersion, AndroidProjectService.MIN_RUNTIME_VERSION_WITH_GRADLE)) {
this.$errors.fail(`The NativeScript CLI requires Android runtime ${AndroidProjectService.MIN_RUNTIME_VERSION_WITH_GRADLE} or later to work properly.`);
}

// TODO: Move these check to validate method once we do not support ant.
this.checkGradle().wait();

this.$fs.ensureDirectoryExists(projectRoot).wait();
this.$fs.ensureDirectoryExists(this.platformData.projectRoot).wait();
let androidToolsInfo = this.$androidToolsInfo.getToolsInfo().wait();
let newTarget = androidToolsInfo.targetSdkVersion;
this.$logger.trace(`Using Android SDK '${newTarget}'.`);
let targetSdkVersion = androidToolsInfo.targetSdkVersion;
this.$logger.trace(`Using Android SDK '${targetSdkVersion}'.`);
if(this.$options.symlink) {
this.symlinkDirectory("build-tools", projectRoot, frameworkDir).wait();
this.symlinkDirectory("libs", projectRoot, frameworkDir).wait();
this.symlinkDirectory("src", projectRoot, frameworkDir).wait();
this.symlinkDirectory("build-tools", this.platformData.projectRoot, frameworkDir).wait();
this.symlinkDirectory("libs", this.platformData.projectRoot, frameworkDir).wait();
this.symlinkDirectory("src", this.platformData.projectRoot, frameworkDir).wait();

this.$fs.symlink(path.join(frameworkDir, "build.gradle"), path.join(projectRoot, "build.gradle")).wait();
this.$fs.symlink(path.join(frameworkDir, "settings.gradle"), path.join(projectRoot, "settings.gradle")).wait();
this.$fs.symlink(path.join(frameworkDir, "build.gradle"), path.join(this.platformData.projectRoot, "build.gradle")).wait();
this.$fs.symlink(path.join(frameworkDir, "settings.gradle"), path.join(this.platformData.projectRoot, "settings.gradle")).wait();
} else {
this.copy(projectRoot, frameworkDir, "build-tools libs src", "-R");
this.copy(projectRoot, frameworkDir, "build.gradle settings.gradle", "-f");
this.copy(this.platformData.projectRoot, frameworkDir, "build-tools libs src", "-R");
this.copy(this.platformData.projectRoot, frameworkDir, "build.gradle settings.gradle", "-f");
}

this.cleanResValues(newTarget).wait();
this.cleanResValues(targetSdkVersion, frameworkVersion).wait();

}).future<any>()();
}

private cleanResValues(versionNumber: number): IFuture<void> {
private cleanResValues(targetSdkVersion: number, frameworkVersion: string): IFuture<void> {
return (() => {
let resDestinationDir = this.getAppResourcesDestinationDirectoryPath().wait();
let resDestinationDir = this.getAppResourcesDestinationDirectoryPath(frameworkVersion).wait();
let directoriesInResFolder = this.$fs.readDirectory(resDestinationDir).wait();
let directoriesToClean = directoriesInResFolder
.map(dir => { return {
Expand All @@ -124,7 +123,7 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
})
.filter(dir => dir.dirName.match(AndroidProjectService.VALUES_VERSION_DIRNAME_PREFIX)
&& dir.sdkNum
&& (!versionNumber || (versionNumber < dir.sdkNum)))
&& (!targetSdkVersion || (targetSdkVersion < dir.sdkNum)))
.map(dir => path.join(resDestinationDir, dir.dirName));
this.$logger.trace("Directories to clean:");
this.$logger.trace(directoriesToClean);
Expand Down Expand Up @@ -270,11 +269,19 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
return Future.fromResult();
}

private canUseGradle(): IFuture<boolean> {
private _canUseGradle: boolean;
private canUseGradle(frameworkVersion?: string): IFuture<boolean> {
return (() => {
this.$projectDataService.initialize(this.$projectData.projectDir);
let frameworkVersion = this.$projectDataService.getValue(this.platformData.frameworkPackageName).wait().version;
return semver.gte(frameworkVersion, AndroidProjectService.MIN_RUNTIME_VERSION_WITH_GRADLE);
if(!this._canUseGradle) {
if(!frameworkVersion) {
this.$projectDataService.initialize(this.$projectData.projectDir);
frameworkVersion = this.$projectDataService.getValue(this.platformData.frameworkPackageName).wait().version;
}

this._canUseGradle = semver.gte(frameworkVersion, AndroidProjectService.MIN_RUNTIME_VERSION_WITH_GRADLE);
}

return this._canUseGradle;
}).future<boolean>()();
}

Expand Down
12 changes: 6 additions & 6 deletions lib/services/ios-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,23 +96,23 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
}).future<void>()();
}

public createProject(projectRoot: string, frameworkDir: string): IFuture<void> {
public createProject(frameworkDir: string, frameworkVersion: string): IFuture<void> {
return (() => {
this.$fs.ensureDirectoryExists(path.join(projectRoot, IOSProjectService.IOS_PROJECT_NAME_PLACEHOLDER)).wait();
this.$fs.ensureDirectoryExists(path.join(this.platformData.projectRoot, IOSProjectService.IOS_PROJECT_NAME_PLACEHOLDER)).wait();
if(this.$options.symlink) {
let xcodeProjectName = util.format("%s.xcodeproj", IOSProjectService.IOS_PROJECT_NAME_PLACEHOLDER);

shell.cp("-R", path.join(frameworkDir, IOSProjectService.IOS_PROJECT_NAME_PLACEHOLDER, "*"), path.join(projectRoot, IOSProjectService.IOS_PROJECT_NAME_PLACEHOLDER));
shell.cp("-R", path.join(frameworkDir, xcodeProjectName), projectRoot);
shell.cp("-R", path.join(frameworkDir, IOSProjectService.IOS_PROJECT_NAME_PLACEHOLDER, "*"), path.join(this.platformData.projectRoot, IOSProjectService.IOS_PROJECT_NAME_PLACEHOLDER));
shell.cp("-R", path.join(frameworkDir, xcodeProjectName), this.platformData.projectRoot);

let directoryContent = this.$fs.readDirectory(frameworkDir).wait();
let frameworkFiles = _.difference(directoryContent, [IOSProjectService.IOS_PROJECT_NAME_PLACEHOLDER, xcodeProjectName]);
_.each(frameworkFiles, (file: string) => {
this.$fs.symlink(path.join(frameworkDir, file), path.join(projectRoot, file)).wait();
this.$fs.symlink(path.join(frameworkDir, file), path.join(this.platformData.projectRoot, file)).wait();
});

} else {
shell.cp("-R", path.join(frameworkDir, "*"), projectRoot);
shell.cp("-R", path.join(frameworkDir, "*"), this.platformData.projectRoot);
}
}).future<void>()();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/services/platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ export class PlatformService implements IPlatformService {

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

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