IC03 Native Android Application Design & Development af unit Publishing your first application



Download 45.5 Kb.
Date20.06.2017
Size45.5 Kb.

IC03_ Native Android Application Design & Development

AF Unit 4. Publishing your first application

4.1. Hello World app

In this unit you will create your first application, the 'Hello World' app and then you will learn to digitally sign it.

Start up Android Studio and click the first option from the Quick Start panel: 'Start a new Android Studio project'


Notice that you might not have any items in the 'Recent Projects' panel so far.

T
he 'New Project' dialog will appear. Keep the default application name and type your 'Company/Center Domain' then hit the 'Next' button.

In the next dialog window, select the 'Minimum SDK'. For now, API 10 will do.




Notice the 'Help me choose' link!




By choosing API Level 10 or Android version 2.3 also known as Gingerbread (all Android versions are named after sweet desserts) you would reach a potential 99.3% Android world market.

Generally speaking, you should stick to the lowest possible Android version; the one that has everything you need to develop your application.

TO KNOW MORE

Check this link to learn about the relative number of devices running a given version of the Android platform.







Android Dashboard




In the next dialog window, choose a 'Blank Activity'. Activities are Android components that hold widgets such as labels, text boxes, buttons and so on. Then hit the 'Next' button.


There are eleven initial activities to choose from. But for now, let's stick to the simplest one, the 'Blank Activity'.



TO KNOW MORE

There are mainly four components in an Android app:




  1. Activities are application components that provide a screen. (Users can interact with it in order to do something).

  2. Services (an application component that can perform long-running operations in the background and does not provide a user interface). As the service has no user interface, it is not bound to the lifecycle of an activity, although they run in the same process as the main thread or UI thread. Playing music or video are both examples of services.

  3. Content Providers (an application component that manages access to a structured set of data). The Contacts application itself provides a content provider for other applications to access our contact’s data.

  4. BroadcastReceivers (an application component that monitors device state changes). For example, you can register a receiver to have your application notified if an incoming call or battery low event arises, to take some actions.

So, select the ‘Blank activity’ and click the Next button. Eventually, the following dialog window will pop up.

Accept the default values for 'Activity Name', 'Layout Name', 'Title' and 'Menu Resource Name'. Notice that only the ‘Title’ text box can contain spaces.

Finally hit the 'Finish' button to end the whole process.

After a few seconds, a ready-to-run app made up of one Activity with its corresponding layout xml file is presented. Initially, the xml file will be displayed in the Design view but you can click the 'Text' tab to see the XML code.




As you can see the so called 'BlankActivity' is not actually blank, it has an 'onCreate' method that loads the 'activity_main.xml' file, which in turn has a label or 'TextView' that displays a “Hello World” message. Besides, a basic menu is also provided with a single item.

Now press the play button (a green triangle icon, the 15th from the left) and choose the already defined AVD to upload and display your app.




Notice that the first time you run your application, the AVD will take quite a long time to load into memory. However, successive executions won't take that much.

For this reason, you should take the time to install the Intel Hardware Accelerator mentioned in a previous unit.

But if you really want to speed up the whole process, a real device will dramatically plunge the upload time and execution, hence decreasing the overall development time. Furthermore, be aware that some crucial features just won't work in a virtual device, such as Bluetooth, NFC or GPS.



And this is how it looks like in my Samsung Galaxy S 5.

The possibilities with a real smartphone are endless ranging from GPS tracking to Bluetooth data transmission.

Just remember to choose the minimum Android version accordingly to your model. As for the Samsung Galaxy S 5, any version up to Android 5 Lollipop would work.

Optionally, you can check how your brand new app looks like in different screen sizes.


Congrats!!! You have completed your first app.





Hello World Application step-by-step guide





Hello World Application step-by-step video

4.2. Signing your application

Now that you have completed your first app, it is time to digitally sign it in order to upload it to Google Play.

First, you need to create your own digital certificate with a key and certification management tool like 'keytool' which comes with the JDK.

You do not need Android Studio to sign your app.

