Skip to content

Commit 17471ce

Browse files
committed
fixed SDK download, simplified target setting
1 parent 551ca4e commit 17471ce

File tree

5 files changed

+59
-25
lines changed

5 files changed

+59
-25
lines changed

src/processing/mode/android/AVD.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ protected boolean create(final AndroidSDK sdk) throws IOException {
203203
}
204204
} catch (InterruptedException e) {}
205205

206-
if (preferredAbi.get(AndroidBuild.target_api_level) == null) {
206+
if (preferredAbi.get(AndroidBuild.target_sdk) == null) {
207207
return false;
208208
}
209209

@@ -214,7 +214,7 @@ protected boolean create(final AndroidSDK sdk) throws IOException {
214214
"-t", target,
215215
"-c", DEFAULT_SDCARD_SIZE,
216216
"-s", DEFAULT_SKIN,
217-
"--abi", preferredAbi.get(AndroidBuild.target_api_level)
217+
"--abi", preferredAbi.get(AndroidBuild.target_sdk)
218218
};
219219

220220
// Set the list to null so that exists() will check again
@@ -267,7 +267,7 @@ static public boolean ensureProperAVD(final AndroidSDK sdk) {
267267
// Base.showWarning("Android Error", AVD_CREATE_ERROR, e);
268268
Messages.showWarningTiered("Android Error", AVD_CREATE_PRIMARY,
269269
String.format(AVD_CREATE_SECONDARY,
270-
AndroidBuild.target_api_level), null);
270+
AndroidBuild.target_sdk), null);
271271
}
272272
return false;
273273
}

src/processing/mode/android/AndroidBuild.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,8 @@ class AndroidBuild extends JavaBuild {
6666
static public final String min_sdk_watchface = "21"; // Lollipop (5.0)
6767

6868
// Hard-coded target SDK, no longer user-selected.
69-
static public final String target_sdk_version = "5.1"; // Lollipop
70-
static public final String target_api_level = "22";
71-
static public final String target_platform = "android-" + target_api_level;
69+
static public final String target_sdk = "22"; // Lollipop (5.1)
70+
static public final String target_platform = "android-" + target_sdk;
7271

7372
static public int appComponent = FRAGMENT;
7473
static boolean forceNewManifest = false;
@@ -173,7 +172,7 @@ public File createProject() throws IOException, SketchException {
173172
}
174173

175174
manifest = new Manifest(sketch);
176-
manifest.setSdkTarget(target_api_level);
175+
manifest.setSdkTarget(target_sdk);
177176
forceNewManifest = false;
178177

179178
// grab code from current editing window (GUI only)
@@ -275,7 +274,7 @@ public File createProject() throws IOException, SketchException {
275274
}
276275

277276
if (platform != null && platform.equals(target_platform) &&
278-
api != null && api.equals(target_api_level)) {
277+
api != null && api.equals(target_sdk)) {
279278
targetID = id;
280279
break;
281280
}
@@ -769,10 +768,9 @@ void antBuildProblems(String outPile, String errPile) throws SketchException {
769768
if (line.contains("Unable to resolve target '" + target_platform + "'")) {
770769
System.err.println("Use the Android SDK Manager (under the Android");
771770
System.err.println("menu) to install the SDK platform and ");
772-
System.err.println("Google APIs for Android " + target_sdk_version +
773-
" (API " + target_api_level + ")");
771+
System.err.println("Google APIs for Android " + target_sdk);
774772
skex = new SketchException("Please install the SDK platform and " +
775-
"Google APIs for API " + target_api_level);
773+
"Google APIs for Android " + target_sdk);
776774
}
777775
}
778776
// Stack trace is not relevant, just the message.

src/processing/mode/android/AndroidMode.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
import java.io.BufferedInputStream;
4040
import java.io.BufferedOutputStream;
4141
import java.io.File;
42+
import java.nio.file.Path;
43+
import java.nio.file.Paths;
4244
import java.io.FileOutputStream;
4345
import java.io.IOException;
4446
import java.text.SimpleDateFormat;
@@ -201,8 +203,16 @@ public String getSearchPath() {
201203
return "";
202204
}
203205

