@@ -61,7 +61,7 @@ class AndroidSDK {
61
61
private final File folder ;
62
62
private final File tools ;
63
63
private final File platforms ;
64
- private final File targetPlatform ;
64
+ private final File highestPlatform ;
65
65
private final File androidJar ;
66
66
private final File platformTools ;
67
67
private final File buildTools ;
@@ -118,16 +118,27 @@ public AndroidSDK(File folder) throws BadSDKException, IOException {
118
118
throw new BadSDKException (AndroidMode .getTextString ("android_sdk.error.missing_platforms_folder" , folder ));
119
119
}
120
120
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 )) {
123
132
throw new BadSDKException (AndroidMode .getTextString ("android_sdk.error.missing_target_platform" ,
124
- AndroidBuild .TARGET_SDK , platforms .getAbsolutePath ()));
133
+ AndroidBuild .TARGET_SDK , platforms .getAbsolutePath ()));
125
134
}
135
+
136
+ highestPlatform = new File (platforms , "android-" + highest );
126
137
127
- androidJar = new File (targetPlatform , "android.jar" );
138
+ androidJar = new File (highestPlatform , "android.jar" );
128
139
if (!androidJar .exists ()) {
129
140
throw new BadSDKException (AndroidMode .getTextString ("android_sdk.error.missing_android_jar" ,
130
- AndroidBuild .TARGET_SDK , targetPlatform .getAbsolutePath ()));
141
+ AndroidBuild .TARGET_SDK , highestPlatform .getAbsolutePath ()));
131
142
}
132
143
133
144
avdManager = findCliTool (new File (tools , "bin" ), "avdmanager" );
@@ -218,8 +229,8 @@ public File getSdkFolder() {
218
229
}
219
230
220
231
221
- public File getTargetPlatform () {
222
- return targetPlatform ;
232
+ public File getHighestPlatform () {
233
+ return highestPlatform ;
223
234
}
224
235
225
236
public File getAndroidJarPath () {
@@ -750,7 +761,7 @@ static class SDKTarget {
750
761
public ArrayList <SDKTarget > getAvailableSdkTargets () throws IOException {
751
762
ArrayList <SDKTarget > targets = new ArrayList <SDKTarget >();
752
763
753
- for (File platform : platforms .listFiles ()) {
764
+ for (File platform : platforms .listFiles ()) {
754
765
File propFile = new File (platform , "build.prop" );
755
766
if (!propFile .exists ()) continue ;
756
767
0 commit comments