Skip to content

Commit 4dfb730

Browse files
committed
tweaked init logic to support new SDK behavior
1 parent 2ef2393 commit 4dfb730

File tree

6 files changed

+62
-19
lines changed

6 files changed

+62
-19
lines changed

mode/languages/mode.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ menu.android.devices = Devices
2828
menu.android.devices.no_connected_devices = No connected devices
2929
menu.android.sdk_updater = SDK Updater
3030
menu.android.reset_adb = Reset ADB
31+
menu.android.accept_licenses = Accept SDK licenses
3132

3233
# | File | Edit | Sketch | Android | Tools | Help |
3334
# | Help |
@@ -174,6 +175,7 @@ android_sdk.error.missing_build_tools_folder = There is no build-tools folder in
174175
android_sdk.error.missing_platforms_folder = There is no platforms folder in %s
175176
android_sdk.error.missing_target_platform = There is no Android %s in %s
176177
android_sdk.error.missing_android_jar = android.jar for plaform %s is missing from %s
178+
android_sdk.error.missing_emulator = The emulator files are missing
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.
179181
android_debugger.error.request_removing_keystore = Please remove the file %s

mode/src/processing/mode/android/AndroidEditor.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,14 @@ public void actionPerformed(ActionEvent e) {
652652
}
653653
});
654654
androidMenu.add(item);
655+
656+
item = new JMenuItem(AndroidMode.getTextString("menu.android.accept_licenses"));
657+
item.addActionListener(new ActionListener() {
658+
public void actionPerformed(ActionEvent e) {
659+
androidMode.getSDK().acceptLicenses();
660+
}
661+
});
662+
androidMenu.add(item);
655663
}
656664

