Getting Started in Android Development
Part 46 -
At some point you will either want to publish your app or test it on a real device. There are activities you need to undertake to prepare your app for publication.
Ultimately, you want to produce a signed Android Application Package (or APK file). In the process of generating the APK you need to do the following:
Versioning is a critical component of your application upgrade and maintenance strategy. Users need to have knowledge of the version number of the application. The android system will not allow an application with a lower version number to be installed over the same application with a higher version number. Market places also display the version umber to users.
Android application versioning comprises two elements. The most significant is the version number and this has to be an integer value. In Android terms, the version number is referred to as the version code. The second element is the version name. This is a string value that is defined and controlled by the author. It has no real meaning, but provides a user friendly way of representing the app version.
Prior to Android Studio, the version information was controlled manually in the Android Manifest. This method is still valid if you want to control things this way. An example of how it is controlled is shown below:
Within Android Studio the application version is controlled by Gradle. There are two ways to adjust the application version.
By selecting build.gradle (Module: app), the Gradle build information is shown in text format. In the screenshot below you can see the app versionCode and versionName. You can simply edit these values.
The second way is to choose:
This opens the window shown below, where the same information can be edited.
Signing your app
Android requires that all apps be digitally signed with a certificate before they can be installed. The Android system uses this certificate to identify the author of an app. The certificate does not need to be signed by a certificate authority and Android apps often use self-
To sign your app first select:
You will be presented with the first part of a wizard. You will need to specify the path and file name of a keystore. In the screenshot below the keystore is called keystore.jks.
Enter passwords and an alias you can remember. On clicking next, you may be asked for a keystore master password if the keystore already exists. You will then be presented with another dialog box where you specify the path of the application APK file.
You can also specify if it is a debug or release build. Click finish and the APK file will be generated. One the process is complete you will be prompted to show the file in explorer if are using Windows. You will then be ready to publish the app simply by uploading the resultant APK file to the market.
Download Download tutorial set 3