@@ -233,16 +233,83 @@ public File createProject() throws IOException, SketchException {
233
233
// TODO: temporary hack until I find a better way to include the cardboard aar
234
234
// packages included in the cardboard SDK:
235
235
236
- File audioJarFile = mode .getContentFile ("mode/cardboard-audio-classes.jar" );
237
- File commonJarFile = mode .getContentFile ("mode/cardboard-common-classes.jar" );
238
- File coreJarFile = mode .getContentFile ("mode/cardboard-core-classes.jar" );
236
+ ////////////////////////////////////////////////////////////////////////
237
+ // first step: unpack the cardboard packages in the project's
238
+ // libs folder:
239
+ File audioZipFile = mode .getContentFile ("mode/cardboard_audio.zip" );
240
+ File commonZipFile = mode .getContentFile ("mode/cardboard_common.zip" );
241
+ File coreZipFile = mode .getContentFile ("mode/cardboard_core.zip" );
242
+ AndroidMode .extractFolder (audioZipFile , libsFolder , true );
243
+ AndroidMode .extractFolder (commonZipFile , libsFolder , true );
244
+ AndroidMode .extractFolder (coreZipFile , libsFolder , true );
245
+ File audioLibsFolder = new File (libsFolder , "cardboard_audio" );
246
+ File commonLibsFolder = new File (libsFolder , "cardboard_common" );
247
+ File coreLibsFolder = new File (libsFolder , "cardboard_core" );
248
+
249
+ ////////////////////////////////////////////////////////////////////////
250
+ // second step: determine target id
251
+ String targetID = "" ;
239
252
240
- Util . copyFile ( audioJarFile , new File ( libsFolder , "cardboard-audio-classes.jar" ));
241
- Util . copyFile ( commonJarFile , new File ( libsFolder , "cardboard-common-classes.jar" ));
242
- Util . copyFile ( coreJarFile , new File ( libsFolder , "cardboard-core-classes.jar" ));
243
- }
253
+ final String [] params = {
254
+ sdk . getAndroidToolPath (),
255
+ "list" , "targets"
256
+ };
244
257
245
-
258
+ ProcessHelper p = new ProcessHelper (params );
259
+ try {
260
+ final ProcessResult abiListResult = p .execute ();
261
+ String id = null ;
262
+ String platform = null ;
263
+ String api = null ;
264
+ for (String line : abiListResult ) {
265
+ if (line .indexOf ("id:" ) == 0 ) {
266
+ String [] parts = line .substring (4 ).split ("or" );
267
+ if (parts .length == 2 ) {
268
+ id = parts [0 ];
269
+ platform = parts [1 ].replaceAll ("\" " , "" ).trim ();
270
+ }
271
+ // System.out.println("***********");
272
+ // System.out.println("ID: " + id);
273
+ // System.out.println("PLATFORM: " + platform);
274
+ }
275
+
276
+ String [] mapi = PApplet .match (line , "API\\ slevel:\\ s(\\ S+)" );
277
+ if (mapi != null ) {
278
+ api = mapi [1 ];
279
+ // System.out.println("API: " + api);
280
+ }
281
+
282
+ if (platform != null && platform .equals (sdkTarget ) &&
283
+ api != null && api .equals (sdkVersion )) {
284
+ targetID = id ;
285
+ break ;
286
+ }
287
+ }
288
+ } catch (InterruptedException e ) {}
289
+
290
+ System .out .println ("TARGET ID: " + targetID );
291
+
292
+ ////////////////////////////////////////////////////////////////////////
293
+ // third step: create library projects
294
+ boolean audioRes = createLibraryProject ("cardboard_audio" , targetID ,
295
+ audioLibsFolder .getAbsolutePath (), "com.google.vr.cardboard.vrtoolkit.vraudio" );
296
+ boolean commonRes = createLibraryProject ("cardboard_common" , targetID ,
297
+ commonLibsFolder .getAbsolutePath (), "com.google.vr.cardboard" );
298
+ boolean coreRes = createLibraryProject ("cardboard_core" , targetID ,
299
+ coreLibsFolder .getAbsolutePath (), "com.google.vrtoolkit.cardboard" );
300
+
301
+ ////////////////////////////////////////////////////////////////////////
302
+ // fourth step: reference library projects from main project
303
+ if (audioRes && commonRes && coreRes ) {
304
+ System .out .println ("Library projects created succesfully in " + libsFolder .toString ());
305
+ audioRes = referenceLibraryProject (targetID , tmpFolder .getAbsolutePath (), "libs/cardboard_audio" );
306
+ commonRes = referenceLibraryProject (targetID , tmpFolder .getAbsolutePath (), "libs/cardboard_common" );
307
+ coreRes = referenceLibraryProject (targetID , tmpFolder .getAbsolutePath (), "libs/cardboard_core" );
308
+ if (audioRes && commonRes && coreRes ) {
309
+ System .out .println ("Library projects referenced succesfully!" );
310
+ }
311
+ }
312
+ }
246
313
247
314
// Copy the data folder (if one exists) to the project's 'assets' folder
248
315
final File sketchDataFolder = sketch .getDataFolder ();
@@ -257,9 +324,66 @@ public File createProject() throws IOException, SketchException {
257
324
Util .copyDir (sketchResFolder , resFolder );
258
325
}
259
326
}
327
+
260
328
return tmpFolder ;
261
329
}
262
330
331
+
332
+ protected boolean createLibraryProject (String name , String target ,
333
+ String path , String pck ) {
334
+ final String [] params = {
335
+ sdk .getAndroidToolPath (),
336
+ "create" , "lib-project" ,
337
+ "--name" , name ,
338
+ "--target" , target ,
339
+ "--path" , path ,
340
+ "--package" , pck
341
+ };
342
+
343
+ ProcessHelper p = new ProcessHelper (params );
344
+ ProcessResult pr ;
345
+ try {
346
+ pr = p .execute ();
347
+ } catch (InterruptedException | IOException e ) {
348
+ e .printStackTrace ();
349
+ return false ;
350
+ }
351
+
352
+ if (pr .succeeded ()) {
353
+ return true ;
354
+ } else {
355
+ System .err .println (pr .getStderr ());
356
+ Messages .showWarning ("Failed to create library project" , "Something wrong happened" , null );
357
+ return false ;
358
+ }
359
+ }
360
+
361
+ protected boolean referenceLibraryProject (String target , String path , String lib ) {
362
+ final String [] params = {
363
+ sdk .getAndroidToolPath (),
364
+ "update" , "project" ,
365
+ "--target" , target ,
366
+ "--path" , path ,
367
+ "--library" , lib
368
+ };
369
+
370
+ ProcessHelper p = new ProcessHelper (params );
371
+ ProcessResult pr ;
372
+ try {
373
+ pr = p .execute ();
374
+ } catch (InterruptedException | IOException e ) {
375
+ e .printStackTrace ();
376
+ return false ;
377
+ }
378
+
379
+ if (pr .succeeded ()) {
380
+ return true ;
381
+ } else {
382
+ System .err .println (pr .getStderr ());
383
+ Messages .showWarning ("Failed to add library project" , "Something wrong happened" , null );
384
+ return false ;
385
+ }
386
+ }
263
387
264
388
/**
265
389
* The Android dex util pukes on paths containing spaces, which will happen
0 commit comments