Home > android app tutorial, development device > Compiling and running your first Android application in Windows 7: Part 3: Modify application and deploy

Compiling and running your first Android application in Windows 7: Part 3: Modify application and deploy


In Part 2, we advanced as far as compiling the Simple Loan Application without errors. Up to that point, we had not yet deployed the application to our device.

(update 18 June 2013) The Simple Loan application developer has decided to remove most menu buttons and this includes the ‘Donate’ option used in this tutorial. If you wish to continue this part of the tutorial, you need to work with the original version of source code which is available from the location below, otherwise you may skip to this step.

Location of original Simple Loan Calculator:

http://ustop5.com/simple.loan.calculator.source.build42.zip

For this final task we have three simple goals:

1. Disable the Paypal donation button present in two menu layouts.

buttons_to_remove
2. Change the application’s version number to make it distinct from the original application.
3. Recompile and deploy to our Android device

Each screen or layout in an Android application  is designed in code as a separate XML file per screen.

In case of the Simple Loan Application, the following layouts exist:

main: contains the base of the application and all the different variable fields used to calculate loans.
schedule: contains the detail of payments once they have  been calculated
compare: similar to the payment schedule, but it allows comparison amongs different payment options
help: user help screen

You can look for layouts under folder <project location>/res/layout
Although menus are displayed in specific screens, they are stored in separate layout files themselves.

Menus are xml files under folder <project location>/menu

Instructions

  • Open your eclipse project defined in the previous step and at the Package Explorer window navigate to:

Project: ee.smkv.calcl.loan.MainActivity
Subfolder /res/menu

  • Double click on mainmenu.xml. This activates an Android Menu layout definition.

eclipse_select_layout_android

Each menu option is represented by an item (‘I’ icon).

  • Click once on the donateMenu item and at the right side, scroll down to the ‘Visible’ attribute. Set the attribute to ‘False’

eclipse_select_layout_android

  • Repeat the task with the other menu layout called ScheduleMenu.xml

That’s all there is to disabling the PayPal donation menu item.  If you click on the ‘Source’ view at the bottom of the Menu Layout window, you can see that the code itself changed as follows:
Excerpts from file schedulemenu.xml
From:
<item android:id="@+id/donateMenu" android:title="@string/donate"  android:icon="@drawable/paypal" />

To this:
<item android:id="@+id/donateMenu" android:title="@string/donate"  android:icon="@drawable/paypal" android:visible="false"/>


The final step before recompiling the application is to change the version number in the application:

  • From the Package Explorer view, click on the ‘AndroidManifest.xml’ file. The manifest is where deployment characteristics are defined.

The Version Code is a user-defined numeric sequence.  The Version Name is a version number for the package in the form <major version>.<minor version>.<minor version variant>

  • Change Version Code and Version Name fields as follows

Add 100 to the ‘Version Code’ number
Set the ‘Version Name’ to our own, for example: 4.0.0

eclipse_android_manifest_version_code_version_name

 Although the action of changing version code and name is optional, we are doing it to differentiate our application from the one found at the Google Play market.

  • Save your changes to the Android Manifest by selecting File -> Save.
  • Plug in your Android device

You can double check that the device is ready to accept applications by briefly switching to the DDMS perpective

  • Select Window-> Open Perspective -> DDMS

This will show your device as a row in the Devices windoweclipse_ddms_device_plugged_in

If your device does not appear, make sure that your device configuration is correct.  Here is an example of how to configure.

The final task is to deploy the modified application.

Clean the current application.

  • Select Project -> Clean

This will remove any previous compilations.
Compile in full.

  • Select Project -> Build all

Before deploying, select the Android console to monitor what will happen during deployment.

  • Click on the Console log in the lower left window and then select ’1. Android’

eclipse_android_console_options_android_ddms

Deploy

  • Select ‘Project -> Run’

A sequence like the following should be displayed in the Console screen:

[2012-12-18 12:57:39 - ee.smkv.calc.loan.MainActivity] ------------------------------
[2012-12-18 12:57:39 - ee.smkv.calc.loan.MainActivity] Android Launch!
[2012-12-18 12:57:39 - ee.smkv.calc.loan.MainActivity] adb is running normally.
[2012-12-18 12:57:39 - ee.smkv.calc.loan.MainActivity] Performing ee.smkv.calc.loan.MainActivity activity launch
[2012-12-18 12:57:39 - ee.smkv.calc.loan.MainActivity] Automatic Target Mode: using device '0123456789ABCDEF'
[2012-12-18 12:57:40 - ee.smkv.calc.loan.MainActivity] Uploading ee.smkv.calc.loan.MainActivity.apk onto device '0123456789ABCDEF'
[2012-12-18 12:57:40 - ee.smkv.calc.loan.MainActivity] Installing ee.smkv.calc.loan.MainActivity.apk...
[2012-12-18 12:57:43 - ee.smkv.calc.loan.MainActivity] Success!
[2012-12-18 12:57:44 - ee.smkv.calc.loan.MainActivity] Starting activity ee.smkv.calc.loan.MainActivity on device 0123456789ABCDEF
[2012-12-18 12:57:45 - ee.smkv.calc.loan.MainActivity] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=ee.smkv.calc.loan/.MainActivity }

At the same time, the modified Simple Loan Application should open on your device immediately.
The log shows that

  • The .apk file, the package containing the modified application was copied to the device.
  • Application installation was successful
  • The MainActivity of the application was started successfully.

This is how the modified menus in the Simple Loan Calculator should look like after deployment

android_menu_items_icons.

This concludes this tutorial, be sure to subscribe to our RSS feed for further tutorials.

 

  1. No comments yet.
  1. No trackbacks yet.

*
= 3 + 5