Signing apk using jarSigner
Monkey Targets Forums/Android/Signing apk using jarSigner
| ||
So signing using JarSigner appears to be a big project in itself. Obviously it is partly because command line tools are not built for win8, however there gotta be a way to sign? First off it seems using any kind of path in the command prompt fails. However if I open the prompt in the same directory as the jarsigner directory it works. For creating the key using keytool I found that it worked if I copied keytool.exe and jli.dll to my android/bin folder (folder with my .apk) However when I move jarsigner I get this error: Error: Could not find or load main class sun.security.tools.JarSigner How can I fix so jarsigner can be moved?? Of course another option is to move my apk, the generated keystore to the C:\Program Files (x86)\Java\jdk1.7.0_13\bin folder. However on my system this folder has a magic copy-protection, so the jarsigner cannot output into it, or so it complains, even after I removed said copy-protection :( Any help appriciated! Is there any tool that is better than the outdated command promt to do this in? |
| ||
Okey, found a way to make it create a file in the protected folder.. Run Command prompt as Administrator. I then enter my command like this: jarsigner -sigalg SHA1withRSA -digestalg SHA1 -keystore ancient_raiders.keystore AncientRaiders-release-unaligned.apk ancient_raiders And now I get this: jarsigner: unable to sign jar: java.util.zip.ZipException: invalid entry compressed size (expected 1583 but got 1610 bytes) Okey... Got past that hurdle as well. After doing so many copies back and forth I by mistake took the .apk in which I hadn't removed the META-INF folder. Leaving this in case anyone in the future encounters the same :) However I'd still be happy for an answer on how to move the jarsigner or any tips on how to make this process easier. |
| ||
It's much easier to sign the apk through Eclipse. Just import the monkey generated code, and select to export it... Eclipse will ask you for your certificate, your password and will spit your signed apk, ready for distribution. |
| ||
Could you please explain how to do this through Eclipse. I tried it and I get: error: Error: No resource found that matches the given name (at 'icon' with value '@drawable/icon'). And so the project does not compile and I can't use the Wizard. Any ideas? How did you create the project? And what folder/files exactly did you import? |
| ||
That's what I do. As I see that you're using JDK 1.7 there might be a problem as the way you have to sign an apk has changed from 1.6 to 1.7 I use two batch files to create a key and sign it. First one to create a key (save as createkey.bat): "c:\Program Files (x86)"\Java\jdk1.7.0_17\bin\keytool -genkey -alias %1.keystore -sigalg MD5withRSA -keyalg RSA -keysize 1024 -validity 20000 -keystore %1.keystore Usage: createkey.bat appname Second one to sign and zip it (save as sign.bat): "c:\Program Files (x86)"\Java\jdk1.7.0_17\bin\jarsigner -sigalg MD5withRSA -digestalg SHA1 -verbose -keystore %1.keystore -signedjar %1-signed.apk %1.apk %1.keystore "c:\Program Files (x86)"\Android\android-sdk\tools\zipalign -v 4 %1-signed.apk %1-signed-zipped.apk Usage: sign.bat appname You will have now an apk called "appname-signed-zipped.apk" |
| ||
Guess what happens. I'm going to update because I got the wrong icons >< Simple I just need to do the jar-thing and the zip-thing using the new apk from Monkey. So I do a new build and the keystore and all folders in my bin folder is gone. A without the .keystore file I apparently need to take down the app and release it as a totally new app. I so I need to do the keytool thing again. Thanks Xaron, I'll try your bat-file approach! |
| ||
Xaron that made the whole process very simple! Thank you very much! :) |
| ||
:) You're welcome! :) |
| ||
It didn't end there. Obviously even tough the app wasn't published Google had no way to delete or reset the upload, so I really did have to create a new App. Not that big a deal I think, considering it is just a bunch of text and images. However it turns out I can no longer use the app id that I built the apk with, so I have to re-build. However this time rebuilding does not work and I get some weird java code compile errors. Usually this means that one should delete the build folder. However I can't because some App is using it. So I close all apps, even using the task bar and explorer.exe. Stil can't delete the build/android folder. So I restarted the computer. Remove the build folder. Compile. And of course I deleted the config.monkey file. Anyway, after doing this all uploading it again.. The icons are back to default... Need to build, change icons and then replace icons and rebuild again... So I'm doing this yet again. Getting funny because it is so much trouble for nothing lol. I think I'm going to make a game called "The Curse" and it should be about building and uploading an App. |
| ||
must you sign apps with jarsigner - or is this optional? and why should we do this? |
| ||
If you cannot delete the android build folder because an app is using it, it's almost certainly adb.exe. I noticed it hangs around after failed builds sometimes. Kill it in process manager, and then you'll be able to delete the build folder. |
| ||
@dragon - if you're testing you don't need to sign but you will if you want distribute it to stores and things. I use the following .bat (with prompts) to sign my apk's. I use the same keystore file for all projects. @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 |