|
36 | 36 | import processing.mode.java.preproc.SurfaceInfo;
|
37 | 37 |
|
38 | 38 | import java.io.*;
|
39 |
| -import java.nio.file.Paths; |
40 | 39 | import java.util.HashMap;
|
41 | 40 |
|
42 | 41 | /**
|
@@ -71,14 +70,44 @@ class AndroidBuild extends JavaBuild {
|
71 | 70 | TARGET_PLATFORM = "android-" + TARGET_SDK;
|
72 | 71 | }
|
73 | 72 |
|
74 |
| - // Versions of Support, AppCompat, Wear and VR in use |
75 |
| - // All of these are hard-coded, as the TARGET_SDK. Should obtained from the |
76 |
| - // repository files? Or users being able to change them in the preferences |
77 |
| - // file? |
78 |
| - static public final String SUPPORT_VER = "25.3.1"; |
79 |
| - static public final String PLAY_SERVICES_VER = "11.8.0"; |
80 |
| - static public final String WEAR_VER = "2.0.5"; |
81 |
| - static public final String GVR_VER = "1.120.0"; |
| 73 | + // Versions of support, play services, wear and VR in use, also stored in |
| 74 | + // preferences file so they can be changed without having to rebuilt/reinstall |
| 75 | + // the mode. |
| 76 | + static public String SUPPORT_VER; |
| 77 | + static { |
| 78 | + SUPPORT_VER = Preferences.get("android.sdk.support"); |
| 79 | + if (SUPPORT_VER == null) { |
| 80 | + SUPPORT_VER = "25.3.1"; |
| 81 | + Preferences.set("android.sdk.support", SUPPORT_VER); |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | + static public String PLAY_SERVICES_VER; |
| 86 | + static { |
| 87 | + PLAY_SERVICES_VER = Preferences.get("android.sdk.play_services"); |
| 88 | + if (PLAY_SERVICES_VER == null) { |
| 89 | + PLAY_SERVICES_VER = "11.8.0"; |
| 90 | + Preferences.set("android.sdk.play_services", PLAY_SERVICES_VER); |
| 91 | + } |
| 92 | + } |
| 93 | + |
| 94 | + static public String WEAR_VER; |
| 95 | + static { |
| 96 | + WEAR_VER = Preferences.get("android.sdk.wear"); |
| 97 | + if (WEAR_VER == null) { |
| 98 | + WEAR_VER = "2.0.5"; |
| 99 | + Preferences.set("android.sdk.wear", WEAR_VER); |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + static public String GVR_VER; |
| 104 | + static { |
| 105 | + GVR_VER = Preferences.get("android.sdk.gvr"); |
| 106 | + if (GVR_VER == null) { |
| 107 | + GVR_VER = "1.120.0"; |
| 108 | + Preferences.set("android.sdk.gvr", GVR_VER); |
| 109 | + } |
| 110 | + } |
82 | 111 |
|
83 | 112 | // Main activity or service
|
84 | 113 | static private final String APP_ACTIVITY_TEMPLATE = "AppActivity.java.tmpl";
|
@@ -231,10 +260,6 @@ protected File createProject(boolean external)
|
231 | 260 | preproc.initSketchSmooth(sketch.getMainProgram());
|
232 | 261 |
|
233 | 262 | sketchClassName = preprocess(srcFolder, getPackageName(), preproc, false);
|
234 |
| - File folder = sdk.getBuildToolsFolder(); |
235 |
| - String[] versions = folder.list(); |
236 |
| - String[] sorted = PApplet.sort(versions, versions.length); |
237 |
| - |
238 | 263 | if (sketchClassName != null) {
|
239 | 264 | renderer = info.getRenderer();
|
240 | 265 | writeMainClass(srcFolder, renderer, external);
|
@@ -361,10 +386,10 @@ private void createAppModule(String moduleName)
|
361 | 386 | copyCodeFolder(libsFolder);
|
362 | 387 |
|
363 | 388 | // Copy any system libraries needed by the project
|
364 |
| - copyWearLib(tmpFolder, libsFolder); |
365 |
| - copySupportLibs(tmpFolder, libsFolder); |
| 389 | + copyWearLib(libsFolder); |
| 390 | + copySupportLibs(libsFolder); |
366 | 391 | if (getAppComponent() == APP) {
|
367 |
| - copyAppCompatLib(tmpFolder, libsFolder); |
| 392 | + copyAppCompatLib(libsFolder); |
368 | 393 | }
|
369 | 394 | if (getAppComponent() == VR) {
|
370 | 395 | copyGVRLibs(libsFolder);
|
@@ -669,69 +694,64 @@ private void copyIcon(File srcFile, File destFile) throws IOException {
|
669 | 694 | // Dependencies
|
670 | 695 |
|
671 | 696 |
|
672 |
| - private void copyWearLib(File tmpFolder, File libsFolder) throws IOException { |
673 |
| - // The wear jar is needed even when the app is not a watch face, because on |
| 697 | + private void copyWearLib(File libsFolder) throws IOException { |
| 698 | + // The wear aar is needed even when the app is not a watch face, because on |
674 | 699 | // devices with android < 5 the dependencies of the PWatchFace* classes
|
675 | 700 | // cannot be resolved.
|
676 |
| - File aarFile = new File(sdk.getWearableFolder(), WEAR_VER + "/wearable-" + WEAR_VER + ".aar"); |
677 |
| - Util.copyFile(aarFile, new File(libsFolder, aarFile.getName())); |
| 701 | + copyAARFileFromSDK(sdk.getWearableFolder() + "/$VER", "wearable-$VER.aar", WEAR_VER, libsFolder); |
678 | 702 | }
|
679 | 703 |
|
680 | 704 |
|
681 |
| - private void copySupportLibs(File tmpFolder, File libsFolder) throws IOException { |
682 |
| - // Copy support packages (core-utils, compat, fragment, annotations, and |
683 |
| - // vector-drawable) |
684 |
| -// copyDepFile(sdk.getSupportLibrary(), "/support-core-utils/$VER/support-core-utils-$VER.aar", SUPPORT_VER); |
685 |
| - |
686 |
| - File aarFile = new File(sdk.getSupportLibrary(), |
687 |
| - "/support-core-utils/" + SUPPORT_VER + "/support-core-utils-" + SUPPORT_VER + ".aar"); |
688 |
| - Util.copyFile(aarFile, new File(libsFolder, aarFile.getName())); |
689 |
| - |
690 |
| - aarFile = new File(sdk.getSupportLibrary(), |
691 |
| - "/support-compat/" + SUPPORT_VER + "/support-compat-" + SUPPORT_VER + ".aar"); |
692 |
| - Util.copyFile(aarFile, new File(libsFolder, aarFile.getName())); |
693 |
| - |
694 |
| - aarFile = new File(sdk.getSupportLibrary(), |
695 |
| - "/support-fragment/" + SUPPORT_VER + "/support-fragment-" + SUPPORT_VER + ".aar"); |
696 |
| - Util.copyFile(aarFile, new File(libsFolder, aarFile.getName())); |
697 |
| - |
698 |
| - aarFile = new File(sdk.getSupportLibrary(), |
699 |
| - "/support-vector-drawable/" + SUPPORT_VER + "/support-vector-drawable-" + SUPPORT_VER + ".aar"); |
700 |
| - Util.copyFile(aarFile, new File(libsFolder, aarFile.getName())); |
| 705 | + private void copySupportLibs(File libsFolder) throws IOException { |
| 706 | + copyAARFileFromSDK(sdk.getSupportLibrary() + "/support-core-utils/$VER", "support-core-utils-$VER.aar", SUPPORT_VER, libsFolder); |
| 707 | + copyAARFileFromSDK(sdk.getSupportLibrary() + "/support-compat/$VER", "support-compat-$VER.aar", SUPPORT_VER, libsFolder); |
| 708 | + copyAARFileFromSDK(sdk.getSupportLibrary() + "/support-fragment/$VER", "support-fragment-$VER.aar", SUPPORT_VER, libsFolder); |
| 709 | + copyAARFileFromSDK(sdk.getSupportLibrary() + "/support-vector-drawable/$VER", "support-vector-drawable-$VER.aar", SUPPORT_VER, libsFolder); |
701 | 710 | }
|
702 | 711 |
|
703 | 712 |
|
704 |
| - private void copyAppCompatLib(File tmpFolder, File libsFolder) |
705 |
| - throws IOException { |
706 |
| - File aarFile = new File(sdk.getSupportLibrary(), |
707 |
| - "/appcompat-v7/" + SUPPORT_VER + "/appcompat-v7-" + SUPPORT_VER + ".aar"); |
708 |
| - Util.copyFile(aarFile, new File(libsFolder, aarFile.getName())); |
| 713 | + private void copyAppCompatLib(File libsFolder) throws IOException { |
| 714 | + copyAARFileFromSDK(sdk.getSupportLibrary() + "/appcompat-v7/$VER", "appcompat-v7-$VER.aar", SUPPORT_VER, libsFolder); |
709 | 715 | }
|
710 | 716 |
|
711 | 717 |
|
712 | 718 | private void copyGVRLibs(File libsFolder) throws IOException {
|
713 |
| - File baseAarFile = mode.getContentFile("libraries/vr/gvrsdk/" + GVR_VER + "/sdk-base-" + GVR_VER + ".aar"); |
714 |
| - Util.copyFile(baseAarFile, new File(libsFolder, baseAarFile.getName())); |
715 |
| - |
716 |
| - File commonAarFile = mode.getContentFile("libraries/vr/gvrsdk/" + GVR_VER + "/sdk-common-" + GVR_VER + ".aar"); |
717 |
| - Util.copyFile(commonAarFile, new File(libsFolder, commonAarFile.getName())); |
718 |
| - |
719 |
| - File audioAarFile = mode.getContentFile("libraries/vr/gvrsdk/" + GVR_VER + "/sdk-audio-" + GVR_VER + ".aar"); |
720 |
| - Util.copyFile(audioAarFile, new File(libsFolder, audioAarFile.getName())); |
| 719 | + copyAARFileFromMode("/libraries/vr/gvrsdk/$VER", "sdk-base-$VER.aar", GVR_VER, libsFolder); |
| 720 | + copyAARFileFromMode("/libraries/vr/gvrsdk/$VER", "sdk-common-$VER.aar", GVR_VER, libsFolder); |
| 721 | + copyAARFileFromMode("/libraries/vr/gvrsdk/$VER", "sdk-audio-$VER.aar", GVR_VER, libsFolder); |
721 | 722 | }
|
722 | 723 |
|
723 | 724 |
|
724 |
| - private void copyDepFile(String baseFolder, String subfolder, String filename) { |
725 |
| -// File aarFile = new File(sdk.getSupportLibrary(), |
726 |
| -// "/support-core-utils/" + SUPPORT_VER + "/support-core-utils-" + SUPPORT_VER + ".aar"); |
727 |
| -// if (aarFile.exists()) { |
728 |
| -// Util.copyFile(aarFile, new File(libsFolder, aarFile.getName())); |
729 |
| -// } else { |
730 |
| -// // The specified version does not exist in the installed SDK, so gradle should be able to download it. |
731 |
| -// } |
| 725 | + private void copyAARFileFromSDK(String srcFolder, String filename, String version, File destFolder) |
| 726 | + throws IOException { |
| 727 | + String fn = filename.replace("$VER", version); |
| 728 | + File srcFile = new File(srcFolder.replace("$VER", version), fn); |
| 729 | + File destFile = new File(destFolder, fn); |
| 730 | + if (srcFile.exists()) { |
| 731 | + Util.copyFile(srcFile, destFile); |
| 732 | + } else { |
| 733 | + // If the AAR file does not exist in the installed SDK, gradle should be able to download it, and so |
| 734 | + // we don't to anything besides printing a warning. |
| 735 | + System.out.println("Warning: cannot find AAR package " + fn + " in installed SDK, gradle will try to download."); |
| 736 | + } |
732 | 737 | }
|
733 | 738 |
|
734 | 739 |
|
| 740 | + private void copyAARFileFromMode(String srcFolder, String filename, String version, File destFolder) |
| 741 | + throws IOException { |
| 742 | + String fn = filename.replace("$VER", version); |
| 743 | + File srcFile = mode.getContentFile(srcFolder.replace("$VER", version) + "/" + fn); |
| 744 | + File destFile = new File(destFolder, fn); |
| 745 | + if (srcFile.exists()) { |
| 746 | + Util.copyFile(srcFile, destFile); |
| 747 | + } else { |
| 748 | + // If the AAR file does not exist in the mode, gradle should be able to download it, and so |
| 749 | + // we don't to anything besides printing a warning. |
| 750 | + System.out.println("Warning: cannot find AAR package " + fn + " in Android mode, gradle will try to download"); |
| 751 | + } |
| 752 | + } |
| 753 | + |
| 754 | + |
735 | 755 | // ---------------------------------------------------------------------------
|
736 | 756 | // Export project
|
737 | 757 |
|
|
0 commit comments