Skip to content

Commit e4463d9

Browse files
authored
Merge pull request #548 from DeerajTheepshi/android-0274-v4.1.0-beta3
GSOC19 work from Deeraj
2 parents de881bd + 2afe132 commit e4463d9

File tree

4 files changed

+445
-172
lines changed

4 files changed

+445
-172
lines changed

mode/languages/mode.properties

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ android_mode.dialog.cannot_export_package_body = The sketch still has the defaul
8888
android_mode.dialog.cannot_use_default_icons_title = Cannot export package...
8989
android_mode.dialog.cannot_use_default_icons_body = The sketch does not include all required app icons. Processing could use its default set of Android icons, which are okay to test the app on your device, but a bad idea to distribute it on the Play store. Create a full set of unique icons for your app, and copy them into the sketch folder. Once you have done that, try exporting the sketch again.<br><br>For more info on distributing apps from Processing,<br>check <a href=\"%s\">this online tutorial</a>.
9090
android_mode.warn.cannot_load_sdk_title = Bad news...
91-
android_mode.warn.cannot_load_sdk_body = The Android SDK could not be loaded.\nThe Android Mode will be disabled.
91+
android_mode.warn.broken_sdk_folder = Your SDK path seems to be broken as %s
92+
android_mode.warn.cannot_load_sdk_body = The Android SDK could not be loaded, because:\n%s.\nThe Android Mode will be disabled.
9293
android_mode.info.cannot_open_sdk_path = "Android SDK path couldn't be opened.";
9394
android_mode.error.cannot_create_avd = "Could not create a virtual device for the emulator.";
9495
android_mode.dialog.no_devices_found_title = No devices found!
@@ -139,16 +140,17 @@ android_sdk.dialog.found_installed_sdk_body = Processing found a valid Android S
139140
android_sdk.option.use_existing_sdk = Use existing SDK
140141
android_sdk.option.download_new_sdk = Download new SDK
141142
android_sdk.dialog.cannot_find_sdk_title = Cannot find an Android SDK...
142-
android_sdk.dialog.cannot_find_sdk_body = Processing did not find an Android SDK on this computer. If there is one, and you know where it is, click \"Locate SDK path\" to select it, or \"Download SDK\" to let Processing download the SDK automatically.<br><br>If you want to download the SDK manually, you can get the command line tools from <a href=\"%s\">here</a>. Make sure to install the SDK platform for API %s.
143+
android_sdk.dialog.cannot_find_sdk_body = Processing did not find an Android SDK on this computer. If there is one, and you know where it is, click \"Locate SDK path\" to select it, or \"Download SDK\" to let Processing download the SDK automatically.<br><br>If you want to download the SDK manually, you can get the command line tools from <a href=\"%s\">here</a>. Make sure to install the SDK platform for API 26 or higher.
143144
android_sdk.dialog.invalid_sdk_title = Android SDK is not valid...
144-
android_sdk.dialog.invalid_sdk_body = Processing found an Android SDK, but is not valid. It could be missing some files, or might not be including the required platform for API %s.<br><br>If a valid SDK is available in a different location, click \"Locate SDK path\" to select it, or \"Download SDK\" to let Processing download the SDK automatically.<br><br>If you want to download the SDK manually, you can get the command line tools from <a href=\"%s\">here</a>. Make sure to install the SDK platform for API %s.
145+
android_sdk.dialog.invalid_sdk_body = Processing found an Android SDK, but is not valid. It could be missing some files, or might not be including the required platform for API 26 or higher.<br><br>If a valid SDK is available in a different location, click \"Locate SDK path\" to select it, or \"Download SDK\" to let Processing download the SDK automatically.<br><br>If you want to download the SDK manually, you can get the command line tools from <a href=\"%s\">here</a>. Make sure to install the SDK platform for API 26 or higher.
145146
android_sdk.option.download_sdk = Download SDK automatically
146147
android_sdk.option.locate_sdk = Locate SDK path manually
147148
android_sdk.dialog.download_phone_image_title = Download phone system image?
148149
android_sdk.dialog.download_phone_image_body = The system image needed by the emulator does not appear to be installed. Do you want Processing to download and install it now?
149150
android_sdk.dialog.download_watch_image_title = Download watch system image?
150151
android_sdk.dialog.download_watch_image_body = The system image needed by the emulator does not appear to be installed. Do you want Processing to download and install it now?
151152
android_sdk.dialog.select_sdk_folder = Choose the location of the Android SDK
153+
android_sdk.error.cancel_sdk_selection = User cancelled SDK path selection
152154
android_sdk.error.sdk_selection_canceled = User canceled attempt to find SDK
153155
android_sdk.error.sdk_download_canceled = User canceled SDK download
154156
android_sdk.error.sdk_download_failed = SDK could not be downloaded
@@ -172,7 +174,7 @@ android_sdk.error.missing_tools_folder = There is no tools folder in %s
172174
android_sdk.error.missing_platform_tools_folder = There is no platform-tools folder in %s
173175
android_sdk.error.missing_build_tools_folder = There is no build-tools folder in %s
174176
android_sdk.error.missing_platforms_folder = There is no platforms folder in %s
175-
android_sdk.error.missing_target_platform = There is no Android %s in %s
177+
android_sdk.error.missing_target_platform = There is no Android %s (or greater) in %s
176178
android_sdk.error.missing_android_jar = android.jar for plaform %s is missing from %s
177179
android_debugger.info.removing_expired_keystore = Removing expired debug.keystore file.
178180
android_debugger.error.cannot_remove_expired_keystore = Could not remove the expired debug.keystore file.
@@ -259,6 +261,8 @@ sdk_downloader.error_cannot_find_emulator = Cannot find the emulator
259261
sdk_downloader.error.cannot_unpack_platform = Error unpacking platform to "%s"
260262
sdk_downloader.download_title = SDK download
261263
sdk_downloader.download_sdk_label = Downloading Android SDK...
264+
sdk_downloader.download_error_title = Incomplete download
265+
sdk_downloader.download_error_message = SDK Installation is incomplete due to: \n%s
262266

