@@ -16,6 +16,9 @@ class AndroidProjectService implements IPlatformProjectService {
16
16
private static RES_DIRNAME = "res" ;
17
17
private static VALUES_DIRNAME = "values" ;
18
18
private static VALUES_VERSION_DIRNAME_PREFIX = AndroidProjectService . VALUES_DIRNAME + "-v" ;
19
+ private static ANDROID_PLATFORM_NAME = "android" ;
20
+ private static LIBS_FOLDER_NAME = "libs" ;
21
+
19
22
20
23
private targetApi : string ;
21
24
@@ -51,7 +54,7 @@ class AndroidProjectService implements IPlatformProjectService {
51
54
frameworkFilesExtensions : [ ".jar" , ".dat" , ".so" ] ,
52
55
configurationFileName : "AndroidManifest.xml" ,
53
56
configurationFilePath : path . join ( this . $projectData . platformsDir , "android" , "AndroidManifest.xml" ) ,
54
- mergeXmlConfig : [ { "nodename" : "manifest" , "attrname" : "*" } ]
57
+ mergeXmlConfig : [ { "nodename" : "manifest" , "attrname" : "*" } , { "nodename" : "application" , "attrname" : "*" } ]
55
58
} ;
56
59
}
57
60
@@ -181,35 +184,37 @@ class AndroidProjectService implements IPlatformProjectService {
181
184
public isPlatformPrepared ( projectRoot : string ) : IFuture < boolean > {
182
185
return this . $fs . exists ( path . join ( projectRoot , "assets" , constants . APP_FOLDER_NAME ) ) ;
183
186
}
184
-
185
- private parseProjectProperties ( projDir : string , destDir : string ) : void {
186
- let projProp = path . join ( projDir , "project.properties" ) ;
187
-
188
- if ( ! this . $fs . exists ( projProp ) . wait ( ) ) {
189
- this . $logger . warn ( "Warning: File %s does not exist" , projProp ) ;
190
- return ;
191
- }
192
-
193
- let lines = this . $fs . readText ( projProp , "utf-8" ) . wait ( ) . split ( os . EOL ) ;
194
-
195
- let regEx = / a n d r o i d \. l i b r a r y \. r e f e r e n c e \. ( \d + ) = ( .* ) / ;
196
- lines . forEach ( elem => {
197
- let match = elem . match ( regEx ) ;
198
- if ( match ) {
199
- let libRef : ILibRef = { idx : parseInt ( match [ 1 ] ) , path : match [ 2 ] . trim ( ) } ;
200
- libRef . adjustedPath = this . $fs . isRelativePath ( libRef . path ) ? path . join ( projDir , libRef . path ) : libRef . path ;
201
- this . parseProjectProperties ( libRef . adjustedPath , destDir ) ;
187
+
188
+ private parseProjectProperties ( projDir : string , destDir : string ) : IFuture < void > {
189
+ return ( ( ) => {
190
+ let projProp = path . join ( projDir , "project.properties" ) ;
191
+
192
+ if ( ! this . $fs . exists ( projProp ) . wait ( ) ) {
193
+ this . $logger . warn ( "Warning: File %s does not exist" , projProp ) ;
194
+ return ;
202
195
}
203
- } ) ;
204
-
205
- this . $logger . info ( "Copying %s" , projDir ) ;
206
- shell . cp ( "-Rf" , projDir , destDir ) ;
207
-
208
- let targetDir = path . join ( destDir , path . basename ( projDir ) ) ;
209
- // TODO: parametrize targetSdk
210
- let targetSdk = "android-17" ;
211
- this . $logger . info ( "Generate build.xml for %s" , targetDir ) ;
212
- this . runAndroidUpdate ( targetDir , targetSdk ) . wait ( ) ;
196
+
197
+ let lines = this . $fs . readText ( projProp , "utf-8" ) . wait ( ) . split ( os . EOL ) ;
198
+
199
+ let regEx = / a n d r o i d \. l i b r a r y \. r e f e r e n c e \. ( \d + ) = ( .* ) / ;
200
+ lines . forEach ( elem => {
201
+ let match = elem . match ( regEx ) ;
202
+ if ( match ) {
203
+ let libRef : ILibRef = { idx : parseInt ( match [ 1 ] ) , path : match [ 2 ] . trim ( ) } ;
204
+ libRef . adjustedPath = this . $fs . isRelativePath ( libRef . path ) ? path . join ( projDir , libRef . path ) : libRef . path ;
205
+ this . parseProjectProperties ( libRef . adjustedPath , destDir ) . wait ( ) ;
206
+ }
207
+ } ) ;
208
+
209
+ this . $logger . info ( "Copying %s" , projDir ) ;
210
+ shell . cp ( "-Rf" , projDir , destDir ) ;
211
+
212
+ let targetDir = path . join ( destDir , path . basename ( projDir ) ) ;
213
+ // TODO: parametrize targetSdk
214
+ let targetSdk = "android-17" ;
215
+ this . $logger . info ( "Generate build.xml for %s" , targetDir ) ;
216
+ this . runAndroidUpdate ( targetDir , targetSdk ) . wait ( ) ;
217
+ } ) . future < void > ( ) ( ) ;
213
218
}
214
219
215
220
private getProjectReferences ( projDir : string ) : ILibRef [ ] {
@@ -225,6 +230,7 @@ class AndroidProjectService implements IPlatformProjectService {
225
230
if ( match ) {
226
231
let libRef : ILibRef = { idx : parseInt ( match [ 1 ] ) , path : match [ 2 ] } ;
227
232
libRef . adjustedPath = path . join ( projDir , libRef . path ) ;
233
+ libRef . key = match [ 0 ] . split ( "=" ) [ 0 ] ;
228
234
refs . push ( libRef ) ;
229
235
}
230
236
} ) ;
@@ -254,7 +260,7 @@ class AndroidProjectService implements IPlatformProjectService {
254
260
let targetPath = path . join ( projDir , "lib" , platformData . normalizedPlatformName ) ;
255
261
this . $fs . ensureDirectoryExists ( targetPath ) . wait ( ) ;
256
262
257
- this . parseProjectProperties ( libraryPath , targetPath ) ;
263
+ this . parseProjectProperties ( libraryPath , targetPath ) . wait ( ) ;
258
264
259
265
shell . cp ( "-f" , path . join ( libraryPath , "*.jar" ) , targetPath ) ;
260
266
let projectLibsDir = path . join ( platformData . projectRoot , "libs" ) ;
@@ -269,10 +275,71 @@ class AndroidProjectService implements IPlatformProjectService {
269
275
}
270
276
} ) . future < void > ( ) ( ) ;
271
277
}
272
-
278
+
273
279
public getFrameworkFilesExtensions ( ) : string [ ] {
274
280
return [ ".jar" , ".dat" ] ;
275
281
}
282
+
283
+ public preparePluginNativeCode ( pluginData : IPluginData ) : IFuture < void > {
284
+ return ( ( ) => {
285
+ let pluginPlatformsFolderPath = this . getPluginPlatformsFolderPath ( pluginData ) ;
286
+
287
+ // Handle *.jars inside libs folder
288
+ let libsFolderPath = path . join ( pluginPlatformsFolderPath , AndroidProjectService . LIBS_FOLDER_NAME ) ;
289
+ if ( this . $fs . exists ( libsFolderPath ) . wait ( ) ) {
290
+ let libsFolderContents = this . $fs . readDirectory ( libsFolderPath ) . wait ( ) ;
291
+ _ ( libsFolderContents )
292
+ . filter ( libsFolderItem => path . extname ( libsFolderItem ) === ".jar" )
293
+ . map ( jar => this . addLibrary ( this . platformData , path . join ( libsFolderPath , jar ) ) . wait ( ) ) ;
294
+ }
295
+
296
+ // Handle android libraries
297
+ let androidLibraries = this . getAllAndroidLibrariesForPlugin ( pluginData ) . wait ( ) ;
298
+ _ . each ( androidLibraries , androidLibraryName => this . addLibrary ( this . platformData , path . join ( pluginPlatformsFolderPath , androidLibraryName ) ) . wait ( ) ) ;
299
+
300
+ } ) . future < void > ( ) ( ) ;
301
+ }
302
+
303
+ public removePluginNativeCode ( pluginData : IPluginData ) : IFuture < void > {
304
+ return ( ( ) => {
305
+ let projectReferences = this . getProjectReferences ( this . platformData . projectRoot ) ;
306
+ let androidLibraries = this . getAllAndroidLibrariesForPlugin ( pluginData ) . wait ( ) ;
307
+
308
+ let file = path . join ( this . platformData . projectRoot , "project.properties" ) ;
309
+ let editor = this . $propertiesParser . createEditor ( file ) . wait ( ) ;
310
+
311
+ _ . each ( androidLibraries , androidLibraryName => {
312
+ // Remove library from project.properties
313
+ let androidLibraryNameLowerCase = androidLibraryName . toLowerCase ( ) ;
314
+ let projectReference = _ . find ( projectReferences , projectReference => _ . last ( projectReference . adjustedPath . split ( path . sep ) ) . toLowerCase ( ) === androidLibraryNameLowerCase ) ;
315
+ if ( projectReference && projectReference . key ) {
316
+ editor . unset ( projectReference . key ) ;
317
+ }
318
+
319
+ // Remove library from lib folder
320
+ this . $fs . deleteDirectory ( path . join ( this . $projectData . projectDir , "lib" , this . platformData . normalizedPlatformName , androidLibraryName ) ) . wait ( ) ;
321
+ } ) ;
322
+
323
+ this . $propertiesParser . saveEditor ( ) . wait ( ) ;
324
+
325
+ } ) . future < void > ( ) ( ) ;
326
+ }
327
+
328
+ private getPluginPlatformsFolderPath ( pluginData : IPluginData ) {
329
+ return pluginData . pluginPlatformsFolderPath ( AndroidProjectService . ANDROID_PLATFORM_NAME ) ;
330
+ }
331
+
332
+ private getAllAndroidLibrariesForPlugin ( pluginData : IPluginData ) : IFuture < string [ ] > {
333
+ return ( ( ) => {
334
+ let pluginPlatformsFolderPath = this . getPluginPlatformsFolderPath ( pluginData ) ;
335
+ let platformsContents = this . $fs . readDirectory ( pluginPlatformsFolderPath ) . wait ( ) ;
336
+ return _ ( platformsContents )
337
+ . filter ( platformItemName => platformItemName !== AndroidProjectService . LIBS_FOLDER_NAME &&
338
+ this . $fs . exists ( path . join ( pluginPlatformsFolderPath , platformItemName , "project.properties" ) ) . wait ( ) )
339
+ . map ( androidLibraryName => androidLibraryName )
340
+ . value ( ) ;
341
+ } ) . future < string [ ] > ( ) ( ) ;
342
+ }
276
343
277
344
private copy ( projectRoot : string , frameworkDir : string , files : string , cpArg : string ) : IFuture < void > {
278
345
return ( ( ) => {
0 commit comments