@@ -119,13 +119,26 @@ class AndroidProjectService implements IPlatformProjectService {
119119 return assetsDirectory ;
120120
121121 } ) . future < string > ( ) ( ) ;
122- }
122+ }
123+
124+ private generateMetadata ( projectRoot : string ) : void {
125+ var metadataGeneratorPath = path . join ( __dirname , "../../resources/tools/metadata-generator.jar" ) ;
126+ var currPlatformDir = path . join ( projectRoot , "../../lib" , this . platformData . normalizedPlatformName ) ;
127+ var inputDir = path . join ( currPlatformDir , "__jars" ) ;
128+ var outDir = path . join ( currPlatformDir , "__metadata" ) ;
129+ this . $fs . ensureDirectoryExists ( outDir ) . wait ( ) ;
130+ this . spawn ( 'java' , [ '-jar' , metadataGeneratorPath , inputDir , outDir ] ) . wait ( ) ;
131+ }
123132
124133 public buildProject ( projectRoot : string ) : IFuture < void > {
125- return ( ( ) => {
134+ return ( ( ) => {
126135 var buildConfiguration = options . release ? "release" : "debug" ;
127- var args = this . getAntArgs ( buildConfiguration , projectRoot ) ;
128- this . spawn ( 'ant' , args ) . wait ( ) ;
136+ var args = this . getAntArgs ( buildConfiguration , projectRoot ) ;
137+ var args2 = this . getAntArgs ( buildConfiguration , projectRoot ) ;
138+ this . spawn ( 'ant' , args ) . wait ( ) ;
139+ this . generateMetadata ( projectRoot ) ;
140+ // build the project again in order to include the newly generated metadata
141+ this . spawn ( 'ant' , args2 ) . wait ( ) ;
129142 } ) . future < void > ( ) ( ) ;
130143 }
131144
@@ -168,13 +181,12 @@ class AndroidProjectService implements IPlatformProjectService {
168181 this . generateBuildFile ( targetDir , targetSdk ) ;
169182 }
170183
171- private updateProjectReferences ( projDir : string , libraryPath : string ) : void {
184+ private getProjectReferences ( projDir : string ) : ILibRef [ ] {
172185 var projProp = path . join ( projDir , "project.properties" ) ;
173186
174187 var lines = fs . readFileSync ( projProp , { encoding : "utf-8" } ) . split ( "\n" ) ;
175188 var thiz = this ;
176189
177- var maxIdx = 0 ;
178190 var refs : ILibRef [ ] = [ ] ;
179191
180192 lines . forEach ( ( elem , idx , arr ) => {
@@ -183,16 +195,23 @@ class AndroidProjectService implements IPlatformProjectService {
183195 var libRef : ILibRef = { idx : parseInt ( match [ 1 ] ) , path : match [ 2 ] } ;
184196 libRef . adjustedPath = path . join ( projDir , libRef . path ) ;
185197 refs . push ( libRef ) ;
186- maxIdx = Math . max ( maxIdx , libRef . idx ) ;
187198 }
188199 } ) ;
189200
201+ return refs ;
202+ }
203+
204+ private updateProjectReferences ( projDir : string , libraryPath : string ) : void {
205+ var refs = this . getProjectReferences ( projDir ) ;
206+ var maxIdx = refs . length > 0 ? _ . max ( refs , r => r . idx ) . idx : 0
207+
190208 var relLibDir = path . relative ( projDir , libraryPath ) . split ( "\\" ) . join ( "/" ) ;
191209
192210 var libRefExists = _ . filter ( refs , r => path . normalize ( r . path ) == path . normalize ( relLibDir ) ) . length > 0 ;
193211
194212 if ( ! libRefExists ) {
195213 var projRef = util . format ( "\nandroid.library.reference.%d=%s" , maxIdx + 1 , relLibDir ) ;
214+ var projProp = path . join ( projDir , "project.properties" ) ;
196215 fs . appendFileSync ( projProp , projRef , { encoding : "utf-8" } ) ;
197216 }
198217 }
0 commit comments