|
21 | 21 |
|
22 | 22 | package processing.mode.android;
|
23 | 23 |
|
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; |
30 | 34 | import processing.core.PApplet;
|
31 | 35 | import processing.mode.java.JavaBuild;
|
32 | 36 |
|
| 37 | +import java.io.*; |
| 38 | + |
33 | 39 |
|
34 | 40 | class AndroidBuild extends JavaBuild {
|
35 | 41 | // static final String basePackage = "changethispackage.beforesubmitting.tothemarket";
|
@@ -267,17 +273,64 @@ public File exportProject() throws IOException, SketchException {
|
267 | 273 | return null;
|
268 | 274 | }
|
269 | 275 |
|
270 |
| - public File exportPackage() throws IOException, SketchException { |
| 276 | + public File exportPackage() throws IOException, SketchException, InterruptedException { |
271 | 277 | File projectFolder = build("release");
|
272 | 278 | if(projectFolder == null) return null;
|
273 | 279 |
|
274 |
| - // TODO all the signing magic needs to happen here |
| 280 | + File keyStore = getKeyStore(); |
| 281 | + if(keyStore == null) return null; |
275 | 282 |
|
276 | 283 | File exportFolder = createExportFolder();
|
277 | 284 | Base.copyDir(projectFolder, exportFolder);
|
278 | 285 | return new File(exportFolder, "/bin/");
|
279 | 286 | }
|
280 | 287 |
|
| 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 | + |
281 | 334 | /*
|
282 | 335 | // SDK tools 17 have a problem where 'dex' won't pick up the libs folder
|
283 | 336 | // (which contains our friend processing-core.jar) unless your current
|
|
0 commit comments