Android App Development Keystore for Beginners

Getting into some mobile app development for Android and I was unprepared for the keystore file that is required to be included in the apk file. Using PhoneGap Build to compile my app the interface requires a keystore file uploaded.
Screen Shot 2013-02-05 at 1.55.07 PM
After some digging on google it seems that the most common way to create a keystore file is by using some Java IDE like Eclipse, but the whole reason I was using build phonegap was because I didn’t want to fool with one of those. I finally pieced together what I needed with a few posts and wanted to put it all together to help at least myself in the future.
phonegap keystore upload alias
Luckily with a mac apparently you can do this with terminal! Following a couple tutorials, I managed to create a proper file, and going through a few steps to set the expiration or validity and the alias.

To create a keystore on mac OSX, first, open terminal. We’ll type keytool and then there are some commands to type and our keystore file will be created. -genkey (generates the key), -v turns on verbose mode so full details will be output, -keystore tells it what to name the actual file (it actually saves to the root directory, I’m sure there’s a way to specify location somewhere) and you type the filename (including the .keystore file extension). Once you enter this in you are prompted to fill out your name and company name and info like city, state and country. Then it verifies everything and you must type ‘yes’. Then it will prompt twice for a password, remember this it is how you will update/rebuild your app.

keytool -genkey -v -keystore file_name.keystore

This got me going but I had to do some back and forth to know some other requirements specifically for android marketplace and working with PhoneGap. PhoneGap Build was asking for the alias when I uploaded the keystore file to build my project, but I hadn’t set one. I had no idea what it would be and after trying my name and company and even filename I had to do some more digging. We can in fact set the alias name when I create the key with the -alias command. It doesn’t matter what this is, you just have to remember it. I think of it like the username to my previously entered password. The default is set to mykey, so you don’t really need to set it. This got me through the Build process with PhoneGap, and then I set up my app on the android marketplace (after paying the $25 license fee). Once I uploaded my first apk file I was getting errors regarding the keystore again. The marketplace was telling me that the validity was not large enough. The validity (or expiration) of the key by default is set to 90 days, but the marketplace requires at least 10000 days… quite a difference, no? So to set validity we add the -validity command followed by the value of 10000. Once i did this round I re-uploaded the keystore to PhoneGap, rebuilt the app and resubmitted to the Android Marketplace and it was accepted! Wow.

keytool -genkey -alias alias_name -validity 10000 -v -keystore file_name.keystore

terminal creating a keystore file for android apk

I hope that helped someone. I’m surprised that the PhoneGap doesn’t aleviate some of the pain in this process. Since the whole point of using Build PhoneGap is so that I don’t have to set up an IDE or get complicated. A simple online keystore gen process would go a long way, and better yet if they automated it somehow!

Did I miss any steps? Are there better ways to do this? (I sure hope so) Share a comment.

Also, check out the app I made from web technologies html, css and javascript with the help of PhoneGap. It’s a quiz that tests and teaches users facial recognition of leaders at church. It’s called LDSQuiz and shows images of modern day prophets and apostles and asks you to identify them by name.

Reference links that helped me:

9 thoughts on “Android App Development Keystore for Beginners

  1. I am new in android and have certain question about KeyStore. Is KeyStore used in user authentication ? I mean can we store user name, password in KeyStore ? If yes how.
    What the real purpose of KeyStore is ? What the difference between Shared Preference and KeyStore ?

    Thanks in advance !!

    1. The keystore is used for creating valid apps that are associated with the author. It is not used at all by the end user, only by the marketplace to verify that you are indeed the approved author of the app.

  2. The key to android development is creativity and new ideas. There are many developers who have been trying their hands on this. Android App Development has a lot of scope but many people choose to develop cross platform instead of native apps because they don’t want to spend individually on every app.

  3. Hi Evan, great post you wrote here, it certainse shead some light on a big issue when workong on apps. where exactly will “Terminal” hide this info, i mean i do need to find it for uploading to PhoneGap, what should be written in the “Title” and “Alias” fields? And yes, why do Adobe not simplify this process, it will without doubt make some give up doing theese quite complicated but crutial steps. Hey thanks again i really hope you can give me an answer to this 🙂

    1. @Bjarne, the title and alias are totally up to you. There are no requirements here. I used the title of my app and the alias was a shortened version of the app. They are as flexible as filenames for example. It doesn’t matter what your file is named, but it has to be named something, and you’ll want to remember what you name it so you can find it later.

  4. hi, me again… i’m a little stuck. so i followed the instructions above (exactly), so i go to the phonegap build and upload the file… i then go back into DW. the build for android is queued. i think it is because it is asking for a KSPassword. i have no idea what that is – do you? thanks in advance!

  5. Actually the same can be done in Windows. Keytool is actually a java program provided with the Java Runtime Environment. I believe it’s already installed on Mac Computers, but it’s not on Windows.

    After someone installs Java on Windows they can do the same thing in a terminal by going to the Java bin folder or adding it to their path file.

Comments are closed.