204-
String path = sdk.getSdkFolder().getAbsolutePath() + File.separator +
205-
"platforms" + File.separator + "android-";
206+
/*
207+
Path path = Paths.get(sdk.getSdkFolder().getAbsolutePath(),
208+
"platforms", AndroidBuild.target_platform,
209+
"android.jar").toAbsolutePath();
210+
211+
// String path = new File().getAbsolutePath();
212+
//
213+
//
214+
// sdk.getSdkFolder().getAbsolutePath() + File.separator +
215+
// "platforms" + File.separator + "android-";
206216
String level = AndroidBuild.target_api_level;
207217
String name = AndroidBuild.target_sdk_version;
208218
String androidJarPath = path + level + File.separator + "android.jar";
@@ -214,9 +224,10 @@ public String getSearchPath() {
214224
return "";
215225
}
216226
}
227+
*/
217228

218-
String processingAndroidCoreJarPath = new File(getFolder(), "android-core.zip").getAbsolutePath();
219-
return androidJarPath + File.pathSeparatorChar + processingAndroidCoreJarPath;
229+
String coreJarPath = new File(getFolder(), "android-core.zip").getAbsolutePath();
230+
return sdk.getAndroidJarPath().getAbsolutePath() + File.pathSeparatorChar + coreJarPath;
220231
}
221232

222233

