FORUMS
Remove All Ads from XDA

Noobs guide to signing an APK with a Private Key

1,267 posts
Thanks Meter: 378
 
By AndroidGraphix, Senior Member on 23rd August 2011, 07:10 PM
Post Reply Email Thread
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
Quote:

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:



Quote:

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.



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.



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



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:



**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!
The Following 17 Users Say Thank You to AndroidGraphix For This Useful Post: [ View ] Gift AndroidGraphix Ad-Free
11th January 2012, 04:54 PM |#2  
Junior Member
Thanks Meter: 0
 
More
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!)
11th January 2012, 07:24 PM |#3  
AndroidGraphix's Avatar
OP Senior Member
Flag Paradise Valley, AZ
Thanks Meter: 378
 
Donate to Me
More
Quote:
Originally Posted by ffdiablos

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
The Following User Says Thank You to AndroidGraphix For This Useful Post: [ View ] Gift AndroidGraphix Ad-Free
11th January 2012, 09:41 PM |#4  
Junior Member
Thanks Meter: 0
 
More
That's great news, thanks for your help. I'm starting to find there are some very helpful people on this site!
5th February 2012, 04:57 PM |#5  
rawrv42's Avatar
Member
Flag Lowell
Thanks Meter: 3
 
More
Question
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
5th February 2012, 09:03 PM |#6  
AndroidGraphix's Avatar
OP Senior Member
Flag Paradise Valley, AZ
Thanks Meter: 378
 
Donate to Me
More
Quote:
Originally Posted by rawrv42

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
7th February 2012, 12:31 AM |#7  
rawrv42's Avatar
Member
Flag Lowell
Thanks Meter: 3
 
More
Quote:
Originally Posted by raider3bravo

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
15th February 2012, 12:30 AM |#8  
rawrv42's Avatar
Member
Flag Lowell
Thanks Meter: 3
 
More
Question
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...
Any ideas?
Thanks,
~Vrawr
15th February 2012, 01:01 AM |#9  
AndroidGraphix's Avatar
OP Senior Member
Flag Paradise Valley, AZ
Thanks Meter: 378
 
Donate to Me
More
Quote:
Originally Posted by rawrv42

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...
Any ideas?
Thanks,
~Vrawr

That's complicated. I wish I knew an answer but I know enough to make me dangerous.
15th February 2012, 01:10 AM |#10  
KingRedHot's Avatar
Senior Member
Flag Baton Rouge
Thanks Meter: 808
 
Donate to Me
More
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
15th February 2012, 01:41 AM |#11  
AndroidGraphix's Avatar
OP Senior Member
Flag Paradise Valley, AZ
Thanks Meter: 378
 
Donate to Me
More
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://forum.xda-developers.com/show....php?t=1471529
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes