Go Public with Your Android Application: Signing and Deployment

Go Public with Your Android Application: Signing and Deployment

o far, you’ve been learning about the interesting things you can do with Android. However, if you want your application to see the light of day and run on other users’ devices, you need a way to distribute your application and deploy them onto your target devices. This article will show you how to prepare your Android applications for deployment and get them onto your customers’ devices.

Creating the Sample Application
A simple Android application will illustrate deployment on an Android device. So, using Eclipse, create a new Android project.

Versioning
Beginning with version 1.0 of the Android SDK, the AndroidManifesl.xml file of every Android applications include the android:versionCode and android:versionName attributes:

                                                                                

The android:versionCode attribute represents the version number of your application. For every revision you make to the application, increment this value by 1 so that you can programmatically differentiate it from its previous version. This value is never used by the Android system, but it’s useful as a way to obtain the version number of an application.

The android:versionName attribute contains versioning information that is visible to the users. It should contain values in the following format: ...

If you are planning to publish your application on the Android Market, the AndroidManifest.xml file must have the following attributes:

  • android:versionCode
  • android:versionName
  • android:name
  • android:name

In addition, if your application needs a minimum version of the SDK, you can specify it in the AndroidManifest.xml file using the element, like this:

                                                                                    

As the current version of the SDK is 1.0, there is no necessity for you to specify the minimum version of the SDK required.

To programmatically retrieve the value of the android:versionCode attribute, use the PackageManager class’ getPackageInfo() method. To see how this can be done, give an id to the view in main.xml, like this:

In MyKillerApp.java, add the following code to retrieve the version code of the application:

