Noobs guide to signing an APK with a Private Key

Search This thread

AndroidGraphix

Senior Member
Apr 4, 2011
1,266
377
Paradise Valley, AZ
Noobs guide to signing an APK with a Private Key

Credit:

Tommytomatoe - For walking me through the setup/process/commands.


What you'll need to sign an APK.

SDK found here>> Java SDK
*For most users the java_ee_sdk-6u3-jdk7-windows.exe will be the one selected.

*After Install, restart your PC.

Next, open your command prompt

Type: cd C:\Program Files\Java\jre1.6.0_07\bin
*It highly likely, the jre1.6.... will be different. If it's close, then select it. I prefer to type cd c:\pro(pressing tab will automatically complete/find the remaining part of the directory)

If you're on Windows 7, the correct path is

Code:
c:\program files\Java\jdk1.7.0_01\bin

Creating your Private Key

Make sure you're in the directory stated above. We will now create a signed key. Below is an example of what we're going to do. I'll break it down in noob terms after.

Code:
keytool -genkey -v -keystore $KEYSTORE -alias $ALIAS -keyalg RSA -keysize 2048 -validity 10000

skin.keystore meaning

The part of the command that contains your information will be skin.keystore and 12215. The "skin" part of skin.keystore is your release key name. I named my skin because this key will be for all the Skins I upload to the market.

[Q] Do I need to have .keystore after my key name?
[A] Yes. It must look like: skin.keystore otherwise the command will not be complete.

12215 meaning

This is like a second password. Remember this, because it will be referenced when signing an APK. I used 12215. You can use johnsmith or anything else.

keytool -genkey -v -keystore skin.keystore -alias 12215 -keyalg RSA -keysize 2048 -validity 10000


Code:
keytool -genkey -v -keystore SAMPLE.keystore -alias SAMPLE -keyalg RSA -keysize 2048 -validity 10000

In the above my key is called "SAMPLE.keystore". Its alias (kind of like an additional password) is "SAMPLE". After you hit enter it will prompt for password. When you type it won't show up on screen (to protect your password)
-Tommytomatoe

Here is an example of the above:

skinstore1.jpg


Keep in mind, if you don't remember your alias you won't be able to use your key
-Tommytomatoe

**IMPORTANT

After you press enter to create the key, it will prompt you for a password. The program mask your password so others won't see it. So when you type it will appear as if no password is being entered.

Your key is stored in the directory you created it in. You won't need to find the file when signing an APK, because it's stored for you already. I'll go into detail of how to access your password in the next step.

How to sign an APK with the Private Key you created.

Anytime you sign an APK, you'll need to open command prompt then type:

Code:
cd c:\Program Files\Java\jdk1.6.0_26\bin
*Keep in mind your jdk1.6.0... might be different than the above.

The following is an example of what you'll copy and paste into command prompt.

Code:
jarsigner -verbose -keystore skin.keystore -signedjar DRAG-DROP-RENAME-APK-NAME DRAG-DROP alias

In the above example, "DRAG-DROP-RENAME-APK-NAME" is telling you to drag your APK into the command prompt and to rename it. Example below.

apkdraganddrop.jpg


You can see below my command prompt after I dragged and dropped my apk into cmd. I also deleted "DRAG-DROP alias" from the command line to make it easier to see the changes I'm doing.

dropapkone.jpg


After you drag and drop, rename your apk to "New-NOVSKIN1.apk", shown below.

renameapkdrag.jpg


Below you'll see, after I renamed the apk, I dragged and dropped the same apk from above into the command directory again. This time, we're not going to rename it. Instead, after you drop it a second time into command prompt, we're going to type our alias at the end. Pictured below:

dragdroprenamealias.jpg


**NOTE

The reason we drag and drop is to SAVE TIME. Tommytomatoe showed me this shortcut and it saves a ton of time from having to type everything out.

After entering this command, and executing it, the apk will now be signed. Congrats!
 
Last edited:

ffdiablos

Member
Dec 6, 2011
14
0
Do you still have the example pictures? This tutorial would help me no end but I'm struggling to make sense of it without any examples!! (newbie, I know!)
 

ffdiablos

Member
Dec 6, 2011
14
0
That's great news, thanks for your help. I'm starting to find there are some very helpful people on this site!:D
 

rawrv42

Member
Dec 30, 2011
40
3
Lowell
I don't seem to be able to drag and drop the .apk into CMD. Not sure if I'm doing anything wrong. I'm running windows 7 if that helps at all. Other than that it was a very clear and helpful tutorial. Just stuck there...ya, i know, im a newb XD
Thanks
~Vrawr

Edit:I followed everything spot on up to that point. And as I drag the .apk into CMD there's the plus sign by the mouse to show that it can be added, but once I release it into CMD, it doesn't appear...hence my problem
 
Last edited:

AndroidGraphix

