Processing Android – Signing an Android app

How to sign an Android app, generated with Processing Android (or generated with another tool)?

Create a (Windows-) batch file (.bat) with the following code:

@echo off
ECHO.
set /p varSketchName="Please enter the Name of your sketch: "
ECHO.
set /p varSketchAlias="Please enter an Alias for your sketch: "
ECHO.
ECHO [KEYTOOL]
keytool -genkey -v -keystore %~dp0%varSketchName%-release-key.keystore -alias %varSketchAlias% -keyalg RSA -keysize 2048 -validity 10000
pause
ECHO [ANT RELEASE]
call ant release
pause
ECHO [JARSIGNER]
call jarsigner -verbose -keystore %~dp0%varSketchName%-release-key.keystore %~dp0bin\%varSketchName%-release-unsigned.apk %varSketchAlias%
pause
ECHO [JARSIGNER VERIFY]
call jarsigner -verify %~dp0bin\%varSketchName%-release-unsigned.apk
pause
ECHO [ZIPALIGN]
set /p varSignedAppName="Please enter name for final signed apk (w/o .apk extension): "
call zipalign -v 4 %~dp0bin\%varSketchName%-release-unsigned.apk %~dp0%varSignedAppName%.apk

Programs you need:

  • keytool.exe (part of the Java JDK)
  • ant.bat (part of Apache ant)
  • jarsigner.exe (part of the Java JDK)
  • zipalign.exe (part of the Android SDK)

Steps:

  1. In Processing: create your sketch in Android Mode
  2. Export the sketch as an Android Project (Ctrl-Shift-E)
  3. Copy the .bat-file above to the newly created android directory and run it
  4. Name of your sketch = name of the .pde-file (without .pde!)
  5. Alias = same as the name (or something else)
  6. Enter a password for your keystore
  7. Enter your personal data
  8. Enter the same keystore password again
  9. Enter the name of the final .apk-file (without the .apk extension!)

N.B. Make sure your folder names DON’T include any SPACES! That will break the batch file.

And there you go! You’ve got a signed .apk file!


Processing – Error building Android for Processing project

Problem:
Error while building an Android for Processing v2.x project:
“Error from inside the Android tools, check the console.”

Fix:
Edit the file “C:\adt-bundle-windows-x86-20131030\sdk\tools\ant\build.xml
(Of course adjust the path to where your Android SDK is living… this fix works for Mac OSX too)

<!-- RvG changed to true -->
<property name="dex.disable.merger" value="true" />

If that doesn’t fix the problem have a look here:
http://forum.processing.org/one/topic/android-problems.html