Figure 1. Run the App: Displaying the application’s versionCode.

    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);                PackageManager pm = getPackageManager();        try {            //---get the package info---            PackageInfo pi =                  pm.getPackageInfo("net.learn2develop.MyKillerApp", 0);            //---display the versioncode---            TextView tv = (TextView) findViewById(R.id.textview);                        tv.setText("VersionCode: " +Integer.toString(pi.versionCode));        } catch (NameNotFoundException e) {            // TODO Auto-generated catch block            e.printStackTrace();        }    }

When you run the application, it will display the value of the android:versionCode attribute (see Figure 1).

All Android Applications Must Be Digitally Signed
All Android applications must be signed before they are allowed to be deployed onto a device (or emulator). Unlike other mobile platforms, you need not purchase digital certificates from a certificate authority (CA). Instead, you can generate your own personal certificate and use it to sign your Android applications.

Figure 2. Signing Your App: All Android applications developed in Eclipse are signed using a default debug keystore.

When you use Eclipse to develop your Android application and then press F11 to deploy it to an emulator, Eclipse automatically signs it for you. To verify this, first go to Windows?Preferences in Eclipse, then expand the Android item, and select Build (see Figure 3). Eclipse uses a default debug keystore (debug.keystore) to sign your application.

Signing an Application Manually
If you are publishing an Android application, you must sign it with your own certificate. Applications signed with the debug certificates cannot be published. To sign your application manually, you need to perform the following steps:

  • Compile your application in release signing mode. To do so in Eclipse, right-click on the package name and select Android Tools?Export Unsigned Application Package… (see Figure 3).
  • You will then be asked to select a directory for exporting the application (Android package has the .apk extension). For convenience, I have exported the Android package to C:Program FilesJavajdk1.6.0_10in (see Figure 4). You will understand why this is so shortly. (Note that I am using JDK 1.6.10; you might have some other versions on your computer and hence the folder name may vary a little.)

  • Figure 3. Using Eclipse: Exporting an Android application in release signing model.
     
    Figure 4. The Directory Path: Exporting an .apk file.

  • If you wish to sign your application using the debug keystore, copy the Debug.keystore file from C:Documents and SettingsLocal SettingsApplication DataAndroid to C:Program FilesJavajdk1.6.0_10in.
  • Use the jarsigner.exe tool (comes with your JDK) located in C:Program FilesJavajdk1.6.0_10in to sign the .apk file with the specified keystore:
    jarsigner -verbose -keystore debug.keystore MyKillerApp.apk androiddebugkey
  • When prompted for the password for the keystore, use the default password: android.

The jarsigner.exe tool takes in the following options:

  • -keystore: This is the name of the keystore containing your private key.
  • -verbose: This enables verbose output.

The alias for the debug.keystore file is androiddebugkey. Figure 5 shows the application signed with the debug.keystore default keystore.


Figure 5. Signed with the Keystore: Signing the .apk file with debug.keystore.
 
Figure 6. Verified and Certified: Verifying that the application was signed correctly.

To verify that the application is signed correctly, you can use the –verify option with jarsigner.exe. You can also use the –certs option to view the details of the certificate used to sign the application (see Figure 6).

Generating Your Own Key
As mentioned, if you wish to publish your application to other users, you need to sign your application using your own personal certificate. You can generate your own certificate by using the keytool.exe tool (this also comes with your JDK).

To generate your own certificate, issue the following command:

keytool –genkey –v –keystore learn2develop.keystore –alias learn2develop –keyalg RSA –validity 10000

The above command generates a certificate named learn2develop.keystore with the key alias learn2develop, generated using the RSA algorithm, and with a validity of 10,000 days (this is the minimum recommended). You will be prompted for some information (see Figure 7). In particular, you need to supply a password for the keystore and a password for the private key. If you are publishing your application for the Android Market, your keystore must have a validity period ending after 22 October 2033.

Secure and protect these two passwords so that only people who are authorized to sign your applications know about them.


Figure 7. Prompting: While generating your own keystore, you will be prompted for information.
 
Figure 8. The learn2develop.keystore File: Signing your application with the new keystore file.

Once the learn2develop.keystore file is generated, you can now sign your application with it (see Figure 8).

Deploying .apk Files
Once your Android application is signed, you can deploy them to emulators and devices using the adb.exe tool (located in the tools folder of the Android SDK).

Figure 9. MyKillerApp.apk: Installing an Android .apk file using adb.

For illustration, copy the MyKillerApp.apk created (and signed) in the previous section to the android-sdk-windows-1.0_r1 ools folder. To install the application to an emulator (assuming the emulator is currently up and running), issue the following command:

adb install MyKillerApp.apk

Figure 9 shows the successful installation of the application.

To remove an installed application using the adb tool, you can use the shell option to remove an application from its installed folder, like this:

adb shell rm /data/app/net.learn2develop.MyKillerApp.apk

Another way of deploying an application is to use the DDMS tool in Eclipse (see Figure 10). With an emulator (or device) selected, use the File Explorer in DDMS to go to the /data/app folder and use the “Push a file onto the device” button to copy the .apk file into the device.


Figure 10. Using the DDMS Tool in Eclipse: Copying an .apk file into the emulator using the DDMS tool.
 
Figure 11. It Works! Locating the newly installed Android application.

Once this is done, the application will automatically appear on the device (see Figure 11).

Easy and Essential
In this article, you’ve been walked through the process of signing your Android applications and how to generate your own keystore by using the jarsigner.exe and keytool.exe tools. Signing your application is absolutely essential if you want your application to run beyond the emulator. This is particularly true if you wish to publish your application on the Android Market.

devx-admin

devx-admin

Share the Post:
AI Girlfriend Craze

AI Girlfriend Craze Threatens Relationships

The surge in virtual AI girlfriends’ popularity is playing a role in the escalating issue of loneliness among young males, and this could have serious

AIOps Innovations

Senser is Changing AIOps

Senser, an AIOps platform based in Tel Aviv, has introduced its groundbreaking AI-powered observability solution to support developers and operations teams in promptly pinpointing the

Malyasian Networks

Malaysia’s Dual 5G Network Growth

On Wednesday, Malaysia’s Prime Minister Anwar Ibrahim announced the country’s plan to implement a dual 5G network strategy. This move is designed to achieve a

Advanced Drones Race

Pentagon’s Bold Race for Advanced Drones

The Pentagon has recently unveiled its ambitious strategy to acquire thousands of sophisticated drones within the next two years. This decision comes in response to

Important Updates

You Need to See the New Microsoft Updates

Microsoft has recently announced a series of new features and updates across their applications, including Outlook, Microsoft Teams, and SharePoint. These new developments are centered

AI Girlfriend Craze

AI Girlfriend Craze Threatens Relationships

The surge in virtual AI girlfriends’ popularity is playing a role in the escalating issue of loneliness among young males, and this could have serious repercussions for America’s future. A

AIOps Innovations

Senser is Changing AIOps

Senser, an AIOps platform based in Tel Aviv, has introduced its groundbreaking AI-powered observability solution to support developers and operations teams in promptly pinpointing the root causes of service disruptions

Bebop Charging Stations

Check Out The New Bebob Battery Charging Stations

Bebob has introduced new 4- and 8-channel battery charging stations primarily aimed at rental companies, providing a convenient solution for clients with a large quantity of batteries. These wall-mountable and

Malyasian Networks

Malaysia’s Dual 5G Network Growth

On Wednesday, Malaysia’s Prime Minister Anwar Ibrahim announced the country’s plan to implement a dual 5G network strategy. This move is designed to achieve a more equitable incorporation of both

Advanced Drones Race

Pentagon’s Bold Race for Advanced Drones

The Pentagon has recently unveiled its ambitious strategy to acquire thousands of sophisticated drones within the next two years. This decision comes in response to Russia’s rapid utilization of airborne

Important Updates

You Need to See the New Microsoft Updates

Microsoft has recently announced a series of new features and updates across their applications, including Outlook, Microsoft Teams, and SharePoint. These new developments are centered around improving user experience, streamlining

Price Wars

Inside Hyundai and Kia’s Price Wars

South Korean automakers Hyundai and Kia are cutting the prices on a number of their electric vehicles (EVs) in response to growing price competition within the South Korean market. Many

Solar Frenzy Surprises

Solar Subsidy in Germany Causes Frenzy

In a shocking turn of events, the German national KfW bank was forced to discontinue its home solar power subsidy program for charging electric vehicles (EVs) after just one day,

Electric Spare

Electric Cars Ditch Spare Tires for Efficiency

Ira Newlander from West Los Angeles is thinking about trading in his old Ford Explorer for a contemporary hybrid or electric vehicle. However, he has observed that the majority of

Solar Geoengineering Impacts

Unraveling Solar Geoengineering’s Hidden Impacts

As we continue to face the repercussions of climate change, scientists and experts seek innovative ways to mitigate its impacts. Solar geoengineering (SG), a technique involving the distribution of aerosols

Razer Discount

Unbelievable Razer Blade 17 Discount

On September 24, 2023, it was reported that Razer, a popular brand in the premium gaming laptop industry, is offering an exceptional deal on their Razer Blade 17 model. Typically

Innovation Ignition

New Fintech Innovation Ignites Change

The fintech sector continues to attract substantial interest, as demonstrated by a dedicated fintech stage at a recent event featuring panel discussions and informal conversations with industry professionals. The gathering,

Import Easing

Easing Import Rules for Big Tech

India has chosen to ease its proposed restrictions on imports of laptops, tablets, and other IT hardware, allowing manufacturers like Apple Inc., HP Inc., and Dell Technologies Inc. more time

Semiconductor Stock Plummet

Dramatic Downturn in Semiconductor Stocks Looms

Recent events show that the S&P Semiconductors Select Industry Index seems to be experiencing a downturn, which could result in a decline in semiconductor stocks. Known as a key indicator

Anthropic Investment

Amazon’s Bold Anthropic Investment

On Monday, Amazon announced its plan to invest up to $4 billion in the AI firm Anthropic, acquiring a minority stake in the process. This decision demonstrates Amazon’s commitment to

AI Experts Get Hired

Tech Industry Rehiring Wave: AI Experts Wanted

A few months ago, Big Tech companies were downsizing their workforce, but currently, many are considering rehiring some of these employees, especially in popular fields such as artificial intelligence. The

Lagos Migration

Middle-Class Migration: Undermining Democracy?

As the middle class in Lagos, Nigeria, increasingly migrates to private communities, a PhD scholar from a leading technology institute has been investigating the impact of this development on democratic

AI Software Development

ChatGPT is Now Making Video Games

Pietro Schirano’s foray into using ChatGPT, an AI tool for programming, has opened up new vistas in game and software development. As design lead at business finance firm Brex, Schirano

Llama Codebot

Developers! Here’s Your Chatbot

Meta Platforms has recently unveiled Code Llama, a free chatbot designed to aid developers in crafting coding scripts. This large language model (LLM), developed using Meta’s Llama 2 model, serves

Tech Layoffs

Unraveling the Tech Sector’s Historic Job Losses

Throughout 2023, the tech sector has experienced a record-breaking number of job losses, impacting tens of thousands of workers across various companies, including well-established corporations and emerging startups in areas

Chinese 5G Limitation

Germany Considers Limiting Chinese 5G Tech

A recent report has put forth the possibility that Germany’s Federal Ministry of the Interior and Community may consider limiting the use of Chinese 5G technology by local network providers

Modern Warfare

The Barak Tank is Transforming Modern Warfare

The Barak tank is a groundbreaking addition to the Israeli Defense Forces’ arsenal, significantly enhancing their combat capabilities. This AI-powered military vehicle is expected to transform the way modern warfare

AI Cheating Growth

AI Plagiarism Challenges Shake Academic Integrity

As generative AI technologies like ChatGPT become increasingly prevalent among students and raise concerns about widespread cheating, prominent universities have halted their use of AI detection software, such as Turnitin’s