You can sign your app from the command line using standard tools from the Android SDK and the JDK.

To sign an app in release mode from the command line:



  1. Generate a private key using keytool. For example:

keytool -genkey -v -keystore demo.keystore -alias pep -keyalg RSA -keysize 2048 -validity 10000
This example prompts you for passwords for the keystore and for the key, and also asks to provide the Distinguished Name fields for your key. It then generates the keystore as a file called my-release-key.keystore. The keystore contains a single key, valid for 10000 days. The alias is a name that you will use later when signing your app.

  1. Compile your app in release mode (access to Project Structure, app node, Build Types tab then choose release mode) to obtain an unsigned APK.



  1. Sign your app with your private key using jarsigner (also provided by JDK):

jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.keystore my_application.apk alias_name

This example prompts you for passwords for the keystore and for the key. It then modifies the APK in-place to sign it.




  1. Verify that your APK is signed. For example:



jarsigner -verify -verbose -certs my_application.apk


  1. Align the final APK package using zipalign.


zipalign -v 4 your_project_name-unaligned.apk your_project_name.apk
zipalign ensures that all uncompressed data starts with a particular byte alignment relative to the start of the file, which reduces the amount of RAM consumed by an app.

As you can see there are quite a few steps. However, Android Studio, provides an easy way to do it with just one click.

In any case, you will first need the private key store you created before.

Now open up the 'Project Structure' dialog window and type the following information. Obviously, you will have to provide your own values for each text box.








CHECK IT OUT

The keytool command line tool has lots of commands and options


-certreq Generates a certificate request

-changealias Changes an entry's alias

-delete Deletes an entry

-exportcert Exports certificate

-genkeypair Generates a key pair

-genseckey Generates a secret key

-gencert Generates certificate from a certificate request

-importcert Imports a certificate or a certificate chain

-importpass Imports a password

-importkeystore Imports one or all entries from another keystore

-keypasswd Changes the key password of an entry

-list Lists entries in a keystore

-printcert Prints the content of a certificate

-printcertreq Prints the content of a certificate request

-printcrl Prints the content of a CRL file

-storepasswd Changes the store password of a keystore



Follow this link to review the whole process from a similar point of view.



Signing an Android application

And download the keytool guide.



Keytool guide


4.3. Uploading your application to Google Play

Uploading an application to Google Play is very easy. Just create a Google account if you do not have one and then create a Google console account at:



https://play.google.com/apps/publish/

Then sign in and click the ‘Add new application’ blue button. Notice that I have already published a couple of apps back in 2013.




As you can see, every row represents a published Android application ready to download. Each one consisting of an icon, name and version number, price, current and total installs, average rating (being 5 stars the top rating) and total rates, crashes and ANR’s (Application Not Responding) error messages, last update and status.

After hitting the ‘Add new application’ blue button, the ‘ADD NEW APPLICATION’ dialog window appears. Just write a title for your application and click the ‘Upload APK’ button then choose your APK file under the build directory in your application project’s folder.

APK stands for Android Application Package and is the package file format used to distribute and install application software and middleware onto Google’s Android operating system among others operating systems.

You must also provide a short description, full description and two icons prior to publishing your application, as well as screen captures and optionally a promotional video.

Although there are many app markets for distribution Google play is arguably the largest and most visited store in the world for Android apps.

Applications not only need to be signed with a cryptographic key that expires after October 22, 2033, the maximum size for an APK published on Google Play is 50 MB.

TO KNOW MORE

Check this link to learn more about how to publish an Android APK.






How to publish an APK




Optionally, you can charge for each and every application download on a country-by-country basis and select the countries your application is available for download.

Eventually, you might need to setup services such as Google Cloud Messaging (GCM), in-app billing, Google play game services or app indexing from Google Search.

These are advanced features not covered in this unit.

Finally, you are more than welcome to visit my Google Play site and download any app you want. Comments are also welcome.





IC03_Native Android Application Design and Development / U
nit 4



Download 45.5 Kb.

Share with your friends:




The database is protected by copyright ©ininet.org 2020
send message

    Main page