Our first project this term will be a very simple Android project, to get you familiar
with some basic app development tools (IDEs, platform SDKs, emulators, build systems, etc.) and concepts
(the various forms of Model-View-Controller, etc.). The first step is to get your development
environment set up on your own computer. You may use the CS labs, of course, but it's actually important
to learn how to set tools up yourself--that's part of life as an app developer. So ideally,
you'll set up your own computer as your main development system for the term.
Get an empty project running
- Download and install Android Studio
- Launch Android Studio
- Create a New Project:
- Change the Application Name to something other than "My Application"
- Change the Package Name to be com.yourname... instead of com.example...
- Change Minimum Required SDK to API 15
- On the second screen of the wizard, choose something other than Blank Activity.
Pick one that you'd like to see in action. You can always create another sample from
a different template later.
- Select Tools→Android→AVD Manager, then click on Create Virtual Device... to add
a device emulator (I like the Nexus S, since its emulator fits nicely on my laptop screen).
Work your way through the screens (pick Android 5.1 for your emulator's OS, choosing
x86 or x86_64 depending on whether you have a 64-bit computer),
then close the AVD Manager.
- Click on the bug toolbar button, or select Run→Debug app to build and run your app.
Wait...wait some more...now in the Choose Device dialog that pops up, select Launch Emulator and pick
your newly-added emulator from the drop-down list.
- Wait...wait...get coffee...OK, now your app is running. Actually, no. Your app probably timed out
waiting for the emulator to launch. Once you have an emulator running, you'll need to swipe it open
with your mouse (click and drag upwards on your Android screen), and click through some intro crap.
Then go back to Android Studio and hit the Debug button again to launch your app. Whoohoo!
- Curse the slowness of the Android emulator--unless your computer is new enough that the
Android Studio installer installed HAXM,
the Intel Hardware Accelerated Execution Manager. If it did, you'll be pretty happy. When I installed
it on my 2.5-year-old MacBook Pro, HAXM went in there without incident. I haven't researched in detail
which processors support HAXM, so you'll just have to see if the emulator is fast enough for you.
- [Optional] Download and install the free version of
Genymotion.
This requires a registration. Are you on a Mac or Linux? Whoops, you'll also need
VirtualBox before Genymotion will run.
- [Optional] Launch Genymotion and click on the Add button to add a Genymotion emulator
for an Android device. Once it appears in your main Genymotion list, double-click on it to launch
it.
- [Optional] Go back to Android Studio and hit the bug icon again. When the Choose Device
dialog appears, choose your new Genymotion emulator.
Get some sample apps
- Make a git clone of
my android_samples repository on github
and start with the ButtonDemo app, moving on to the ListDemo app later.
I'll put more samples here as needed.
- Or, you can get a sample from the
Android Studio samples page, select
a sample, and click on its download link.
- It's also possible to get the official samples from within
Android Studio. Go to Tools→Android→SDK Manager. Within
SDK Manager, select Samples for SDK for whatever version of the SDK you have installed, and then
click on the Install Packages button. The trick now is to find where SDK Manager hides the samples.
Build and run a sample app
Suppose you have my ButtonDemo app. If you go to File→Open
and select the ButtonDemo folder, the project should load. You'll probably have to click the Project
tab on the upper left of the Android Studio window to see your source files listed.
Sometimes, importing samples gets tricky, however, so you may need to experiment with
the File→Import Project menu item. Post to slack if you're having trouble.
Resources