Help signing .apk

Monkey Targets Forums/Android/Help signing .apk

Supertino(Posted 2012) [#1]
We'll I have been following therevills guide;

http://www.monkeycoder.co.nz/Community/post.php?topic=1014&post=8800

which everyone but me seem to be able to follow with no issues.

I am failing on the 2nd part it seems (signing).

Doesn't help that I don't fully understand why we have to do this so if someone could explain that would be super.

Here is what I am doing.

Pre-stage
=========
1. compile the game
2. rename "MonkeyGame-debug.apk" to "mygame.apk"
3. create a folder on my e drive "e:\test\" and put mygame.apk in there
4. open the mygame.apk and delete the META-INF folder

Stage 1 (create a keystore file called mykey)
=======
1. create a folder in my "e:\test\" location called "keystore" and a folder inside keystore called "keys" (e:\test\keystore\keys)

2. open cmd (as admin)

3. cd to C:\Program Files (x86)\Java\jdk1.7.0_07\bin\

4. keytool -genkey -alias mykey.keystore -keyalg RSA -validity 20000 -keystore e:/game/keystore/keys/mykey.keystore

5. answer questions

6. I don't understand why it wants me to set another password? so i hit enter.

7. mykey.keystore is now in e:\game\keystore\keys\


Stage 2
=======

1. cd to C:\Program Files (x86)\Java\jdk1.7.0_07\bin\

2. jarsigner -verbose -keystore e:/test/keystore/keys/mykey.keystore -signedjar e:/test/mygame-signed.apk e:/test/mygame.apk e:/test/keystore/keys/mykey.keystore

I get error;
jarsigner: Certificate chain not found for: e:/test/keystore/keys/mykey.keystore.
e:/test/keystore/keys/mykey.keystore must reference a valid KeyStore key entry containing a private key and corresponding public key certificate chain.


I have done this many times starting from scratch I did somehow get it to sign once then I zip-aligned it but it would not install on my device?

Just don't see what is going wrong? I am at the end of tether, spent all day getting videos, screen shots and various other promo stuff made and I get stuck as the last bit. grrrrrr


Supertino(Posted 2012) [#2]
ok well I think I got it, jarsigner needs two extra switches if you have JDK7

-digestalg SHA1 -sigalg MD5withRSA


Used these and it went through ok? and installed but did give some error, going to install JDK 6.0.24


Supertino(Posted 2012) [#3]
ok good so installing 6.0.24 made all my troubles go away.

I also found this rather neat .bat file. That does the signing and zipping.

@echo off
Title Sign an unsigned apk
set OLDDIR=%CD%


cls
echo.
echo You will need to copy your keystore file
echo eg. my-release-key.keystore
echo into the same folder as this script.
echo.
echo Please place your unsigned app in the same 
echo directory as this program, when you have
echo done this please type in its name below:
echo.
echo.
set /p apk= What is the filename (including the .apk at the end)?  
echo Your app is named %apk% 
echo.
echo.
echo while creating your Private Key, what did you put as your ALIASNAME?
set /p alias= Aliasname 
echo. 
echo Is the Java JDK in your path?
echo if you do not know what this means, please type "N"
CHOICE /C:YN /M "Java JDK in path?"
If errorlevel 2 goto nojdk
If errorlevel 1 goto jdk

:nojdk
echo.
echo.
echo It is recommended that you put the jdk in your path
echo To see how please visit this web page:
echo http://www.oracle.com/technetwork/java/javase/documentation/install-windows-152927.html
echo.
echo.
pause
cls
echo.
echo.
:jdk
echo ok, you will need to type in your password when prompted

jarsigner.exe -verbose -keystore  my-release-key.keystore %apk% %alias%
echo.
echo. 
echo Checking it is signed correctly
jarsigner -verify %apk%
echo.
echo If you got an error you probably
echo compiled your apk with a key
echo (probably the debug key).
echo Try recompiling it without signing
echo and then copy and paste the
echo resulting temp.ap_ file here.
echo.
echo.
echo Now we just need to zipalign the apk
echo. 
echo.
echo.
set /p final= What do you want the finished apk to be called?:     
echo %final% it is
echo. 
pause
zipalign -v 4 %apk% %final%
echo.
echo.
pause
cls
Pause