@@ -29,32 +29,37 @@ 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+ platformProjectService : this ,
43+ emulatorServices : this . $androidEmulatorServices ,
44+ projectRoot : projectRoot ,
45+ deviceBuildOutputPath : path . join ( this . $projectData . platformsDir , "android" , "bin" ) ,
46+ validPackageNamesForDevice : [
47+ util . format ( "%s-%s.%s" , this . $projectData . projectName , "debug" , "apk" ) ,
48+ util . format ( "%s-%s.%s" , this . $projectData . projectName , "release" , "apk" )
49+ ] ,
50+ frameworkFilesExtensions : [ ".jar" , ".dat" , ".so" ]
51+ } ;
52+ }
53+
54+ return this . _platformData ;
5055 }
5156
5257 public validate ( ) : IFuture < void > {
5358 return ( ( ) => {
5459 this . validatePackageName ( this . $projectData . projectId ) ;
5560 this . validateProjectName ( this . $projectData . projectName ) ;
5661
57- this . checkAnt ( ) . wait ( ) && this . checkAndroid ( ) . wait ( ) && this . checkJava ( ) . wait ( ) ;
62+ this . checkAnt ( ) . wait ( ) && this . checkAndroid ( ) . wait ( ) ;
5863 } ) . future < void > ( ) ( ) ;
5964 }
6065
@@ -65,14 +70,14 @@ class AndroidProjectService implements IPlatformProjectService {
6570 var versionNumber = _ . last ( newTarget . split ( "-" ) ) ;
6671 if ( options . symlink ) {
6772 this . copyResValues ( projectRoot , frameworkDir , versionNumber ) . wait ( ) ;
68- this . copy ( projectRoot , frameworkDir , ".project AndroidManifest.xml project.properties" , "-f" ) . wait ( ) ;
73+ this . copy ( projectRoot , frameworkDir , ".project AndroidManifest.xml project.properties custom_rules.xml " , "-f" ) . wait ( ) ;
6974
7075 this . symlinkDirectory ( "assets" , projectRoot , frameworkDir ) . wait ( ) ;
7176 this . symlinkDirectory ( "libs" , projectRoot , frameworkDir ) . wait ( ) ;
7277 } else {
7378 this . copyResValues ( projectRoot , frameworkDir , versionNumber ) . wait ( ) ;
7479 this . copy ( projectRoot , frameworkDir , "assets libs" , "-R" ) . wait ( ) ;
75- this . copy ( projectRoot , frameworkDir , ".project AndroidManifest.xml project.properties" , "-f" ) . wait ( ) ;
80+ this . copy ( projectRoot , frameworkDir , ".project AndroidManifest.xml project.properties custom_rules.xml " , "-f" ) . wait ( ) ;
7681 }
7782
7883 if ( newTarget ) {
@@ -132,45 +137,18 @@ class AndroidProjectService implements IPlatformProjectService {
132137 }
133138
134139 public canUpdatePlatform ( currentVersion : string , newVersion : string ) : IFuture < boolean > {
135- return ( ( ) => {
136- return true ;
137- } ) . future < boolean > ( ) ( ) ;
140+ return Future . fromResult < boolean > ( true ) ;
138141 }
139142
140143 public updatePlatform ( currentVersion : string , newVersion : string ) : IFuture < void > {
141144 return ( ( ) => { } ) . future < void > ( ) ( ) ;
142145 }
143146
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-
164147 public buildProject ( projectRoot : string ) : IFuture < void > {
165148 return ( ( ) => {
166149 var buildConfiguration = options . release ? "release" : "debug" ;
167150 var args = this . getAntArgs ( buildConfiguration , projectRoot ) ;
168- var argsSaved = this . getAntArgs ( buildConfiguration , projectRoot ) ;
169151 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 ( ) ;
174152 } ) . future < void > ( ) ( ) ;
175153 }
176154
@@ -285,7 +263,7 @@ class AndroidProjectService implements IPlatformProjectService {
285263 private spawn ( command : string , args : string [ ] ) : IFuture < void > {
286264 if ( hostInfo . isWindows ( ) ) {
287265 args . unshift ( '/s' , '/c' , command ) ;
288- command = 'cmd' ;
266+ command = process . env . COMSPEC || 'cmd.exe ' ;
289267 }
290268
291269 return this . $childProcess . spawnFromEvent ( command , args , "close" , { stdio : "inherit" } ) ;
@@ -311,6 +289,9 @@ class AndroidProjectService implements IPlatformProjectService {
311289 }
312290 }
313291
292+ // metadata generation support
293+ args = args . concat ( [ "-Dns.resources" , path . join ( __dirname , "../../resources/tools" ) ] ) ;
294+
314295 return args ;
315296 }
316297
@@ -422,16 +403,6 @@ class AndroidProjectService implements IPlatformProjectService {
422403 } ) . future < void > ( ) ( ) ;
423404 }
424405
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-
435406 private checkAndroid ( ) : IFuture < void > {
436407 return ( ( ) => {
437408 try {
0 commit comments