I had the same problem and here is how I do it. My Unity is 3.4 and Java JDK 7.45.
private key
You must generate one using Keytool located in Java bin folder. In my case C:\Program Files\Java\jdk1.7.0_51\bin.
JSE is not enough, download JDK from Java web site.
Run → cmd, navigate Command prompt to our JDK\bin folder (cd C:\Program Files\Java\jdk1.7.0_51\bin) and type:
keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000
in my case:
keytool -genkey -v -keystore stnicholas.keystore -alias stnicholas -keyalg RSA -keysize 2048 -validity 10000
Running the command above, Keytool prompts you to provide passwords and other data. It then generates the keystore as a file called my-release-key.keystore, stnicholas.keystore in my case.
compile the application
In order to release your application to users, you must compile it in release mode. In release mode, the compiled application is not signed by default and you will need to sign it with your private key from above.
From Unity:
Use your private key and leave application Unsigned.
modify .apk file
Rename your .apk file to .zip or open it with 7zip or similar software.
Remove META-INF folder, make other changes you need, for example place drawable-xhdpi,hdpi,mdpi,ldpi in res folder. Rename it back to .apk if Zip is used.
Signing
Use Jarsigner tool located in Java bin folder. In my case C:\Program Files\Java\jdk1.7.0_51\bin
Place your .keystore and .apk file to folder.
Run → cmd, navigate Command prompt to our JDK\bin folder and type:
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.keystore my_application.apk alias_name
in my case:
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore stnicholas.keystore StNicholas.apk stnicholas
Jarsigner prompts you to provide passwords, it then modifies the .apk, meaning the APK is now signed.
To verify that your APK is signed, type this:
jarsigner -verify my_application.apk
If the package is signed properly, Jarsigner prints “jar verified”.
align .apk
Run zipalign on signed application package. This tool is provided with the Android SDK, inside the tools/ directory. In my case C:\adt-bundle-windows-x86\sdk ools.
Zipalign provides a performance optimization for Android system.
Place your .apk file to folder sdk ools and rename it. In my case from StNicholas.apk to StNicholas2.apk
Run → cmd, navigate Command prompt to our tools folder and type:
zipalign -v 4 your_project_name-unaligned.apk your_project_name.apk
in my case:
zipalign -v 4 StNicholas2.apk StNicholas.apk
That’s it. your_project_name.apk, or in my case StNicholas.apk, is your signed Android application.