657665
private void initDebugger() {

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

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,13 @@ public AndroidSDK(File folder) throws BadSDKException, IOException {
9999
throw new BadSDKException(AndroidMode.getTextString("android_sdk.error.missing_sdk_folder", folder));
100100
}
101101

102-
cmdlineTools = new File(folder, "cmdline-tools");
103-
if (!cmdlineTools.exists()) {
104-
throw new BadSDKException(AndroidMode.getTextString("android_sdk.error.missing_tools_folder", folder));
105-
}
102+
File tmp = new File(folder, "cmdline-tools/latest");
103+
if (!tmp.exists()) {
104+
tmp = new File(folder, "tools");
105+
} else if (!tmp.exists()) {
106+
throw new BadSDKException(AndroidMode.getTextString("android_sdk.error.missing_tools_folder", folder));
107+
}
108+
cmdlineTools = tmp;
106109

107110
platformTools = new File(folder, "platform-tools");
108111
if (!platformTools.exists()) {
@@ -149,8 +152,18 @@ public AndroidSDK(File folder) throws BadSDKException, IOException {
149152
// First try the new location of the emulator inside its own folder
150153
emulator = findCliTool(emuFolder, "emulator");
151154
} else {
152-
// If not found, use old location inside tools
153-
emulator = findCliTool(cmdlineTools, "emulator");
155+
// If not found, use old location inside tools as fallback
156+
emuFolder = new File(cmdlineTools, "emulator");
157+
if (emuFolder.exists()) {
158+
emulator = findCliTool(cmdlineTools, "emulator");
159+
} else {
160+
emulator = null;
161+
if (SDKDownloader.DOWNLOAD_EMU) {
162+
// Only throw an exception if the downloader was supposed to download the emulator
163+
throw new BadSDKException(AndroidMode.getTextString("android_sdk.error.missing_emulator",
164+
AndroidBuild.TARGET_SDK, highestPlatform.getAbsolutePath()));
165+
}
166+
}
154167
}
155168

156169
String path = Platform.getenv("PATH");
@@ -285,10 +298,9 @@ public File getZipAlignTool() {
285298
// 10 just in case, having more does not cause any trouble.
286299
private static final String response = "y\ny\ny\ny\ny\ny\ny\ny\ny\ny\n";
287300

288-
private void acceptLicenses() {
301+
public void acceptLicenses() {
289302
final String[] cmd = new String[] {
290303
sdkManager.getAbsolutePath(),
291-
"--sdk_root=", folder.getAbsolutePath(),
292304
"--licenses"
293305
};
294306

@@ -489,7 +501,7 @@ static public AndroidSDK download(final Frame editor, final AndroidMode androidM
489501

490502
final int result = showSDKLicenseDialog(editor);
491503
if (result == JOptionPane.YES_OPTION) {
492-
sdk.acceptLicenses();
504+
// sdk.acceptLicenses();
493505
String msg = AndroidMode.getTextString("android_sdk.dialog.sdk_installed_body", PROCESSING_FOR_ANDROID_URL, WHATS_NEW_URL);
494506
File driver = AndroidSDK.getGoogleDriverFolder();
495507
if (Platform.isWindows() && driver.exists()) {

mode/src/processing/mode/android/AndroidUtil.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
import java.util.HashMap;
3232
import java.util.zip.ZipEntry;
3333
import java.util.zip.ZipFile;
34-
34+
import java.nio.file.Files;
35+
import java.nio.file.StandardCopyOption;
36+
3537
import javax.swing.JEditorPane;
3638
import javax.swing.JLabel;
3739
import javax.swing.JOptionPane;
@@ -295,5 +297,13 @@ static public boolean noFileExists(File[] files) {
295297
if (f.exists()) return false;
296298
}
297299
return true;
298-
}
300+
}
301+
302+
static public void moveDir(File from, File to) {
303+
try {
304+
Files.move(from.toPath(), to.toPath(), StandardCopyOption.REPLACE_EXISTING);
305+
} catch (IOException ex) {
306+
ex.printStackTrace();
307+
}
308+
}
299309
}

mode/src/processing/mode/android/EmulatorController.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ synchronized public void launch(final AndroidSDK sdk, final boolean wear)
7575
String gpuFlag = "auto";
7676

7777
final File emulator = sdk.getEmulatorTool();
78+
if (emulator == null || emulator.exists()) {
79+
System.err.println("EmulatorController: Emulator is not available.");
80+
return;
81+
}
82+
7883
final String[] cmd = new String[] {
7984
emulator.getCanonicalPath(),
8085
"-avd", avdName,

mode/src/processing/mode/android/SDKDownloader.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public class SDKDownloader extends JDialog implements PropertyChangeListener {
6666
private static final String REPOSITORY_LIST = "repository2-1.xml";
6767
private static final String ADDON_LIST = "addon2-1.xml";
6868

69-
private static final boolean DOWNLOAD_EMU = false;
69+
public static final boolean DOWNLOAD_EMU = false;
7070

7171
private JProgressBar progressBar;
7272
private JLabel downloadedTextArea;
@@ -133,23 +133,29 @@ protected Object doInBackground() throws Exception {
133133
getHaxmDownloadUrl(downloadUrls, haxmUrl, Platform.getName());
134134
firePropertyChange(AndroidMode.getTextString("download_property.change_event_total"), 0, downloadUrls.totalSize);
135135

136-
// command-line tools
136+
// Command-line tools
137137
File downloadedCmdLineTools = new File(tempFolder, downloadUrls.cmdlineToolsFilename);
138138
downloadAndUnpack(downloadUrls.cmdlineToolsUrl, downloadedCmdLineTools, sdkFolder, true);
139-
140-
// platform-tools
139+
File tmpFrom = new File(sdkFolder, "cmdline-tools");
140+
File tmpTo = new File(sdkFolder, "cmdline-tmp");
141+
AndroidUtil.moveDir(tmpFrom, tmpTo);
142+
File cmdlineToolsFolder = new File(sdkFolder, "cmdline-tools/latest");
143+
if (!cmdlineToolsFolder.exists()) cmdlineToolsFolder.mkdirs();
144+
AndroidUtil.moveDir(tmpTo, cmdlineToolsFolder);
145+
146+
// Platform tools
141147
File downloadedPlatformTools = new File(tempFolder, downloadUrls.platformToolsFilename);
142148
downloadAndUnpack(downloadUrls.platformToolsUrl, downloadedPlatformTools, sdkFolder, true);
143149

144-
// build-tools
150+
// Build tools
145151
File downloadedBuildTools = new File(tempFolder, downloadUrls.buildToolsFilename);
146152
downloadAndUnpack(downloadUrls.buildToolsUrl, downloadedBuildTools, buildToolsFolder, true);
147153

148-
// platform
154+
// Platform
149155
File downloadedPlatform = new File(tempFolder, downloadUrls.platformFilename);
150156
downloadAndUnpack(downloadUrls.platformUrl, downloadedPlatform, platformsFolder, false);
151157

152-
// usb driver
158+
// USB driver
153159
if (Platform.isWindows()) {
154160
File downloadedFolder = new File(tempFolder, downloadUrls.usbDriverFilename);
155161
downloadAndUnpack(downloadUrls.usbDriverUrl, downloadedFolder, googleRepoFolder, false);
@@ -162,7 +168,7 @@ protected Object doInBackground() throws Exception {
162168
}
163169

164170
if (DOWNLOAD_EMU) {
165-
// emulator, unpacks directly to sdk folder
171+
// Emulator, unpacks directly to sdk folder
166172
File downloadedEmulator = new File(tempFolder, downloadUrls.emulatorFilename);
167173
downloadAndUnpack(downloadUrls.emulatorUrl, downloadedEmulator, sdkFolder, true);
168174
}

0 commit comments

Comments
 (0)