CS 342: Mobile Application Development
Setting up Android Studio
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.
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 14
- On the second screen of the wizard, choose something other than Blank Activity
- Select Tools→AVD Manager, then click on New... to add a device emulator, choose some options,
then close the AVD Manager..
- Click on the bug toolbar button, or select Run→Debug app to build and run your app.
Wait... Wait... 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... wait... OK, now your app is running. Whoohoo!
- Curse the slowness of the Android emulator. Brood over the unfairness of life.
- [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.
- [Optional] Bask in the joy of having an emulator that runs more quickly than the movement
of the tectonic plates.
Get one of the official sample apps
- Method 1: go to the
Android Studio samples page, select
a sample, and click on its download link.
- Method 2: in 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.
On a Mac, it's in /Applications/Android Studio.app/sdk/samples/.
Build and run a sample app
Suppose you have made a copy of the BorderlessButtons sample app. If you go to File→Import Project
and select BorderlessButtons/build.gradle, the project will import. It's possible that you'll now be able
to poke the bug button and build and run the project with no trouble. As you witnessed in class, however,
that is not what happened on my Mac laptop. Here are my notes on how I succeeded in getting
BorderlessButtons to work.
The problems getting the sample to build are a few version numbers hard-coded into the samples that
are inconsistent with the tools as installed on my computer. Change those numbers, and all is well.
- Open the dummy program you generated in the first section above.
Use it to find the correct values for the steps below.
- In BorderlessButtons/BorderlessButtonsSample/build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
}
}
we need to change the "0.8.+" to whatever value appears in the corresponding place in
the dummy program. For me, the number was "0.9.+".
- Also in BorderlessButtons/BorderlessButtonsSample/build.gradle:
android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
...
}
we need to change the "19.0.1" to whatever value appears in the corresponding place in
the dummy program. For me, the number was "19.0.3".
- In BorderlessButtons/gradle/wrapper/gradle-wrapper.properties, I had to change
distributionUrl=http\://services.gradle.org/distributions/gradle-1.8-bin.zip
to 1.10 instead of 1.8. The 1.10 came from the error message Android Studio gave me when I tried to build
BorderlessButtons in the first place.
Those three changes did the job on my system. If you have additional problems, please
post the problems (and the solutions, if you find them) on Piazza.
Resources