Skip to content

Commit e827f92

Browse files
committed
does not crash id installed platform is higher than target
1 parent 7a25626 commit e827f92

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

mode/src/processing/mode/android/AndroidSDK.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class AndroidSDK {
6161
private final File folder;
6262
private final File tools;
6363
private final File platforms;
64-
private final File targetPlatform;
64+
private final File highestPlatform;
6565
private final File androidJar;
6666
private final File platformTools;
6767
private final File buildTools;
@@ -118,16 +118,27 @@ public AndroidSDK(File folder) throws BadSDKException, IOException {
118118
throw new BadSDKException(AndroidMode.getTextString("android_sdk.error.missing_platforms_folder", folder));
119119
}
120120

121-
targetPlatform = new File(platforms, AndroidBuild.TARGET_PLATFORM);
122-
if (!targetPlatform.exists()) {
121+
// Retrieve the highest platform from the available targets
122+
ArrayList<SDKTarget> targets = getAvailableSdkTargets();
123+
int highest = 1;
124+
for (SDKTarget targ: targets) {
125+
System.out.println(targ);
126+
if (highest < targ.version) {
127+
highest = targ.version;
128+
}
129+
}
130+
131+
if (highest < PApplet.parseInt(AndroidBuild.TARGET_SDK)) {
123132
throw new BadSDKException(AndroidMode.getTextString("android_sdk.error.missing_target_platform",
124-
AndroidBuild.TARGET_SDK, platforms.getAbsolutePath()));
133+
AndroidBuild.TARGET_SDK, platforms.getAbsolutePath()));
125134
}
135+
136+
highestPlatform = new File(platforms, "android-" + highest);
126137

127-
androidJar = new File(targetPlatform, "android.jar");
138+
androidJar = new File(highestPlatform, "android.jar");
128139
if (!androidJar.exists()) {
129140
throw new BadSDKException(AndroidMode.getTextString("android_sdk.error.missing_android_jar",
130-
AndroidBuild.TARGET_SDK, targetPlatform.getAbsolutePath()));
141+
AndroidBuild.TARGET_SDK, highestPlatform.getAbsolutePath()));
131142
}
132143

133144
avdManager = findCliTool(new File(tools, "bin"), "avdmanager");
@@ -218,8 +229,8 @@ public File getSdkFolder() {
218229
}
219230

220231

221-
public File getTargetPlatform() {
222-
return targetPlatform;
232+
public File getHighestPlatform() {
233+
return highestPlatform;
223234
}
224235

225236
public File getAndroidJarPath() {
@@ -750,7 +761,7 @@ static class SDKTarget {
750761
public ArrayList<SDKTarget> getAvailableSdkTargets() throws IOException {
751762
ArrayList<SDKTarget> targets = new ArrayList<SDKTarget>();
752763

753-
for(File platform : platforms.listFiles()) {
764+
for (File platform : platforms.listFiles()) {
754765
File propFile = new File(platform, "build.prop");
755766
if (!propFile.exists()) continue;
756767

0 commit comments

Comments
 (0)