@@ -130,7 +130,7 @@ public File build(String target) throws IOException, SketchException {
130
130
}
131
131
}
132
132
133
- File folder = createHandheldProject (wearFolder );
133
+ File folder = createHandheldProject (wearFolder , null );
134
134
if (folder != null ) {
135
135
if (!antBuild ()) {
136
136
return null ;
@@ -357,7 +357,7 @@ public File createProject(boolean wear) throws IOException, SketchException {
357
357
// This creates the special activity project only needed to serve as the
358
358
// (invisible) app on the handheld that allows to uninstall the watchface
359
359
// from the watch.
360
- public File createHandheldProject (File wearFolder )
360
+ public File createHandheldProject (File wearFolder , File wearPackage )
361
361
throws IOException , SketchException {
362
362
// According to these instructions:
363
363
// https://developer.android.com/training/wearables/apps/packaging.html#PackageManually
@@ -418,9 +418,22 @@ public File createHandheldProject(File wearFolder)
418
418
writeIconFiles (sketchFolder , resFolder );
419
419
420
420
// Copy the wearable apk
421
- String apkName = sketch .getName ().toLowerCase () + "_debug" ;
421
+ String apkName = "" ;
422
+ if (wearPackage == null ) {
423
+ String suffix = target .equals ("release" ) ? "release_unsigned" : "debug" ;
424
+ apkName = sketch .getName ().toLowerCase () + "_" + suffix ;
425
+ } else {
426
+ String name = wearPackage .getName ();
427
+ int dot = name .lastIndexOf ('.' );
428
+ if (dot == -1 ) {
429
+ apkName = name ;
430
+ } else {
431
+ apkName = name .substring (0 , dot );
432
+ }
433
+ }
434
+
422
435
File rawFolder = mkdirs (resFolder , "raw" );
423
- File wearApk = new File (wearFolder , "bin/" + apkName + ".apk" ); // TODO TODO should be an argument, to support the release situation.
436
+ File wearApk = new File (wearFolder , "bin/" + apkName + ".apk" );
424
437
Util .copyFile (wearApk , new File (rawFolder , apkName + ".apk" ));
425
438
426
439
// Create dummy layout/activity_handheld.xml
@@ -597,12 +610,16 @@ public int getAppComponent() {
597
610
return appComponent ;
598
611
}
599
612
600
- public void setAppComponent (int opt ) {
601
- if (appComponent != opt ) {
602
- appComponent = opt ;
603
- resetManifest = true ;
604
- }
605
- }
613
+ // public void setAppComponent(int opt) {
614
+ // if (appComponent != opt) {
615
+ // appComponent = opt;
616
+ // resetManifest = true;
617
+ // }
618
+ // }
619
+
620
+ public void resetManifest () {
621
+ resetManifest = true ;
622
+ }
606
623
607
624
protected boolean usesGPU () {
608
625
return renderer != null && (renderer .equals ("P2D" ) || renderer .equals ("P3D" ));
@@ -662,20 +679,14 @@ public File exportProject() throws IOException, SketchException {
662
679
// this will set debuggable to true in the .xml file
663
680
target = "debug" ;
664
681
665
- if (appComponent == WATCHFACE && ! runOnEmulator ) {
682
+ if (appComponent == WATCHFACE ) {
666
683
// We are building a watchface not to run on the emulator. We need the
667
684
// handheld app:
668
- // https://developer.android.com/training/wearables/apps/creating.html
669
- // so the watchface can be uninstalled from the phone, and can be
670
- // published on Google Play.
671
685
File wearFolder = createProject (true );
672
- if (wearFolder != null ) {
673
- if (!antBuild ()) {
674
- return null ;
675
- }
676
- }
686
+ if (wearFolder == null ) return null ;
687
+ if (!antBuild ()) return null ;
677
688
678
- File projectFolder = createHandheldProject (wearFolder );
689
+ File projectFolder = createHandheldProject (wearFolder , null );
679
690
if (projectFolder != null ) {
680
691
File exportFolder = createExportFolder ();
681
692
Util .copyDir (projectFolder , exportFolder );
@@ -694,16 +705,35 @@ public File exportProject() throws IOException, SketchException {
694
705
}
695
706
696
707
public File exportPackage (String keyStorePassword ) throws Exception {
697
- // TODO TODO
698
- File projectFolder = build ("release" );
699
- if (projectFolder == null ) return null ;
700
-
701
- File signedPackage = signPackage (projectFolder , keyStorePassword );
702
- if (signedPackage == null ) return null ;
708
+ File projectFolder = null ;
709
+ if (appComponent == WATCHFACE ) {
710
+ this .target = "release" ;
711
+ // We need to sign and align the wearable and handheld apps:
712
+ File wearFolder = createProject (true );
713
+ if (wearFolder == null ) return null ;
714
+ if (!antBuild ()) return null ;
715
+ File signedWearPackage = signPackage (wearFolder , keyStorePassword );
716
+ if (signedWearPackage == null ) return null ;
717
+
718
+ // Handheld package
719
+ projectFolder = createHandheldProject (wearFolder , signedWearPackage );
720
+ if (projectFolder == null ) return null ;
721
+ if (!antBuild ()) return null ;
722
+
723
+ File signedPackage = signPackage (projectFolder , keyStorePassword );
724
+ if (signedPackage == null ) return null ;
725
+ } else {
726
+ projectFolder = build ("release" );
727
+ if (projectFolder == null ) return null ;
703
728
729
+ File signedPackage = signPackage (projectFolder , keyStorePassword );
730
+ if (signedPackage == null ) return null ;
731
+ }
732
+
733
+ // Final export folder
704
734
File exportFolder = createExportFolder ();
705
735
Util .copyDir (projectFolder , exportFolder );
706
- return new File (exportFolder , "/bin/" );
736
+ return new File (exportFolder , "/bin/" );
707
737
}
708
738
709
739
private File signPackage (File projectFolder , String keyStorePassword ) throws Exception {
0 commit comments