Skip to content

Commit 2faeccb

Browse files
committed
store dependency versions in preferences, cleaned up code
1 parent 8675ece commit 2faeccb

File tree

2 files changed

+82
-63
lines changed

2 files changed

+82
-63
lines changed

core/src/processing/core/PApplet.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import java.io.*;
2828
import java.lang.reflect.*;
2929
import java.net.*;
30-
import java.nio.charset.StandardCharsets;
3130
import java.text.NumberFormat;
3231
import java.util.*;
3332
import java.util.regex.*;
@@ -65,8 +64,8 @@
6564

6665
public class PApplet extends Object implements ActivityAPI, PConstants {
6766

67+
static final public boolean DEBUG = false;
6868
// static final public boolean DEBUG = true;
69-
static final public boolean DEBUG = true;
7069

7170
// Convenience public constant holding the SDK version, akin to platform in Java mode
7271
static final public int SDK = Build.VERSION.SDK_INT;

src/processing/mode/android/AndroidBuild.java

Lines changed: 81 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import processing.mode.java.preproc.SurfaceInfo;
3737

3838
import java.io.*;
39-
import java.nio.file.Paths;
4039
import java.util.HashMap;
4140

4241
/**
@@ -71,14 +70,44 @@ class AndroidBuild extends JavaBuild {
7170
TARGET_PLATFORM = "android-" + TARGET_SDK;
7271
}
7372

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+
}
82111

83112
// Main activity or service
84113
static private final String APP_ACTIVITY_TEMPLATE = "AppActivity.java.tmpl";
@@ -231,10 +260,6 @@ protected File createProject(boolean external)
231260
preproc.initSketchSmooth(sketch.getMainProgram());
232261

233262
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-
238263
if (sketchClassName != null) {
239264
renderer = info.getRenderer();
240265
writeMainClass(srcFolder, renderer, external);
@@ -361,10 +386,10 @@ private void createAppModule(String moduleName)
361386
copyCodeFolder(libsFolder);
362387

363388
// Copy any system libraries needed by the project
364-
copyWearLib(tmpFolder, libsFolder);
365-
copySupportLibs(tmpFolder, libsFolder);
389+
copyWearLib(libsFolder);
390+
copySupportLibs(libsFolder);
366391
if (getAppComponent() == APP) {
367-
copyAppCompatLib(tmpFolder, libsFolder);
392+
copyAppCompatLib(libsFolder);
368393
}
369394
if (getAppComponent() == VR) {
370395
copyGVRLibs(libsFolder);
@@ -669,69 +694,64 @@ private void copyIcon(File srcFile, File destFile) throws IOException {
669694
// Dependencies
670695

671696

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
674699
// devices with android < 5 the dependencies of the PWatchFace* classes
675700
// 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);
678702
}
679703

680704

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);
701710
}
702711

703712

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);
709715
}
710716

711717

712718
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);
721722
}
722723

723724

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+
}
732737
}
733738

734739

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+
735755
// ---------------------------------------------------------------------------
736756
// Export project
737757

0 commit comments

Comments
 (0)