Senior Member
Apr 4, 2011
1,266
377
Paradise Valley, AZ
I don't seem to be able to drag and drop the .apk into CMD. Not sure if I'm doing anything wrong. I'm running windows 7 if that helps at all. Other than that it was a very clear and helpful tutorial. Just stuck there...ya, i know, im a newb XD
Thanks
~Vrawr

Edit:I followed everything spot on up to that point. And as I drag the .apk into CMD there's the plus sign by the mouse to show that it can be added, but once I release it into CMD, it doesn't appear...hence my problem

I haven't a clue why that's happening. Maybe you don't have the latest jdk or sdk installed. I'm also running Windows Seven.

Sent from my ADR6425LVW using xda premium
 

rawrv42

Member
Dec 30, 2011
40
3
Lowell
I haven't a clue why that's happening. Maybe you don't have the latest jdk or sdk installed. I'm also running Windows Seven.

Sent from my ADR6425LVW using xda premium

I made sure I had the latest JDK installed several times. As for the SDK I downloaded the one you provided, the Java SDK. I am probably just going to redownload everything.
Thanks for your time, :)
Vrawr
 

rawrv42

Member
Dec 30, 2011
40
3
Lowell
okay, so i redownloaded everything and tried all over again. (i still couldnt drag in the app so i typed the directory in manually) and even with hours of effort, i ended with the message:

Error: Could not find or load main class sun.security.tools.Jarsigner

CMD doesnt close or anything, just that error appears... :confused:
Any ideas?
Thanks,
~Vrawr
 

AndroidGraphix

Senior Member
Apr 4, 2011
1,266
377
Paradise Valley, AZ
okay, so i redownloaded everything and tried all over again. (i still couldnt drag in the app so i typed the directory in manually) and even with hours of effort, i ended with the message:

Error: Could not find or load main class sun.security.tools.Jarsigner

CMD doesnt close or anything, just that error appears... :confused:
Any ideas?
Thanks,
~Vrawr

That's complicated. I wish I knew an answer but I know enough to make me dangerous.
 

KingRedHot

Senior Member
Oct 31, 2010
1,421
806
Baton Rouge
Thanks Raider, I had no idea about signing with private keys. Is this why certain Market Apps can't be decompiled?

Swyped from my Epic 4g Touch
 

AndroidGraphix

Senior Member
Apr 4, 2011
1,266
377
Paradise Valley, AZ
I'm guessing certain apk's need a specific com.htc.resources.apk and framework-res.apk to be decompiled. For example, I can't decompile apk's/skins for Sense 3.5 without first having those apk's that signar needs to decompile. I hope that makes sense. Nice works on your themes. Check out my latest thread on my modified skin. It's the first of it's kind and was just released 5 minutes ago. No joke.

http://xdaforums.com/showthread.php?t=1471529
 

KingRedHot

Senior Member
Oct 31, 2010
1,421
806
Baton Rouge
I'm guessing certain apk's need a specific com.htc.resources.apk and framework-res.apk to be decompiled. For example, I can't decompile apk's/skins for Sense 3.5 without first having those apk's that signar needs to decompile. I hope that makes sense. Nice works on your themes. Check out my latest thread on my modified skin. It's the first of it's kind and was just released 5 minutes ago. No joke.

http://xdaforums.com/showthread.php?t=1471529

Whoa man that is nice! I couldn't figure out how to get to the clock tabs, but I see you're hacking away at it lol

Awesome Work!

Swyped from my Epic 4g Touch
 

rawrv42

Member
Dec 30, 2011
40
3
Lowell
lol thanks for the heads up.
I didn't realize there were apps on the market that signed .apk on the phone. I did just that, signed with an app on the market on my phone. Worked like a charm. So many hours of my life wasted hahaha :eek:
Thanks again,
~Vrawr
 

AndroidGraphix

Senior Member
Apr 4, 2011
1,266
377
Paradise Valley, AZ
lol thanks for the heads up.
I didn't realize there were apps on the market that signed .apk on the phone. I did just that, signed with an app on the market on my phone. Worked like a charm. So many hours of my life wasted hahaha :eek:
Thanks again,
~Vrawr

Ya but doesn't it just test sign it by using that market application. I don't think it actually uses a private key to sign it. This thread is for signing with a private key not signing using a test key.


Sent from my ADR6425LVW using xda premium
 

12MaNy

Senior Member
Jun 7, 2010
2,427
881
Seattle
Signed and zipaligned my apk succesfully using this method but I keep getting this error when I try to upload to Google Play: "Google Play does not accept apks signed with certificates issued by Android team. Create a new certificate that is valid for at least 50 years.".

I'm lost....
 

SevereDeceit

Senior Member
Oct 13, 2010
593
155
St. Louis
Signed and zipaligned my apk succesfully using this method but I keep getting this error when I try to upload to Google Play: "Google Play does not accept apks signed with certificates issued by Android team. Create a new certificate that is valid for at least 50 years.".

I'm lost....

50 years? That's funny if you ask me. :D
 

