public void createProject( AndroidSDK target, String projectName, File path, String activity, String packageName) throws CoreException { IStatus status = HybridProjectConventions.validateProjectName(projectName); if (!status.isOK()) throw new CoreException(status); // activity class name matches the project name status = HybridProjectConventions.validateProjectName(activity); if (!status.isOK()) throw new CoreException(status); status = HybridProjectConventions.validateProjectID(packageName); if (!status.isOK()) throw new CoreException(status); ExternalProcessUtility processUtility = new ExternalProcessUtility(); StringBuilder command = new StringBuilder(); command.append(getAndroidCommand()); command.append(" create project"); command.append(" --target ").append(target.getId()); command.append(" --path ").append('"').append(path.getPath()).append('"'); command.append(" --name ").append('"').append(projectName).append('"'); command.append(" --activity ").append(activity); command.append(" --package ").append(packageName); CreateProjectResultParser parser = new CreateProjectResultParser(); processUtility.execSync( command.toString(), null, parser, parser, new NullProgressMonitor(), null, null); if (parser.getErrorString() != null) { throw new CoreException( new Status( IStatus.ERROR, AndroidCore.PLUGIN_ID, "Error creating the Android project: " + parser.getErrorString())); } }
public List<AndroidSDK> getSDKList() { if (buffer == null || buffer.length() < 1) return null; StringReader reader = new StringReader(buffer.toString()); BufferedReader read = new BufferedReader(reader); ArrayList<AndroidSDK> sdkList = new ArrayList<AndroidSDK>(); String line = null; try { AndroidSDK sdk = null; while ((line = read.readLine()) != null) { final int scolIdx = line.indexOf(':'); if (scolIdx < 0) { continue; } String[] pair = new String[2]; pair[0] = line.substring(0, scolIdx).trim(); pair[1] = line.substring(scolIdx + 1).trim(); if ("id".equalsIgnoreCase(pair[0])) { sdk = new AndroidSDK(); sdkList.add(sdk); int vIndex = pair[1].indexOf("or"); sdk.setId(pair[1].substring(vIndex + "or".length()).replace("\"", "")); } else if ("Type".equalsIgnoreCase(pair[0])) { Assert.isNotNull(sdk); sdk.setType(pair[1].trim()); } else if ("API level".equalsIgnoreCase(pair[0])) { Assert.isNotNull(sdk); sdk.setApiLevel(Integer.parseInt(pair[1])); } } } catch (IOException e) { AndroidCore.log(IStatus.ERROR, "Error parsing the SDK list", e); } finally { try { read.close(); reader.close(); } catch (IOException e) { // ignored } } return sdkList; }
protected boolean create(final AndroidSDK sdk) throws IOException { final String[] params = { sdk.getAndroidToolPath(), "create", "avd", "-n", name, "-t", target, "-c", DEFAULT_SDCARD_SIZE, "-s", DEFAULT_SKIN, "--abi", "armeabi" }; // Set the list to null so that exists() will check again avdList = null; final ProcessHelper p = new ProcessHelper(params); try { // Passes 'no' to "Do you wish to create a custom hardware profile [no]" // System.out.println("CREATE AVD STARTING"); final ProcessResult createAvdResult = p.execute("no"); // System.out.println("CREATE AVD HAS COMPLETED"); if (createAvdResult.succeeded()) { return true; } if (createAvdResult.toString().contains("Target id is not valid")) { // They didn't install the Google APIs Base.showWarningTiered("Android Error", AVD_TARGET_PRIMARY, AVD_TARGET_SECONDARY, null); // throw new IOException("Missing required SDK components"); } else { // Just generally not working // Base.showWarning("Android Error", AVD_CREATE_ERROR, null); Base.showWarningTiered("Android Error", AVD_CREATE_PRIMARY, AVD_CREATE_SECONDARY, null); System.out.println(createAvdResult); // throw new IOException("Error creating the AVD"); } // System.err.println(createAvdResult); } catch (final InterruptedException ie) { } return false; }
protected static void list(final AndroidSDK sdk) throws IOException { try { avdList = new ArrayList<String>(); badList = new ArrayList<String>(); ProcessResult listResult = new ProcessHelper(sdk.getAndroidToolPath(), "list", "avds").execute(); if (listResult.succeeded()) { boolean badness = false; for (String line : listResult) { String[] m = PApplet.match(line, "\\s+Name\\:\\s+(\\S+)"); if (m != null) { if (!badness) { // System.out.println("good: " + m[1]); avdList.add(m[1]); } else { // System.out.println("bad: " + m[1]); badList.add(m[1]); } // } else { // System.out.println("nope: " + line); } // "The following Android Virtual Devices could not be loaded:" if (line.contains("could not be loaded:")) { // System.out.println("starting the bad list"); // System.err.println("Could not list AVDs:"); // System.err.println(listResult); badness = true; // break; } } } else { System.err.println("Unhappy inside exists()"); System.err.println(listResult); } } catch (final InterruptedException ie) { } }