41
41
import java .io .IOException ;
42
42
import java .io .InputStream ;
43
43
import java .io .OutputStream ;
44
- import java .nio .file .DirectoryStream ;
45
44
import java .nio .file .Files ;
46
45
import java .nio .file .Path ;
47
46
import java .nio .file .Paths ;
53
52
import java .nio .file .attribute .PosixFilePermission ;
54
53
55
54
import java .io .PrintWriter ;
56
- import java .util .HashSet ;
57
55
import java .util .Set ;
58
56
59
57
/**
@@ -140,14 +138,14 @@ public AndroidSDK(File folder) throws BadSDKException, IOException {
140
138
}
141
139
142
140
// Retrieve the highest platform from the available targets
143
- ArrayList <SDKTarget > targets = getAvailableSdkTargets ();
144
- int highestIncremental = 1 ;
141
+ ArrayList <Target > targets = getAvailableSdkTargets ();
142
+ int highestBuild = 1 ;
145
143
int highestTarget = 1 ;
146
144
String highestName = "" ;
147
- for (SDKTarget targ : targets ) {
148
- if (highestIncremental < targ .version_incremental ) {
149
- highestIncremental = targ .version_incremental ;
150
- highestTarget = targ .version_sdk ;
145
+ for (Target targ : targets ) {
146
+ if (highestBuild < targ .build ) {
147
+ highestBuild = targ .build ;
148
+ highestTarget = targ .sdk ;
151
149
highestName = targ .name ;
152
150
}
153
151
}
@@ -157,23 +155,7 @@ public AndroidSDK(File folder) throws BadSDKException, IOException {
157
155
AndroidBuild .TARGET_SDK , platforms .getAbsolutePath ()));
158
156
}
159
157
160
- // Find the platform folder with the correct android.jar file.
161
- // Path platformPath = Paths.get(platforms.getAbsolutePath());
162
- // String highestPrefix = "android-" + highest;
163
- // File tmpFile;
164
- // try (DirectoryStream<Path> stream = Files.newDirectoryStream(platformPath, highestPrefix + "*")) {
165
- // for (Path entry: stream) {
166
- // if (Files.isDirectory(entry) && entry.getFileName().toString().startsWith(highestPrefix)) {
167
- // tmpFile = new File(entry.toString(), "android.jar");
168
- // if (tmpFile.exists()) {
169
- // System.out.println(tmpFile);
170
- // }
171
- // }
172
- // }
173
- // }
174
-
175
158
highestPlatform = new File (platforms , highestName );
176
-
177
159
androidJar = new File (highestPlatform , "android.jar" );
178
160
if (!androidJar .exists ()) {
179
161
throw new BadSDKException (AndroidMode .getTextString ("android_sdk.error.missing_android_jar" ,
@@ -893,44 +875,44 @@ public Process getAdbProcess(final String... cmd)
893
875
}
894
876
}
895
877
896
- static private class SDKTarget {
897
- public int version_sdk = 0 ;
898
- public String version_release = "" ;
899
- public int version_incremental = 0 ;
878
+ static private class Target {
879
+ public int sdk = 0 ;
880
+ public String release = "" ;
881
+ public int build = 0 ;
900
882
public String name = "" ;
901
883
}
902
884
903
- private ArrayList <SDKTarget > getAvailableSdkTargets () throws IOException {
904
- ArrayList <SDKTarget > targets = new ArrayList <SDKTarget >();
885
+ private ArrayList <Target > getAvailableSdkTargets () throws IOException {
886
+ ArrayList <Target > targets = new ArrayList <Target >();
905
887
906
888
for (File platform : platforms .listFiles ()) {
907
889
File propFile = new File (platform , "build.prop" );
908
890
if (!propFile .exists ()) continue ;
909
891
910
- SDKTarget target = new SDKTarget ();
892
+ Target target = new Target ();
911
893
912
894
BufferedReader br = new BufferedReader (new FileReader (propFile ));
913
895
String line ;
914
896
while ((line = br .readLine ()) != null ) {
915
897
String [] lineData = line .split ("=" );
916
898
917
899
if (lineData [0 ].equals ("ro.system.build.version.incremental" )) {
918
- target .version_incremental = Integer .valueOf (lineData [1 ]);
900
+ target .build = Integer .valueOf (lineData [1 ]);
919
901
}
920
902
921
903
if (lineData [0 ].equals ("ro.build.version.release" )) {
922
- target .version_release = lineData [1 ];
904
+ target .release = lineData [1 ];
923
905
}
924
906
925
907
if (lineData [0 ].equals ("ro.build.version.sdk" )) {
926
- target .version_sdk = Integer .valueOf (lineData [1 ]);
908
+ target .sdk = Integer .valueOf (lineData [1 ]);
927
909
}
928
910
929
911
target .name = platform .getName ();
930
912
}
931
913
br .close ();
932
914
933
- if (target .version_sdk != 0 && target .version_incremental != 0 && target .name != "" ) targets .add (target );
915
+ if (target .sdk != 0 && target .build != 0 && target .name != "" ) targets .add (target );
934
916
}
935
917
936
918
return targets ;
0 commit comments