Skip to content

Commit 08a0406

Browse files
committed
Generate key store file if not exists
1 parent 390cd49 commit 08a0406

File tree

2 files changed

+63
-8
lines changed

2 files changed

+63
-8
lines changed

src/processing/mode/android/AndroidBuild.java

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,21 @@
2121

2222
package processing.mode.android;
2323

24-
import java.io.*;
25-
26-
import org.apache.tools.ant.*;
27-
28-
import processing.app.*;
29-
import processing.app.exec.*;
24+
import org.apache.tools.ant.BuildException;
25+
import org.apache.tools.ant.DefaultLogger;
26+
import org.apache.tools.ant.Project;
27+
import org.apache.tools.ant.ProjectHelper;
28+
import processing.app.Base;
29+
import processing.app.Library;
30+
import processing.app.Sketch;
31+
import processing.app.SketchException;
32+
import processing.app.exec.ProcessHelper;
33+
import processing.app.exec.ProcessResult;
3034
import processing.core.PApplet;
3135
import processing.mode.java.JavaBuild;
3236

37+
import java.io.*;
38+
3339

3440
class AndroidBuild extends JavaBuild {
3541
// static final String basePackage = "changethispackage.beforesubmitting.tothemarket";
@@ -267,17 +273,64 @@ public File exportProject() throws IOException, SketchException {
267273
return null;
268274
}
269275

270-
public File exportPackage() throws IOException, SketchException {
276+
public File exportPackage() throws IOException, SketchException, InterruptedException {
271277
File projectFolder = build("release");
272278
if(projectFolder == null) return null;
273279

274-
// TODO all the signing magic needs to happen here
280+
File keyStore = getKeyStore();
281+
if(keyStore == null) return null;
275282

276283
File exportFolder = createExportFolder();
277284
Base.copyDir(projectFolder, exportFolder);
278285
return new File(exportFolder, "/bin/");
279286
}
280287

288+
private File getKeyStore() throws IOException, InterruptedException {
289+
File keyStoreFolder = new File(sketch.getFolder(), "keystore");
290+
if(!keyStoreFolder.exists()) {
291+
boolean result = keyStoreFolder.mkdirs();
292+
293+
if(!result) {
294+
Base.showWarning("Folders, folders, folders",
295+
"Could not create the necessary folders to build.\n" +
296+
"Perhaps you have some file permissions to sort out?", null);
297+
return null;
298+
}
299+
}
300+
301+
File keyStore = new File(keyStoreFolder, sketch.getName() + "-release-key.keystore");
302+
if(!keyStore.exists()) {
303+
String dname = "CN=Unknown, OU=Unknown, O=Unknown, L=Unknown, S=Unknown, C=Unknown";
304+
// TODO Generate password and store it with alias in some accessible place
305+
String password = "generatedpasswordhere";
306+
307+
String[] args = {
308+
"keytool", "-genkey",
309+
"-keystore", keyStore.getCanonicalPath(),
310+
"-alias", sketch.getName(),
311+
"-keyalg", "RSA",
312+
"-keysize", "2048",
313+
"-validity", "10000",
314+
"-keypass", password,
315+
"-storepass", password,
316+
"-dname", dname
317+
};
318+
319+
Process generation = Runtime.getRuntime().exec(args);
320+
generation.waitFor();
321+
322+
// any better ways to check if it is created now?
323+
keyStore = new File(keyStore.getCanonicalPath());
324+
if(!keyStore.exists()) {
325+
Base.showWarning("Failed to create key store",
326+
"There was an error while creating the key store");
327+
return null;
328+
}
329+
}
330+
331+
return keyStore;
332+
}
333+
281334
/*
282335
// SDK tools 17 have a problem where 'dex' won't pick up the libs folder
283336
// (which contains our friend processing-core.jar) unless your current

src/processing/mode/android/AndroidEditor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,8 @@ public void run() {
393393
statusError(e);
394394
} catch (SketchException e) {
395395
statusError(e);
396+
} catch (InterruptedException e) {
397+
e.printStackTrace();
396398
}
397399
stopIndeterminate();
398400
}

0 commit comments

Comments
 (0)