Android development is a fun experience, allowing those technically adventurous types to make really interesting applications for a variety of different devices. Google has made development even more accessible for the Android platform with its ADT Bundles- development environments requiring very little setup and are ready to go out of the box. For those readers interested in this turn key approach to set up a development environment and primarily own a mac, here is a step by step tutorial from download to debug.
Step 1: Download and Launch the ADT Bundle
As with any installation of new toolkit, the first step is downloading the necessary tools, which can be found at this link:
After going through the Terms and Conditions and downloading the app, you should end up with a zip file containing the latest version of the ADT Bundle for OSX found in your browser’s specified Downloads directory. Using a terminal instance, unzip the contents to a desired location in your home directory:
unzip ~/Downloads/adt-bundle-mac-x86_64.zip -d ~/.
Now that we have the ADT Bundle extracted, we are ready to start. In order to launch the ADT IDE, open up the extracted bundle directory in an Finder instance. Next, click on the OSX application “eclipse.app” found in the root of the bundle directory:
Doing so should normally start an instance of prebundled Eclipse IDE environment for android. As mentioned earlier, the ADT IDE is built on the Eclipse platform, which requires a java runtime to run. If you do not have the java installed on your mac, you will be given a prompt to install the latest Java JRE that Apple supports:
Go ahead and select install to get the JRE on your system. After the installation completes, relaunch the eclipse.app icon in Finder and you should be ready to go.
Once you get Eclipse running, the you will be prompted with is where should you put your development workspace:
Select the location that suits you best and click ok, which will bring you into the Eclipse IDE:
Step 2: Configure your Android Device Emulator
One of the niceties about the ADT bundle is that there are emulator images out of the gate, without any additional downloads required. Creating a virtual device is pretty painless with this prepackaged setup, which we will do this for our next step in this tutorial.
To start creating a new virtual device, we first need to ensure that we are viewing ADT in the Java perspective. To do so, select Window -> Open Perspective -> Other. In the dialog that opens, select the perspective titled “Java (default)”:
After selecting “OK” in this dialog, open the Android Virtual Device Manager by selecting Window -> Android Virtual Device Manager from the Menu Bar. This will launch the Android Virtual Device Manager, a utility to manage Android emulators running on the ADT development environment. SInce this is the first time we are using the device manager, We need to create a new device for our future Android projects. To do so, select “Device Definitions” in the device manager to create your first device image. We are going to be emulating a Nexus 7 tablet in this tutorial, so select the Nexus 7 template and select “Create AVD”:
The device emulator currently includes some nice features as GPU acceleration and running from a previously booted snapshot of the image. For this tutorial, we will just use the default settings, so select “OK” with the selected options to create a new image to emulate a Nexus 7. You will now see a new device image in the “Android Virtual Devices” view. Select the newly created device and start the image, using all the default launch options.
Select “Launch” to start up the Android Arm Emulator running this selected image. In a few minutes, the device should finish booting, showing the android home screen:
Click the blue “OK” button in the emulator window and leave the virtual device running in the background. We will use this image later in the tutorial when we debug our first app.
Step 3: Create an Android Project in the ADT IDE
Now that we have the IDE installed and an emulator running, we are ready to create our first Android Project. This is an eclipse project using convential views of this IDE, with highly customized tools used for Android device development.
To get started, close out the welcome screen (press “X” in the tab) to reveal the empty development workspace in the eclipse Java perspective:
To add our first Android project to the workspace, select File -> New -> Android Application Project from the menu bar. This should launch the first page of the “New Android Application” wizard. To identify this project in the workspace, enter “Test” as the Application Name, “Test” as the Project Name, and “com.testdomain.test” as the Package Name:
We are going to stick with the default settings for now, so click next through the next 3 screens and leaving the settings unmodified. On the last screen of the wizard, select “Finish” which creates a new project called “Test” in our workspace:
Be default, our design environment is configured to support the UI of a Nexus One device. We want to match a Nexus 7 device, since it was we are targeting with our emulator. To do so, select the layout for our default activity in activity_main.xml (this should be already open for you in the design area of the project). Then, select the option to match the Design time theme with the Nexus 7 emulator image by clicking “AVD_for_Nexus_7_by_Google”:
With this, you will see our design time environment change to that of a Nexus 7 device:
Since we will not be doing any custom development in this project, we are ready to continue on with our tutorial.
Step 4: Setting up the Debugger
The final step in our getting started tutorial is configuring the IDE for debugging with a running emulator image. To do this, open up the Debug Configurations Manager by selecting Run -> Debug Configurations from the menu bar:
To create the configuration for our project select “Android Application” as the configuration type and press the “New Configuration” icon. This will create a configuration that matches tools and interop with the android debugger. In the new window, rename the configuration to “Test” and select the project associated with this configuration to be “Test” as well:
Next, we want to set up the debugger when lauching to pick a running instance instead of launching a new one each time. This is a real time saver when using the integrated debugger in the ADT eclipse bundle, reducing debugging launches from several minutes to a few seconds. To do so, select the “Target” tab, then select “Always prompt to pick device”. This allows us to attach to the running emulator that IDE can detect:
Click “Apply” and “Close”, and we now have a debug configuration we can use efficiently with this project.
The last step is a simple one of adding a breakpoint to our project. To do so, select the the “Package Explorer” pane, open up src -> com.testdomain.test -> MainActivity.java. Select the first line of the onCreate method and add a breakpoint by pressing Command > Shift > Break on the keyboard:
We now have debugging configured, and are all ready to launch the application.
Step 5: Launch And Debug the Application from the Emulator
Since we have gone through the previous steps, launching and debugging is very straight forward. To start from the menu bar, launch the application in debug mode by selecting Run -> Debug. We can also use the default shortcut key of Command > F11, assuming that OS mappings enabled for this key. Once the debugger is started. we will immediately be prompted with the “Android Device Chooser”. Select the image “AVD_for_Nexus_7_by_Google” to get running:
Once this selected, Eclipse will prompt the developer that the IDE perspective is going to change to the Debug perspective. This perspective makes it easier durring debugging, opening up the debugger play controls and appropriate debugging tools windows. We want to enable this pretty much all the time, so check “Remember my decision” and select “Yes”:
The environment will switch to Debug perspective with our app launching in the emulator. You will see that the breakpoint we set earlier has been hit and the application is suspended. From here we can inspect variables, view the stack, and control the debugger with the play controls:
After inspecting the state of the Application in the debugger, lets let the app run and render on the screen. To do so, select the Resume button or the shortcut key F8. We now see the application running, our end our tutorial:
Next steps: Develop!
If you followed this tutorial successfully, you should have in place the basic steps needed for development of and Android Application on your Mac OSX pc: Installing the IDE, Setting up an emulator instance, creating a test application, configuring the debugger for speedy development, and launching the debugger to use in the application. Now, with (a lot of) further research in the Android programming model and their APIs, application development is possible and you are all set to go.