Android App Development For Dummies
Book image
Explore Book Buy On Amazon

Publishable APK files differ from other APK files. You need to make sure your Android app has a publishable APK file if you hope to publish your app in the Google Play Store. You’ll be surprised to find out that creating a publishable APK file isn’t very complicated. Just follow these instructions:

  1. Make sure you have prepared your code for the Google Play Store.

  2. In Android Studio’s main menu, choose Build → Generate Signed APK.

    The Generate Signed APK dialog box appears. This dialog box has a drop-down list in which you select one of your project’s modules.

    The first Generate Signed APK dialog box.
    The first Generate Signed APK dialog box.
  3. Click Next.

    As a result, another Generate Signed APK dialog box appears. This box contains a Key Store Path field.

    Android Studio asks for a Key Store Path.
    Android Studio asks for a Key Store Path.

    In what follows, it’s assumed that you haven’t yet created a key store. (If you’ve created one, you’ll know that you did.)

  4. Click the Create New button.

    As a result, a New Key Store dialog box opens.

  5. Choose a name and a location for your key store. Put the full path name (the location and filename) of the new key store in the dialog box’s Key Store Path field.

    See the first field below. A key store file was created and named android.jks. The new file was put in a directory named /Users/barryburd/keystores. (In the filename android.jks, the extension .jks stands for Java key store.) As you publish more apps, you’ll probably use this key store to sign other projects’ APK files.

    The New Key Store dialog box.
    The New Key Store dialog box.

    Signing all your Android projects with the same key is a very good idea. Android treats the key as a kind of fingerprint, and two apps with the same fingerprint can be trusted to communicate with one another. When two apps have the same key, you can easily get these apps to help one another out.

    Android Studio’s New Key Store dialog box won’t create a directory for you. If you type /Users/myUserName/keystores/ something .jks in the Key Store Path field, you must have a /Users/myUserName/keystores directory before you click OK.

    At this point, it helps to understand the difference between a key store file and a single key. A key is what you use to digitally sign your Android app. A key store file is a place to store one or more keys. That’s why you supply two passwords — one for the new key store file, and another for the key that you’ll be putting in the key store file.

  6. Enter passwords in the Password and Confirm fields.

    Do yourself a favor and make ‘em strong passwords.

    Please remember to remember the passwords that you create when you fill in the Password and Confirm fields. You’ll need to enter these passwords when you use this key to sign another app.

    In a key store file, each key has a name (an alias, that is).

  7. Type a name in the Alias field.

    The alias can be any string of characters, but you might want to decide against being creative when you make up an alias. Avoid blank spaces and punctuation. If you ever create a second key with a second alias, make sure that the second alias’s spelling (and not only its capitalization) is different from the first alias’s spelling.

  8. Accept the default validity period (25 years).

    If you create a key on New Year’s Day in 2016, the key will expire on New Year’s Day in 2041. Happy New Year, everybody! According to the Play Store’s rules, your key must not expire until sometime after October 22, 2033, so 25 years from 2016 is okay.

  9. In the Certificate section, fill in at least one of the six fields.

    The items First and Last Name, Organizational Unit, and so on are part of the X.500 Distinguished Name standard. The probability of two people having the same name and working in the same unit of the same organization in the same locality is close to zero.

    When you finish, your dialog box resembles the image above.

  10. Click OK.

    As a result, the Generate Signed APK dialog box reappears. This time, many of the box’s fields are filled in for you.

  11. Click Next.

    When you do, one last Generate Signed APK dialog box appears.

    On your way to an APK.
    On your way to an APK.

    In this final Generate Signed APK box, take note of the APK Destination Folder. Also, be sure to select Release in the Build Type drop-down list.

    Don’t delay. Make an APK!
    Don’t delay. Make an APK!

    And finally …

  12. Click Finish.

    Android Studio offers to open the folder containing your shiny, new APK file. That’s great! Open the folder, and stare proudly at your work.

    If Android Studio opens a folder, and you don’t see an APK file in the folder, your operating system might be hiding things such as the letters apk at the ends of filenames.

    Very nice!
    Very nice!

Congratulations! You’ve created a distributable APK file and a reusable key store for future updates.

To make sure your APK file has been signed type JAVA_HOME/bin/jarsigner -verify -verbose -certs APKfileName .apk in Android Studio’s Terminal window. If the output includes the words jar verified, and it doesn’t include CN=android debug, then all is well.

About This Article

This article can be found in the category: