Skip to content

Commit 0041ab9

Browse files
committed
read build versions from properties file when mode starts up
1 parent 4f10a9d commit 0041ab9

File tree

2 files changed

+81
-61
lines changed

2 files changed

+81
-61
lines changed

mode/src/processing/mode/android/AndroidBuild.java

Lines changed: 78 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
import java.io.*;
3939
import java.util.HashMap;
40+
import java.util.Properties;
4041

4142
/**
4243
* Class with all the infrastructure needed to build a sketch in the Android
@@ -53,71 +54,20 @@ class AndroidBuild extends JavaBuild {
5354
static public final int AR = 4;
5455

5556
// Minimum SDK's API levels required for each component:
56-
static public final String MIN_SDK_APP = "17"; // Android 4.2
57-
static public final String MIN_SDK_WALLPAPER = "17"; // Android 4.2
58-
static public final String MIN_SDK_VR = "19"; // Android 4.4
59-
static public final String MIN_SDK_AR = "24"; // Android 7.0.0
60-
static public final String MIN_SDK_WATCHFACE = "25"; // Android 7.1.1
57+
static public String MIN_SDK_APP;
58+
static public String MIN_SDK_WALLPAPER;
59+
static public String MIN_SDK_VR;
60+
static public String MIN_SDK_AR;
61+
static public String MIN_SDK_WATCHFACE;
6162

62-
// Target SDK is stored in the preferences file.
63+
// Versions of all required dependencies
6364
static public String TARGET_SDK;
6465
static public String TARGET_PLATFORM;
65-
static {
66-
TARGET_SDK = Preferences.get("android.sdk.target");
67-
if (TARGET_SDK == null || PApplet.parseInt(TARGET_SDK) < 26) {
68-
TARGET_SDK = "26";
69-
Preferences.set("android.sdk.target", TARGET_SDK);
70-
}
71-
TARGET_PLATFORM = "android-" + TARGET_SDK;
72-
}
73-
74-
// Versions of support, play services, wear and VR in use, also stored in
75-
// preferences file so they can be changed without having to rebuilt/reinstall
76-
// the mode.
7766
static public String SUPPORT_VER;
78-
static {
79-
SUPPORT_VER = Preferences.get("android.sdk.support");
80-
if (SUPPORT_VER == null || !versionCheck(SUPPORT_VER, "26.0.2")) {
81-
SUPPORT_VER = "26.0.2";
82-
Preferences.set("android.sdk.support", SUPPORT_VER);
83-
}
84-
}
85-
8667
static public String PLAY_SERVICES_VER;
87-
static {
88-
PLAY_SERVICES_VER = Preferences.get("android.sdk.play_services");
89-
if (PLAY_SERVICES_VER == null || !versionCheck(PLAY_SERVICES_VER, "11.0.4")) {
90-
PLAY_SERVICES_VER = "11.0.4";
91-
Preferences.set("android.sdk.play_services", PLAY_SERVICES_VER);
92-
}
93-
}
94-
9568
static public String WEAR_VER;
96-
static {
97-
WEAR_VER = Preferences.get("android.sdk.wear");
98-
if (WEAR_VER == null || !versionCheck(WEAR_VER, "2.1.0")) {
99-
WEAR_VER = "2.1.0";
100-
Preferences.set("android.sdk.wear", WEAR_VER);
101-
}
102-
}
103-
10469
static public String GVR_VER;
105-
static {
106-
GVR_VER = Preferences.get("android.sdk.gvr");
107-
if (GVR_VER == null || !versionCheck(GVR_VER, "1.150.0")) {
108-
GVR_VER = "1.150.0";
109-
Preferences.set("android.sdk.gvr", GVR_VER);
110-
}
111-
}
112-
11370
static public String GAR_VER;
114-
static {
115-
GAR_VER = Preferences.get("android.sdk.ar");
116-
if (GAR_VER == null) {
117-
GAR_VER = "1.2.0";
118-
Preferences.set("android.sdk.ar", GAR_VER);
119-
}
120-
}
12171

12272
// Main activity or service
12373
static private final String APP_ACTIVITY_TEMPLATE = "AppActivity.java.tmpl";
@@ -375,7 +325,7 @@ private void createAppModule(String moduleName)
375325
File appBuildFile = new File(moduleFolder, "build.gradle");
376326
HashMap<String, String> replaceMap = new HashMap<String, String>();
377327
replaceMap.put("@@tools_folder@@", Base.getToolsFolder().getPath().replace('\\', '/'));
378-
replaceMap.put("@@target_platform@@", sdk.getTargetPlatform().getPath().replace('\\', '/'));
328+
replaceMap.put("@@target_platform@@", TARGET_SDK);
379329
replaceMap.put("@@package_name@@", getPackageName());
380330
replaceMap.put("@@min_sdk@@", minSdk);
381331
replaceMap.put("@@target_sdk@@", TARGET_SDK);
@@ -825,9 +775,9 @@ private void copyImportedLibs(final File libsFolder,
825775
for (File exportFile : library.getAndroidExports()) {
826776
String exportName = exportFile.getName();
827777

828-
// Skip the GVR and ARCore jars, because the gradle will resolve the dependencies
829-
if (appComponent == VR && exportName.toLowerCase().startsWith("sdk-")) continue;
830-
if (appComponent == AR && exportName.toLowerCase().startsWith("core-")) continue;
778+
// Skip the GVR and ARCore jars, because gradle will resolve the dependencies
779+
if (appComponent == VR && exportName.toLowerCase().startsWith("sdk")) continue;
780+
if (appComponent == AR && exportName.toLowerCase().startsWith("core")) continue;
831781

832782
if (!exportFile.exists()) {
833783
System.err.println(AndroidMode.getTextString("android_build.error.export_file_does_not_exist", exportFile.getName()));
@@ -935,6 +885,73 @@ private File createExportFolder(String name) throws IOException {
935885
}
936886

937887

888+
static public void initVersions(File file) {
889+
InputStream input;
890+
try {
891+
input = new FileInputStream(file);
892+
Properties props = new Properties();
893+
props.load(input);
894+
895+
MIN_SDK_APP = props.getProperty("android-min-app");
896+
MIN_SDK_WALLPAPER = props.getProperty("android-min-wallpaper");
897+
MIN_SDK_VR = props.getProperty("android-min-vr");
898+
MIN_SDK_AR = props.getProperty("android-min-ar");
899+
MIN_SDK_WATCHFACE = props.getProperty("android-min-wear");
900+
901+
// Versions of the target sdk, support, play services, wear, VR, and AR are stored in
902+
// preferences file so they can be changed by the user without having to rebuilt/reinstall
903+
// the mode.
904+
905+
TARGET_SDK = Preferences.get("android.sdk.target");
906+
String defTargetSDK = props.getProperty("android-platform");
907+
if (TARGET_SDK == null || PApplet.parseInt(TARGET_SDK) != PApplet.parseInt(defTargetSDK)) {
908+
TARGET_SDK = defTargetSDK;
909+
Preferences.set("android.sdk.target", TARGET_SDK);
910+
}
911+
TARGET_PLATFORM = "android-" + TARGET_SDK;
912+
913+
SUPPORT_VER = Preferences.get("android.sdk.support");
914+
String defSupportVer = props.getProperty("com.android.support%support-v4");
915+
if (SUPPORT_VER == null || !versionCheck(SUPPORT_VER, defSupportVer)) {
916+
SUPPORT_VER = defSupportVer;
917+
Preferences.set("android.sdk.support", SUPPORT_VER);
918+
}
919+
920+
PLAY_SERVICES_VER = Preferences.get("android.sdk.play_services");
921+
String defPlayServicesVer = props.getProperty("com.google.android.gms%play-services-wearable");
922+
if (PLAY_SERVICES_VER == null || !versionCheck(PLAY_SERVICES_VER, defPlayServicesVer)) {
923+
PLAY_SERVICES_VER = defPlayServicesVer;
924+
Preferences.set("android.sdk.play_services", PLAY_SERVICES_VER);
925+
}
926+
927+
WEAR_VER = Preferences.get("android.sdk.wear");
928+
String defWearVer = props.getProperty("com.google.android.support%wearable");
929+
if (WEAR_VER == null || !versionCheck(WEAR_VER, defWearVer)) {
930+
WEAR_VER = defWearVer;
931+
Preferences.set("android.sdk.wear", WEAR_VER);
932+
}
933+
934+
GVR_VER = Preferences.get("android.sdk.gvr");
935+
String defVRVer = props.getProperty("com.google.vr");
936+
if (GVR_VER == null || !versionCheck(GVR_VER, defVRVer)) {
937+
GVR_VER = defVRVer;
938+
Preferences.set("android.sdk.gvr", GVR_VER);
939+
}
940+
941+
GAR_VER = Preferences.get("android.sdk.ar");
942+
String defARVer = props.getProperty("com.google.ar");
943+
if (GAR_VER == null || !versionCheck(GAR_VER, defARVer)) {
944+
GAR_VER = defARVer;
945+
Preferences.set("android.sdk.ar", GAR_VER);
946+
}
947+
} catch (FileNotFoundException e) {
948+
e.printStackTrace();
949+
} catch (IOException e) {
950+
e.printStackTrace();
951+
}
952+
}
953+
954+
938955
static private boolean versionCheck(String currentVersion, String minVersion) {
939956
String[] currentPieces = currentVersion.split("\\.");
940957
String[] minPieces = minVersion.split("\\.");

mode/src/processing/mode/android/AndroidMode.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ public class AndroidMode extends JavaMode {
6262
// Using this temporarily until support for mode translations is finalized in the Processing app
6363
private static Map<String, String> textStrings = null;
6464

65+
private static final String VERSIONS_FILE = "version.properties";
66+
6567
private static final String BLUETOOTH_DEBUG_URL =
6668
"https://developer.android.com/training/wearables/apps/debugging.html";
6769

@@ -70,6 +72,7 @@ public class AndroidMode extends JavaMode {
7072

7173
public AndroidMode(Base base, File folder) {
7274
super(base, folder);
75+
AndroidBuild.initVersions(getContentFile(VERSIONS_FILE));
7376
loadTextStrings();
7477
}
7578

0 commit comments

Comments
 (0)