Skip to content

Commit 6053ed4

Browse files
committed
Build android project
1 parent 69f54b0 commit 6053ed4

File tree

4 files changed

+46
-8
lines changed

4 files changed

+46
-8
lines changed

lib/common

Submodule common updated 1 file

lib/options.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var knownOpts:any = {
1010
"path" : String,
1111
"copy-from": String,
1212
"link-to": String,
13+
"release": String,
1314
"version": Boolean,
1415
"help": Boolean
1516
},

lib/services/platform-service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ export class PlatformService implements IPlatformService {
9898

9999
public buildPlatform(platform: string): IFuture<void> {
100100
return (() => {
101-
this.$projectService.buildProject(platform);
101+
this.validatePlatform(platform);
102+
103+
this.$projectService.buildProject(platform).wait();
102104
}).future<void>()();
103105
}
104106

lib/services/project-service.ts

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export class ProjectService implements IProjectService {
161161
shell.cp("-r",path.join(this.projectData.projectDir, ProjectService.APP_FOLDER_NAME), assetsDirectoryPath);
162162

163163
var files = helpers.enumerateFilesInDirectorySync(path.join(assetsDirectoryPath, ProjectService.APP_FOLDER_NAME));
164-
var pattern = util.format("%s%s%s", path.sep, ProjectService.APP_FOLDER_NAME ,path.sep);
164+
var pattern = util.format("%s%s%s", path.sep, ProjectService.APP_FOLDER_NAME, path.sep);
165165
_.each(files, fileName => {
166166
if(ProjectService.shouldExcludeFile(platform, platforms, fileName.split(pattern)[1])) {
167167
this.$fs.deleteFile(fileName).wait();
@@ -194,17 +194,17 @@ export class ProjectService implements IProjectService {
194194

195195
private executePlatformSpecificAction(platform, functionName: string): IFuture<void> {
196196
return (() => {
197-
var projectService = null;
197+
var platformProjectService = null;
198198
switch (platform) {
199199
case "android":
200-
projectService = this.$androidProjectService;
200+
platformProjectService = this.$androidProjectService;
201201
break;
202202
case "ios":
203-
projectService = this.$iOSProjectService;
203+
platformProjectService = this.$iOSProjectService;
204204
break;
205205
}
206206

207-
this.executeFunctionByName(functionName, projectService, [this.projectData]).wait();
207+
this.executeFunctionByName(functionName, platformProjectService, [this.projectData]).wait();
208208
}).future<void>()();
209209
}
210210

@@ -257,6 +257,7 @@ class AndroidProjectService implements IPlatformProjectService {
257257
this.frameworkDir = this.getFrameworkDir(projectData).wait();
258258

259259
var packageName = projectData.projectId;
260+
var packageAsPath = packageName.replace(/\./g, path.sep);
260261
var projectDir = path.join(projectData.projectDir, "platforms", "android");
261262

262263
this.validatePackageName(packageName);
@@ -268,7 +269,7 @@ class AndroidProjectService implements IPlatformProjectService {
268269

269270
// Log the values for project
270271
this.$logger.trace("Creating NativeScript project for the Android platform");
271-
this.$logger.trace("Path: %s", projectData.projectDir);
272+
this.$logger.trace("Path: %s", projectDir);
272273
this.$logger.trace("Package: %s", projectData.projectId);
273274
this.$logger.trace("Name: %s", projectData.projectName);
274275
this.$logger.trace("Android target: %s", targetApi);
@@ -283,6 +284,10 @@ class AndroidProjectService implements IPlatformProjectService {
283284
shell.cp("-f", path.join(this.frameworkDir, ".project"), projectDir);
284285
shell.cp("-f", path.join(this.frameworkDir, "AndroidManifest.xml"), projectDir);
285286

287+
// Create src folder
288+
var activityDir = path.join(projectDir, 'src', packageAsPath);
289+
this.$fs.createDirectory(activityDir).wait();
290+
286291
this.$fs.deleteDirectory(path.join(projectData.platformsDir, "android", "node_modules")).wait();
287292

288293
// Interpolate the activity name and package
@@ -301,10 +306,40 @@ class AndroidProjectService implements IPlatformProjectService {
301306

302307
public buildProject(projectData: IProjectData): IFuture<void> {
303308
return (() => {
309+
var projectRoot = path.join(projectData.platformsDir, "android");
310+
var buildConfiguration = options.release || "--debug";
311+
var args = this.getAntArgs(buildConfiguration, projectRoot);
312+
313+
switch(buildConfiguration) {
314+
case "--debug":
315+
args[0] = "debug";
316+
break;
317+
case "--release":
318+
args[0] = "release";
319+
break;
320+
default:
321+
this.$errors.fail("Build option %s not recognized", buildConfiguration);
322+
}
323+
324+
this.spawn('ant', args);
304325

305326
}).future<void>()();
306327
}
307328

329+
private spawn(command: string, args: string[], options?: any): void {
330+
if(helpers.isWindows()) {
331+
args.unshift('/s', '/c', command);
332+
command = 'cmd';
333+
}
334+
335+
this.$childProcess.spawn(command, args, {cwd: options, stdio: 'inherit'});
336+
}
337+
338+
private getAntArgs(configuration: string, projectRoot: string): string[] {
339+
var args = [configuration, "-f", path.join(projectRoot, "build.xml")];
340+
return args;
341+
}
342+
308343
private runAndroidUpdate(projectPath: string, targetApi: string): IFuture<void> {
309344
return (() => {
310345
this.$childProcess.exec("android update project --subprojects --path " + projectPath + " --target " + targetApi).wait();

0 commit comments

Comments
 (0)