Top Liked Posts

  • There are no posts matching your filters.
  • 17
    Noobs guide to signing an APK with a Private Key

    Credit:

    Tommytomatoe - For walking me through the setup/process/commands.


    What you'll need to sign an APK.

    SDK found here>> Java SDK
    *For most users the java_ee_sdk-6u3-jdk7-windows.exe will be the one selected.

    *After Install, restart your PC.

    Next, open your command prompt

    Type: cd C:\Program Files\Java\jre1.6.0_07\bin
    *It highly likely, the jre1.6.... will be different. If it's close, then select it. I prefer to type cd c:\pro(pressing tab will automatically complete/find the remaining part of the directory)

    If you're on Windows 7, the correct path is

    Code:
    c:\program files\Java\jdk1.7.0_01\bin

    Creating your Private Key

    Make sure you're in the directory stated above. We will now create a signed key. Below is an example of what we're going to do. I'll break it down in noob terms after.

    Code:
    keytool -genkey -v -keystore $KEYSTORE -alias $ALIAS -keyalg RSA -keysize 2048 -validity 10000

    skin.keystore meaning

    The part of the command that contains your information will be skin.keystore and 12215. The "skin" part of skin.keystore is your release key name. I named my skin because this key will be for all the Skins I upload to the market.

    [Q] Do I need to have .keystore after my key name?
    [A] Yes. It must look like: skin.keystore otherwise the command will not be complete.

    12215 meaning

    This is like a second password. Remember this, because it will be referenced when signing an APK. I used 12215. You can use johnsmith or anything else.

    keytool -genkey -v -keystore skin.keystore -alias 12215 -keyalg RSA -keysize 2048 -validity 10000


    Code:
    keytool -genkey -v -keystore SAMPLE.keystore -alias SAMPLE -keyalg RSA -keysize 2048 -validity 10000

    In the above my key is called "SAMPLE.keystore". Its alias (kind of like an additional password) is "SAMPLE". After you hit enter it will prompt for password. When you type it won't show up on screen (to protect your password)
    -Tommytomatoe

    Here is an example of the above:

    skinstore1.jpg


    Keep in mind, if you don't remember your alias you won't be able to use your key
    -Tommytomatoe

    **IMPORTANT

    After you press enter to create the key, it will prompt you for a password. The program mask your password so others won't see it. So when you type it will appear as if no password is being entered.

    Your key is stored in the directory you created it in. You won't need to find the file when signing an APK, because it's stored for you already. I'll go into detail of how to access your password in the next step.

    How to sign an APK with the Private Key you created.

    Anytime you sign an APK, you'll need to open command prompt then type:

    Code:
    cd c:\Program Files\Java\jdk1.6.0_26\bin
    *Keep in mind your jdk1.6.0... might be different than the above.

    The following is an example of what you'll copy and paste into command prompt.

    Code:
    jarsigner -verbose -keystore skin.keystore -signedjar DRAG-DROP-RENAME-APK-NAME DRAG-DROP alias

    In the above example, "DRAG-DROP-RENAME-APK-NAME" is telling you to drag your APK into the command prompt and to rename it. Example below.

    apkdraganddrop.jpg


    You can see below my command prompt after I dragged and dropped my apk into cmd. I also deleted "DRAG-DROP alias" from the command line to make it easier to see the changes I'm doing.

    dropapkone.jpg


    After you drag and drop, rename your apk to "New-NOVSKIN1.apk", shown below.

    renameapkdrag.jpg


    Below you'll see, after I renamed the apk, I dragged and dropped the same apk from above into the command directory again. This time, we're not going to rename it. Instead, after you drop it a second time into command prompt, we're going to type our alias at the end. Pictured below:

    dragdroprenamealias.jpg


    **NOTE

    The reason we drag and drop is to SAVE TIME. Tommytomatoe showed me this shortcut and it saves a ton of time from having to type everything out.

    After entering this command, and executing it, the apk will now be signed. Congrats!
    2
    in case anyone is struggling like i was with this... this command works for me perfectly... you have to place the apk you want signed in the bin folder of your jdk and copy over your .keystore to that same folder...

    Code:
    jarsigner -verbose -sigalg MD5withRSA -digestalg SHA1 -keystore $NAME.keystore $FILE.apk $ALIAS

    • NAME = your keystore name WITH ".keystore" on the end
    • FILE = the name of the apk you want to sign WITH ".apk" on the end
    • ALIAS = the alias you setup your keystore with

    i'm also putting this here b/c i set this stuff up several weeks ago on a different computer and when i went to sign my updated stuff, i forgot how lol... so now this is saved on the internet for all eternity!! muahahaha
    1
    Do you still have the example pictures? This tutorial would help me no end but I'm struggling to make sense of it without any examples!! (newbie, I know!)

    Sure bro. My old server went down so I'll need to reload them again. I'll get to it when I can. You can always pm me for help.

    Sent from my ADR6425LVW using xda premium