Understanding Android Projects


Welcome to Part 5 of this review of the Pluralsight course Android for .NET Developers: 1 Getting Started by Jim Wilson

Jim has over 30 years of software engineering experience, with the past 15 years heavily focused on creating mobile device and location-based solutions. He has co-founded multiple software-related startups and has served in a consulting role at several more.

After nearly a decade as a Microsoft Device Application Development MVP, Jim now focuses on developing Android and iOS device applications. Jim’s passion is mentoring software developers. He blogs at hedgehogjim.wordpress.com.

Also in this series:

Part 1 – Series Overview
Part 2 – Setting up your environment
Part 3 – Android Toolset Fundamentals
Part 4 – Dalvik Debug Monitor Server
Part 5 – Understanding Android Projects
Part 6 – Android Studio
Part 7 – Understanding Android Versioning

Understanding Android Projects

Android project decisions

Jim says the first thing to decide is your project name, and asks “What’s is a name?”

In Android, the project name affects how classes are packages, affects some of the setting screens, and affects the Google Play identity. Google Play is the main Android App market.

We also need to think about the app appearance. This includes the Android launcher icon and the User interface flow and structure.

And another key questions is which Android versions should we support? Jim talks about this a lot more later in this course.

Walkthrough: Creating a new project

Jim creates a new workspace. A workspace is a grouping of projects in Eclipse, and Jim explains how it differs to Visual Studio.

Inside Eclipse he creates a new project with File->New->Android Application Project

We see a wizard, and on the first screen it is asking us to enter the following information:

  • Application Name
  • Project Name
  • Package Name
  • Minimum Required SDK
  • Target SDK
  • Compiles With
  • Theme

Jim explains all of these, fills in the information and clicks next. The next screen has the following checkboxes:

  • Create custom launcher icon
  • Create activity
  • Mark this project as a library
  • Create Project in Workspace
  • Add project to working sets

The create activity checkbox is an important one. Do we want our app to have a UI? If so, we should check this.

Then we see the Configure Launcher Icon screen. We can select our own icon file here, and we have the option of selecting a predefined clip art image and change the foreground and background colors.

Jim also demonstrates the “Trim Surrounding Blank Space checkbox”, which enlarges the content portion of the image.

We can also type in text and have this text displayed as an image.

The next screen is titled “Create Activity”. We can choose a Blank Activity, Fullscreen Activity, or Master/Detail Flow. Jim chooses a Blank Activity.

The final screen is titled “Blank Activity” and has the following settings:

  • Activity Name (this means the Java class name)
  • Layout Name (this is a XML layout resource)
  • Navigation Type (None, Fixed Tabs + Swipe, Scrollable Tabs + Swipe, Dropdown)

Android project members

In the Eclipse IDE, there are 3 kinds of project members most commonly interacted with:

  • Java files
  • Resource files
  • AndroidManifest.xml file

Jim explains each of these here.

The Android Manifest is an XML files that contains identifying information about the app, such as the privileges we want, and what SDK we want to support. Jim says it’s a really critical file.

Walkthrough: Android project members

Inside the Eclipse IDE, Jim explains the Package explorer, and opens MainActivity.java.

Next he shows us the activity_main.xml file. We can make manual text changes here, or use the GUI to update the contents in here.

We also see the drawable images:

  • drawable-hdpi
  • drawable-ldpi
  • drawable-mdpi
  • drawable-xhdip
  • drawable-xxhdpi

These relate to the automatic adaptability of device differences that Android supports. The image at the most appropriate resolution with be displayed to each user.

Next Jim discusses the values folders. There are different xml files in each values folder to support older versions of Android.

We see our AndroidManifest.xml and the sections that it has include uses-sdk, application and activity.

There are actually different views for each section. Eclipse has the following tabs:

  • Manifest (with package, SDK versions etc)
  • Application (with Name, Theme, Label, Icon etc)
  • Permissions (e.g. Uses Permission)
  • Instrumentation

Android project build steps

The file that we send to an Android device which contains our program is an APK file. APK stands for Android Package Kit.

The Android Asset Packaging Tool (AAPT) takes both our resources and the Android Manifest and outputs R.java and compiled versions of the resources.

Then our Java source code runs in the Java compiler, and the R.java file is also fed into the Java compiler. This produces a Java class file.

Because Android uses the Dalvik runtime instead of standard Java runtime, the Java classes need to be fed into a tool called DEX, which stands for the Dalvik Executable Tool.

The name Dalvik was originally named after a fishing village in Iceland.

Recently Dalvik has been succeeded by Android runtime (ART). For more details see ART and Dalvik

Walkthrough: Android project build results

Back in Eclipse, Jim starts the emulator. He checks scale display to real size for video recording purposes.

A few seconds later we see a gen folder. This contains Generated Java Files. Inside we can see R.java.

Jim explains that some of our code uses R as a Java class, for example R.menu.main.

He says every once in a while we might get compiler errors to do with the R class, meaning the R class is not being automatically generated for us. In this scenario:

  1. Confirm build automatically selected
  2. Clean project
  3. Confirm no errors in resource XML files

Lastly Jim shows us the bin folder, which contains our DemoApp.apk file.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s