263267
# ---------------------------------------
264268
# System image downloader

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,17 @@ public void checkSDK(Editor editor) {
157157
if (userCancelledSDKSearch) return;
158158
checkingSDK = true;
159159
Throwable tr = null;
160-
if (sdk == null) {
160+
Boolean broken = false;
161+
if (sdk != null) { //when mode changes, sdk object is not recreated, this ensures that
162+
try {
163+
sdk = new AndroidSDK(sdk.getSdkFolder());
164+
} catch (AndroidSDK.BadSDKException | IOException e) {
165+
Messages.showWarning(AndroidMode.getTextString("android_mode.warn.cannot_load_sdk_title"),
166+
AndroidMode.getTextString("android_mode.warn.broken_sdk_folder",e.getMessage()));
167+
broken = true;
168+
}
169+
}
170+
if (sdk == null || broken) {
161171
try {
162172
sdk = AndroidSDK.load(true, editor);
163173
if (sdk == null) {
@@ -171,8 +181,8 @@ public void checkSDK(Editor editor) {
171181
}
172182
}
173183
if (sdk == null) {
174-
Messages.showWarning(AndroidMode.getTextString("android_mode.warn.cannot_load_sdk_title"),
175-
AndroidMode.getTextString("android_mode.warn.cannot_load_sdk_body"), tr);
184+
Messages.showWarning(AndroidMode.getTextString("android_mode.warn.cannot_load_sdk_title"),
185+
AndroidMode.getTextString("android_mode.warn.cannot_load_sdk_body",tr.getMessage()), tr);
176186
} else {
177187
Devices devices = Devices.getInstance();
178188
devices.setSDK(sdk);

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

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ class AndroidSDK {
9292
private static final int INVALID_SDK = 3;
9393
private static int loadError = NO_ERROR;
9494

95+
private static boolean backOptionSelected;
96+
9597
public AndroidSDK(File folder) throws BadSDKException, IOException {
9698
this.folder = folder;
9799
if (!folder.exists()) {
@@ -117,11 +119,17 @@ public AndroidSDK(File folder) throws BadSDKException, IOException {
117119
if (!platforms.exists()) {
118120
throw new BadSDKException(AndroidMode.getTextString("android_sdk.error.missing_platforms_folder", folder));
119121
}
120-
121-
targetPlatform = new File(platforms, AndroidBuild.TARGET_PLATFORM);
122+
123+
String[] availPlatforms = platforms.list();
124+
int maxVersion = 26;
125+
for (String availPlatform:availPlatforms){
126+
int platformVersion = Integer.parseInt(availPlatform.substring(availPlatform.length()-2));
127+
if (platformVersion >= maxVersion) maxVersion = platformVersion;
128+
}
129+
targetPlatform = new File(platforms, "android-"+maxVersion);
122130
if (!targetPlatform.exists()) {
123131
throw new BadSDKException(AndroidMode.getTextString("android_sdk.error.missing_target_platform",
124-
AndroidBuild.TARGET_SDK, platforms.getAbsolutePath()));
132+
maxVersion, platforms.getAbsolutePath()));
125133
}
126134

127135
androidJar = new File(targetPlatform, "android.jar");
@@ -133,6 +141,8 @@ public AndroidSDK(File folder) throws BadSDKException, IOException {
133141
avdManager = findCliTool(new File(tools, "bin"), "avdmanager");
134142
sdkManager = findCliTool(new File(tools, "bin"), "sdkmanager");
135143

144+
Preferences.set("android.sdk.target",maxVersion+"");
145+
136146
String path = Platform.getenv("PATH");
137147

138148
Platform.setenv("ANDROID_SDK", folder.getCanonicalPath());
@@ -403,11 +413,17 @@ public static AndroidSDK load(boolean checkEnvSDK, Frame editor) throws IOExcept
403413

404414
static public AndroidSDK locate(final Frame window, final AndroidMode androidMode)
405415
throws BadSDKException, CancelException, IOException {
406-
416+
backOptionSelected = false;
417+
407418
if (loadError == SKIP_ENV_SDK) {
408419
// The user does not want to use the environment SDK, so let's simply
409420
// download a new one to the sketchbook folder.
410-
return download(window, androidMode);
421+
AndroidSDK sdk = download(window, androidMode);
422+
if(sdk==null && backOptionSelected){
423+
return locate(window,androidMode);
424+
} else {
425+
return sdk;
426+
}
411427
}
412428

413429
// At this point, there is no ANDROID_SDK env variable, no SDK in the preferences,
@@ -416,7 +432,11 @@ static public AndroidSDK locate(final Frame window, final AndroidMode androidMod
416432
int result = showLocateDialog(window);
417433

418434
if (result == JOptionPane.YES_OPTION) {
419-
return download(window, androidMode);
435+
AndroidSDK sdk = download(window, androidMode);
436+
if(sdk==null && backOptionSelected){
437+
return locate(window,androidMode);
438+
}
439+
return sdk;
420440
} else if (result == JOptionPane.NO_OPTION) {
421441
// User will manually select folder containing SDK folder
422442
File folder = selectFolder(AndroidMode.getTextString("android_sdk.dialog.select_sdk_folder"), null, window);
@@ -448,9 +468,13 @@ static public boolean locateSysImage(final Frame window,
448468
static public AndroidSDK download(final Frame editor, final AndroidMode androidMode)
449469
throws BadSDKException, CancelException {
450470
final SDKDownloader downloader = new SDKDownloader(editor);
451-
downloader.run(); // This call blocks until the SDK download complete, or user cancels.
452-
453-
if (downloader.cancelled()) {
471+
//downloader.run(); // This call blocks until the SDK download complete, or user cancels.
472+
473+
if (downloader.isGoBack()){
474+
backOptionSelected = true;
475+
return null;
476+
}
477+
else if (downloader.cancelled()) {
454478
throw new CancelException(AndroidMode.getTextString("android_sdk.error.sdk_download_canceled"));
455479
}
456480
AndroidSDK sdk = downloader.getSDK();

0 commit comments

Comments
 (0)