src/processing/mode/android/AndroidSDK.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class AndroidSDK {
4545
private final File tools;
4646
private final File platforms;
4747
private final File targetPlatform;
48+
private final File androidJar;
4849
private final File platformTools;
4950
private final File androidTool;
5051

@@ -60,8 +61,7 @@ class AndroidSDK {
6061
"If you want to download the SDK manually, you can visit <br>"+
6162
"http://developer.android.com/sdk/installing/index.html <br>" +
6263
"and select the stand-alone SDK tools. Make sure to install <br>"+
63-
"the SDK platform for Android " + AndroidBuild.target_sdk_version +
64-
" (API level " + AndroidBuild.target_api_level + ") or higher.";
64+
"the SDK platform for API " + AndroidBuild.target_sdk + ".";
6565

6666
private static final String SELECT_ANDROID_SDK_FOLDER =
6767
"Choose the location of the Android SDK";
@@ -90,9 +90,15 @@ public AndroidSDK(File folder) throws BadSDKException, IOException {
9090
targetPlatform = new File(platforms, AndroidBuild.target_platform);
9191
if (!targetPlatform.exists()) {
9292
throw new BadSDKException("There is no Android " +
93-
AndroidBuild.target_sdk_version + " in " + platforms.getAbsolutePath());
93+
AndroidBuild.target_sdk + " in " + platforms.getAbsolutePath());
9494
}
9595

96+
androidJar = new File(targetPlatform, "android.jar");
97+
if (!androidJar.exists()) {
98+
throw new BadSDKException("android.jar for plaform " +
99+
AndroidBuild.target_sdk + " is missing from " + targetPlatform.getAbsolutePath());
100+
}
101+
96102
androidTool = findAndroidTool(tools);
97103

98104
String path = Platform.getenv("PATH");
@@ -182,6 +188,11 @@ public File getSdkFolder() {
182188
}
183189

184190

191+
public File getAndroidJarPath() {
192+
return androidJar;
193+
}
194+
195+
185196
public File getPlatformToolsFolder() {
186197
return platformTools;
187198
}

src/processing/mode/android/SDKDownloader.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@
4949

5050
@SuppressWarnings("serial")
5151
public class SDKDownloader extends JDialog implements PropertyChangeListener {
52-
// Version and API level are both used to avoid ambiguity with preview versions,
53-
// which might share the API level with the earlier stable platform.
54-
private static final String PLATFORM_VERSION = "6.0";
55-
private static final String PLATFORM_API_LEVEL = "23";
56-
5752
private static final String URL_REPOSITORY = "https://dl-ssl.google.com/android/repository/repository-11.xml";
5853
private static final String URL_REPOSITORY_FOLDER = "http://dl-ssl.google.com/android/repository/";
5954
private static final String URL_USB_DRIVER = "https://dl-ssl.google.com//android/repository/latest_usb_driver_windows.zip";
@@ -74,6 +69,7 @@ public class SDKDownloader extends JDialog implements PropertyChangeListener {
7469
private int totalSize = 0;
7570

7671
class SDKUrlHolder {
72+
public String platformVersion;
7773
public String platformToolsUrl, buildToolsUrl, platformUrl, toolsUrl;
7874
public String platformToolsFilename, buildToolsFilename, platformFilename, toolsFilename;
7975
public int totalSize = 0;
@@ -128,7 +124,7 @@ protected Object doInBackground() throws Exception {
128124
// platform
129125
File downloadedPlatform = new File(tempFolder, downloadUrls.platformFilename);
130126
downloadAndUnpack(downloadUrls.platformUrl, downloadedPlatform, platformsFolder, false);
131-
127+
132128
// usb driver
133129
if (Platform.isWindows()) {
134130
File usbDriverFolder = new File(extrasFolder, "google");
@@ -142,6 +138,17 @@ protected Object doInBackground() throws Exception {
142138

143139
tempFolder.delete();
144140

141+
// Normalize platform folder to android-<API LEVEL>
142+
File expectedPath = new File(platformsFolder, "android-" + AndroidBuild.target_sdk);
143+
File actualPath = new File(platformsFolder, "android-" + downloadUrls.platformVersion);
144+
if (!expectedPath.exists()) {
145+
if (actualPath.exists()) {
146+
actualPath.renameTo(expectedPath);
147+
} else {
148+
throw new IOException("Error unpacking platform to " + actualPath.getAbsolutePath());
149+
}
150+
}
151+
145152
// Done, let's set the environment and load the new SDK!
146153
Platform.setenv("ANDROID_SDK", sdkFolder.getAbsolutePath());
147154
Preferences.set("android.sdk.path", sdkFolder.getAbsolutePath());
@@ -209,14 +216,21 @@ private SDKUrlHolder getDownloadUrls(String repositoryUrl, String requiredHostOs
209216
Document doc = db.parse(new URL(repositoryUrl).openStream());
210217

211218
// platform
219+
String platformDescription = "Android SDK Platform " + AndroidBuild.target_sdk;
212220
NodeList platformList = doc.getElementsByTagName("sdk:platform");
213221
for (int i = 0; i < platformList.getLength(); i++) {
214222
Node platform = platformList.item(i);
215223
NodeList version = ((Element) platform).getElementsByTagName("sdk:version");
216224
NodeList level = ((Element) platform).getElementsByTagName("sdk:api-level");
217-
if (version.item(0).getTextContent().equals(PLATFORM_VERSION) && level.item(0).getTextContent().equals(PLATFORM_API_LEVEL)) {
225+
NodeList desc = ((Element) platform).getElementsByTagName("sdk:description");
226+
// API level and platform description are both used to avoid ambiguity with
227+
// preview versions, which might share the API level with the earlier stable
228+
// platform, but use the letter codename in their description.
229+
if (level.item(0).getTextContent().equals( AndroidBuild.target_sdk) &&
230+
desc.item(0).getTextContent().equals(platformDescription)) {
218231
Node archiveListItem = ((Element) platform).getElementsByTagName("sdk:archives").item(0);
219232
Node archiveItem = ((Element) archiveListItem).getElementsByTagName("sdk:archive").item(0);
233+
urlHolder.platformVersion = version.item(0).getTextContent();
220234
urlHolder.platformUrl = ((Element) archiveItem).getElementsByTagName("sdk:url").item(0).getTextContent();
221235
urlHolder.platformFilename = urlHolder.platformUrl.split("/")[urlHolder.platformUrl.split("/").length-1];
222236
urlHolder.totalSize += Integer.parseInt(((Element) archiveItem).getElementsByTagName("sdk:size").item(0).getTextContent());

0 commit comments

Comments
 (0)