To get started, you’ll need to install Android Studio. You can get it along with instructions at the Android developer site. This will also download the Android SDK. Make sure that you have plenty of space. Over time, installing different versions of the Android SDK can fill up hard drive space quickly. If you don’t have Java installed, make sure to grab that as well. JDK 8.x will do.
If you need to update the SDK files you can do so in Android Studio under
Tools > Android > SDK Manager
Alternatively, in the command line you can type:
To quickly find a shortcut or command in Android Studio you can use the Find Action search box. Hit
Ctrl or Cmd +Shift+A, then type what you’re looking for.
If you are having trouble setting up Java or the SDK, check your environment variables (.bash_profile or .bashrc in Linux). If they don’t exist, add:
You can test these with
javac -v and
adb -h (Android debugging bridge)
Getting started with Android Studio
Start up Android studio and create a new project.
Give your project a name and choose blank activity.
An Activity in Android is a presentation layer for the UI.
Methods that start with on are automatically invoked by Android. We don’t need to call them manually. Ex: onCreate, onClick.
Layouts are XML files that are used to build visual components in Android.
This example uses LinearLayout. This type of layout is useful for stacking views vertically, horizontally, or side-by-side.
android:layout_width="fill_parent" Takes up the entire width of the screen.
android:layout_height="fill_parent" Takes up the entire height of the screen.
android:layout_height="wrap_content" Gives just enough room to display the line (height-wise in this case).
You should not hard-code data like this.
Instead, it should be saved as a variable in res/values dir/strings.xml.
Now that it is defined, you can call the greeting string in main.xml
Similarly, you can save colors into colors.xml
Running the project
Before you get too far in your project you might want to test it. If this is your first time in Android Studio, you’ll need to set up an AVD, which stands for Android Virtual Device. Click
Tools > Android > AVD Manager. You can create as many virtual devices as you’d like, but keep in mind they do take up a lot of space and they tend to run slow.
Create Virtual Device > Phone > Nexus 5 (or whatever type of device you want to test on) then click
Next. Here you can name the device and set some default settings. Most importantly, you can set the API level of the device. Click
Finish When you are done.
To run your application click on
Run > Run. This will give you a Run dialog. There might be multiple options here if you have more than one project open. Click on the name of the app you want to run, then after a few seconds Android Studio should ask you to choose a device. Select the device you want to use and click OK. If all goes well, your AVD should start up with your app running. If not, you’ll have to take a look at the console in Android Studio for any error messages and debug the issue.