@@ -29,32 +29,38 @@ class AndroidProjectService implements IPlatformProjectService {
2929 private $propertiesParser : IPropertiesParser ) {
3030 }
3131
32+ private _platformData : IPlatformData = null ;
3233 public get platformData ( ) : IPlatformData {
33- var projectRoot = path . join ( this . $projectData . platformsDir , "android" ) ;
34-
35- return {
36- frameworkPackageName : "tns-android" ,
37- normalizedPlatformName : "Android" ,
38- appDestinationDirectoryPath : path . join ( projectRoot , "assets" ) ,
39- appResourcesDestinationDirectoryPath : path . join ( projectRoot , "res" ) ,
40- platformProjectService : this ,
41- emulatorServices : this . $androidEmulatorServices ,
42- projectRoot : projectRoot ,
43- deviceBuildOutputPath : path . join ( this . $projectData . platformsDir , "android" , "bin" ) ,
44- validPackageNamesForDevice : [
45- util . format ( "%s-%s.%s" , this . $projectData . projectName , "debug" , "apk" ) ,
46- util . format ( "%s-%s.%s" , this . $projectData . projectName , "release" , "apk" )
47- ] ,
48- frameworkFilesExtensions : [ ".jar" , ".dat" , ".so" ]
49- } ;
34+ if ( ! this . _platformData ) {
35+ var projectRoot = path . join ( this . $projectData . platformsDir , "android" ) ;
36+
37+ this . _platformData = {
38+ frameworkPackageName : "tns-android" ,
39+ normalizedPlatformName : "Android" ,
40+ appDestinationDirectoryPath : path . join ( projectRoot , "assets" ) ,
41+ appResourcesDestinationDirectoryPath : path . join ( projectRoot , "res" ) ,
42+ libDir : path . join ( projectRoot , "libs" ) ,
43+ platformProjectService : this ,
44+ emulatorServices : this . $androidEmulatorServices ,
45+ projectRoot : projectRoot ,
46+ deviceBuildOutputPath : path . join ( this . $projectData . platformsDir , "android" , "bin" ) ,
47+ validPackageNamesForDevice : [
48+ util . format ( "%s-%s.%s" , this . $projectData . projectName , "debug" , "apk" ) ,
49+ util . format ( "%s-%s.%s" , this . $projectData . projectName , "release" , "apk" )
50+ ] ,
51+ frameworkFilesExtensions : [ ".jar" , ".dat" , ".so" ]
52+ } ;
53+ }
54+
55+ return this . _platformData ;
5056 }
5157
5258 public validate ( ) : IFuture < void > {
5359 return ( ( ) => {
5460 this . validatePackageName ( this . $projectData . projectId ) ;
5561 this . validateProjectName ( this . $projectData . projectName ) ;
5662
57- this . checkAnt ( ) . wait ( ) && this . checkAndroid ( ) . wait ( ) && this . checkJava ( ) . wait ( ) ;
63+ this . checkAnt ( ) . wait ( ) && this . checkAndroid ( ) . wait ( ) ;
5864 } ) . future < void > ( ) ( ) ;
5965 }
6066
@@ -132,45 +138,18 @@ class AndroidProjectService implements IPlatformProjectService {
132138 }
133139
134140 public canUpdatePlatform ( currentVersion : string , newVersion : string ) : IFuture < boolean > {
135- return ( ( ) => {
136- return true ;
137- } ) . future < boolean > ( ) ( ) ;
141+ return Future . fromResult < boolean > ( true ) ;
138142 }
139143
140144 public updatePlatform ( currentVersion : string , newVersion : string ) : IFuture < void > {
141145 return ( ( ) => { } ) . future < void > ( ) ( ) ;
142146 }
143147
144- private updateMetadata ( projectRoot : string ) : void {
145- var projMetadataDir = path . join ( projectRoot , "assets" , "metadata" ) ;
146- var libsmetadataDir = path . join ( projectRoot , "../../lib" , this . platformData . normalizedPlatformName , AndroidProjectService . METADATA_DIRNAME ) ;
147- shell . cp ( "-f" , path . join ( libsmetadataDir , "*.dat" ) , projMetadataDir ) ;
148- }
149-
150- private generateMetadata ( projectRoot : string ) : void {
151- var metadataGeneratorPath = path . join ( __dirname , "../../resources/tools/metadata-generator.jar" ) ;
152- var libsFolder = path . join ( projectRoot , "../../lib" , this . platformData . normalizedPlatformName ) ;
153- var metadataDirName = AndroidProjectService . METADATA_DIRNAME ;
154- var outDir = path . join ( libsFolder , metadataDirName ) ;
155- this . $fs . ensureDirectoryExists ( outDir ) . wait ( ) ;
156-
157- shell . cp ( "-f" , path . join ( __dirname , "../../resources/tools/android.jar" ) , libsFolder ) ;
158- shell . cp ( "-f" , path . join ( __dirname , "../../resources/tools/android-support-v4.jar" ) , libsFolder ) ;
159- shell . cp ( "-f" , path . join ( projectRoot , "libs/*.jar" ) , libsFolder ) ;
160-
161- this . spawn ( 'java' , [ '-jar' , metadataGeneratorPath , libsFolder , outDir ] ) . wait ( ) ;
162- }
163-
164148 public buildProject ( projectRoot : string ) : IFuture < void > {
165149 return ( ( ) => {
166150 var buildConfiguration = options . release ? "release" : "debug" ;
167151 var args = this . getAntArgs ( buildConfiguration , projectRoot ) ;
168- var argsSaved = this . getAntArgs ( buildConfiguration , projectRoot ) ;
169152 this . spawn ( 'ant' , args ) . wait ( ) ;
170- this . generateMetadata ( projectRoot ) ;
171- this . updateMetadata ( projectRoot ) ;
172- // build the project again in order to include the newly generated metadata
173- this . spawn ( 'ant' , argsSaved ) . wait ( ) ;
174153 } ) . future < void > ( ) ( ) ;
175154 }
176155
@@ -285,7 +264,7 @@ class AndroidProjectService implements IPlatformProjectService {
285264 private spawn ( command : string , args : string [ ] ) : IFuture < void > {
286265 if ( hostInfo . isWindows ( ) ) {
287266 args . unshift ( '/s' , '/c' , command ) ;
288- command = 'cmd' ;
267+ command = process . env . COMSPEC || 'cmd.exe ' ;
289268 }
290269
291270 return this . $childProcess . spawnFromEvent ( command , args , "close" , { stdio : "inherit" } ) ;
@@ -311,6 +290,10 @@ class AndroidProjectService implements IPlatformProjectService {
311290 }
312291 }
313292
293+ // metadata generation support
294+ args = args . concat ( [ "-Dns.resources" , path . join ( __dirname , "../../resources/tools" ) ] ) ;
295+ args = args . concat ( ( [ "-Dns.project.libs" , this . platformData . libDir ] ) ) ;
296+
314297 return args ;
315298 }
316299
@@ -422,16 +405,6 @@ class AndroidProjectService implements IPlatformProjectService {
422405 } ) . future < void > ( ) ( ) ;
423406 }
424407
425- private checkJava ( ) : IFuture < void > {
426- return ( ( ) => {
427- try {
428- this . $childProcess . exec ( "java -version" ) . wait ( ) ;
429- } catch ( error ) {
430- this . $errors . fail ( "%s\n Failed to run 'java', make sure your java environment is set up.\n Including JDK and JRE.\n Your JAVA_HOME variable is %s" , error , process . env . JAVA_HOME ) ;
431- }
432- } ) . future < void > ( ) ( ) ;
433- }
434-
435408 private checkAndroid ( ) : IFuture < void > {
436409 return ( ( ) => {
437410 try {
0 commit comments