Getting started with Android Studio: requirements, installation, initial setup, and tutorials

- 👤 Andrés Cruz

🇪🇸 En español

Getting started with Android Studio: requirements, installation, initial setup, and tutorials

As you know for a long time now that Google went from the already obsolete Eclipse with the ADT plugin to Android Studio; which is the official IDE that is based on a variant of intelligent idea and that offers us fantastic tools and possibilities for the development of Android applications.

This entry will indicate the first steps to use Android Studio, its requirements, features offered by this IDE and will also list a series of other tutorials that consist of their respective examples with which we can start in the world of Android application development.

Android Studio, our best ally for the development of Android apps

Android Studio is a powerful tool for building Android applications which should be the "norm" when developing Android applications as it already incorporates a large number of tools that Eclipse does not have (such as Android Device Monitor) or must be installed based on Eclipse. to plugins (Gradle...).

This post provides a basic introduction to Android Studio.

We will see how to install Android Studio, take the first steps, some keyboard shortcuts that you probably use in the old Eclipse with the ADT plugin and some explanations about its interface and new changes.

Requirements to use Android Studio on our computer.

Like all software, the requirements as updates are released, which in a few words means that with the passage of time, their hardware and of course software requirements increase; to date these are the requirements that are needed:

Requirements for Windows

  • Microsoft® Windows® 7/8/10 (32- or 64-bit)
  • 3 GB RAM minimum, 8 GB RAM recommended; plus 1 GB for the Android Emulator
  • 2 GB available space minimum, 4 GB recommended (500 MB for IDE + 1.5 GB for Android SDK and emulators)
  • 1280 x 800 screen resolution

Requirements for Mac

  • Mac® OS X® 10.10 (Yosemite) or higher - 10.13 (macOS High Sierra)
  • 3 GB RAM minimum, 8 GB RAM recommended; plus 1 GB for the Android emulator
  • 2 GB available space minimum, 4 GB recommended (500 MB for IDE + 1.5 GB for Android SDK and emulators)
  • 1280 x 800 screen resolution

Requirements for Linux

  • 2 GB available space minimum, 4 GB recommended (500 MB for IDE + 1.5 GB for Android SDK and emulators)
  • 1280 x 800 screen resolution

These requirements were taken from the official page that you can consult here.

Installing Android Studio

To get our copy of Android Studio for later installation, we must go to the official Android portal at the following Android Studio link and click on the Download Android Studio button:

Descargar Android Studio

Installing Android Studio on any platform couldn't be easier; in Linux we must unpack the downloaded file, relocate it to the directory we want and execute the studio.sh located inside the IDE's bin folder:

 sh studio.sh

Or if we are in Windows, we run the .exe.

From here it will launch the installer -which, as in Windows- practically configures itself; You must have an Internet connection for it to finish downloading all the modules, SDKs, support libraries, etc. It is recommended that you install the Google Play Service package once:

Instalar Google Play Service en Android Studio

In case you feel like developing in any of the APIs that Google offers such as Google Maps, Firebase Cloud Messaging among others of the many APIs that are offered through this package.

How to create a project in Android Studio

Once installed and downloaded all Android Studio dependencies we can finally start developing applications in it.

To create our first project we have to go to the top menu and then:

File >  New >  New Project 

file new project

We will be presented with a new window where we will have to indicate the data of the application that we are creating by Android Studio:

crear android app

Application name: it is the name of the application that we are going to create.
Company domain: it simply indicates the folder structure or hierarchy that the project will have, where each dot (.) is a separator; for the previous example we would have a folder tree like the following: app | dl | ko.
Project location: It refers to the location where our project will be.

By clicking on the Next button we will be presented with the selection of the SDK as well as the selection of the environment to develop, Android for phones and tablets, for watches (or wear, at the moment it does not have much of a market), for TV (it is reinventing itself , but it does not have much of a market either) among others; generally we are interested in developing for mobiles and tablets, which is the default option:

selección android sdk

In addition to being able to vary the level of SDK or support that the application will have, although we can change this at any time from the Gradle files that we define a little below.

Then we go to the feature selection part that the application to create will have, we generally leave it in Empty Activity:

empty activity android sdk

Finally, we select the name of the main activity, as well as that of the layout that accompanies it (Android application development is based on a variant of the MVC model and therefore there is a separation between the controller, which is the Activity Name with the view that is the Layout Name of the following image):

Configurar activity android sdk

And then we press Finish and with this our project will be created.

What does Android Studio offer us?

Once our project is installed and created in Android Studio we will see an interface somewhat loaded like the following; the first thing we will see is a different structure from the one we used in Eclipse with the ADT plugin both in the interface and in our project:

Interfaz Android Studio

If we go to the AndroidManifest.xml:

We will see that it is quite small and information about the configuration of the project is missing; for example, the level of targetSdkVersion and minSdkVersion -to name a few-; these configurations must now be managed from the Gradle files:

Listados de archivos Gradle en Android Studio

Gradle files are plain text files to edit the different modules, libraries and configurations to incorporate into our project.

Most of the time it is enough to edit the /app/build.gradle:

apply plugin: 'com.android.application' android {    compileSdkVersion 22    buildToolsVersion "22.0.1"    defaultConfig {        applicationId "net.desarrollolibre.dolphinaudio"        minSdkVersion 15        targetSdkVersion 22        versionCode 1        versionName "1.0"    }    buildTypes {        release {            minifyEnabled false            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'        }    } } dependencies {    compile fileTree(dir: 'libs', include: ['*.jar'])    compile 'com.android.support:design:22.2.0'    compile 'com.android.support:support-v13:22.2.1'    compile 'com.android.support:cardview-v7:22.2.0'    compile 'com.android.support:recyclerview-v7:22.2.0'    compile 'com.android.support:appcompat-v7:22.2.0' }

In which are the dependencies (modules) and part of the basic configurations of Android (targetSdkVersion and minSdkVersion).

Modules in Android Studio

Now it is easier to use libraries created by third parties that, as you can see, most of them offer the option of incorporating them through a simple dependency.

Import libraries into projects using gradle

In the following link List of Android UI/UX Libraries you can find a fairly large section of resources for Material Design, review some and you will see in the installation section links like:

dependencies {   compile 'com.github.navasmdc:MaterialDesign:1.5@aar' }

What else does Android Studio offer us?

There are quite a few interesting tools that allow us to learn more about how our apps work, which is a very useful resource for testing our apps before publishing them somewhere like Google Play; one of them is Android Device Monitor.

Android Device Monitor

So that you know how these tools work, I recommend the following video tutorials created by the people of Google:

Android Device Monitor: Lesson 2A

The tool can be found at:

Tools > Android > Android Device Monitor

We will also see that there are very useful windows such as those presented for our layouts with their design/code modality that we saw in other applications such as DreamWeaver.

Fundamental keyboard shortcuts to use Android Studio like an expert

To indent our code in Eclipse with the ADT plugins instead of using the combination of control+shift + F we must use Control+ Alt + L.

To use the Search / Replace option we must use the Ctrl + F key combination.

You can check the following entry:

 

To see a more extensive list of keyboard shortcuts.

 

To complete it is the same key combination as Eclipse Control + Spacebar.

In this post we will see some keyboard shortcuts of all that exist that you can see in the following link:

Android Studio: Key combinations

These keyboard shortcuts indicated in this entry can be used for the most common situations that may arise when we are coding in Android Studio; in such a way that by using these shortcuts we avoid using other means such as the mouse and we can save a few seconds per operation, which in the end gives us considerable time savings (and less wear and tear on our hands!).

Control + E: Recently opened files popup

The first shortcut that we will see is one of the most general since it allows us to navigate between the files that we are editing or that are more common:

The shortcut in question is called "Recently Opened Files Popup" and that shortcut is Control + E:

control_e android studio

And using the cursors we can quickly navigate from one file to another once this small but useful window is open.

Project Quick Fix (show intent actions and quick fixes)

Many times Android Studio gives us some warning in our code, which is very useful since it allows us to improve the quality of our code, this is very common for example when we add text directly to our Java/Kotlin file, to see the warning it would be enough By clicking on the small icon that is positioned next to the line of code that has said warning, but we can also do it with a keyboard shortcut, we can press Alt + Enter:

alt_enter android studio

Control + i: Implement methods

Another very common problem is that when inheriting from other classes we probably have to override several methods that define these classes, so that Android Studio defines the basic scheme of these functions we must press Control + i.

control_i android studio

Alt + Enter: Quick fix project (show intent actions and quick fixes)

Next with the implementation of methods, when we are writing our code it is very likely that we want to create or use methods that do not yet exist within the class whose code we have selected, for this we press Control + Alt + M:

alt_enter android studio

Find/Replace

This keyboard shortcut allows us to search for code fragments or letters in the file that we are viewing at a given moment: Control + F; we also have another function that allows us to search and replace texts: Control + R.

Ctrl+Alt+M: Extract method

This shortcut allows us to place a code that we have selected and place it within the scope of a function that the same option creates (Extract method); the keyboard shortcut may not work for you on Windows, but you can also find such functionality from Refactor | Extract | Funtion or just change the keyboard shortcut to another; the keyboard shortcut is Ctrl+Alt+M:

control_alt_m android studio

Format code and Comment/uncomment with line comment

Other keyboard shortcuts that are a little better known are those that allow you to indent the selected code or all the code of a file in question; for this we press Control + Alt + L and the method to comment the selected line(s) of code(s); for this we press Control + /.

Creating/modifying our own keyboard and/or mouse shortcuts

It is likely that we have a problem with some keyboard shortcuts in our operating system, in my personal case the keyboard shortcut Control + Alt + L does not work for me, for those cases we can vary the assignment; for this we press Control + Alt + S or File | Setting and from Keymap we can customize the keyboard shortcuts:

keymap android studio

Creating our device

Virtual devices

As it happened with Eclipse with the ADT plugins, we must have at least one device configured to test our applications from the computer; the tool in question is still called AVD (Android Virtual Device); this is one of the many features that were brought over from Eclipse with the ADT plugins; to access the AVD we must go to:

Tools > Android > AVD Manager

Physical devices

You can also use physical devices; for this we must enable the developer options on our Android device, this was already discussed in a previous post: Configuring an Android device to develop; once this is done, we connect our device and we will see a screen like the following:

Dispositivos físicos - Asus TF300

Tablet Asus TF300

 

In this way, although the process of executing an application on the device will surely take a little longer (compared to a virtual one), but the system will have fewer processes to perform because it does not have to maintain a virtual device for our applications.

 

Resources, tutorials, and examples for developing in Android Studio:

We currently have more than 78 entries in DesarrolloLibre with which you can start developing applications for Android; starting from its basic components:

Among many others that you can consult in the section corresponding to Android in our blog:

Android

One of the latest additions (or one of the most momentous) is the incorporation of Kotlin, as a programming language that we can use in parallel (or only) when developing Android applications; Kotlin has many advantages over Java for the development of Android applications, being a modern, concise language that can even be run in the Java virtual machine:

 

How to clone a project in Android Studio

How to clone a project in Android Studio

A fairly common process when developing software is that at some point we want to clone it to quickly and easily reuse its components, in PHP it is easy, we just have to copy and paste the project, rename the root folder, change the configurations of the path, maybe the database and we're pretty much ready to start working with our copied or cloned project.

In Android Studio, this cloning is not so simple; So if we want to open, for example, an android studio project on another computer or reinstall our Android Studio or something like that, we must perform some of the previous steps and copy certain key sections of the source project (project to copy) into our new project (project to copy). destination or cloned) and performing some extra steps.

Creating the target/cloned project in Android Studio

The first difference between copying and pasting that we would do with a PHP project is that we must first create a new project in Android Studio by doing the traditional steps:

File - New - New Project

Very pending with the name of the package or package which you can obtain from the AndroidManifest of the project which we will use later.

And this newly created project would be our target project.

Once our destination project has been created, the best thing we can do is close Android Studio to avoid any generation of a process by it to the base project or blocking a file that we want to replace.

Now we must replace the key files, first the application resources which are in the folder:

/app/src/main

We copy them from the project to be cloned to our destination or base project.

Now we go with the libraries in case they exist, we copy and paste them:

Copy /app/libs

Like these two files:

 

Override /build.gradle Override /gradle.properties

And the folder:

Override /gradle/wrapper

And of course, the AndroidManifest.xml:

Replace /app/src/main/AndroidManifest.xml

We are almost done, now we can open our Android Studio together with the base project to which we copied all the sources.

Surely it will give many errors, for the moment do not worry, first we must replace the name of the package with that of our new project (destination project) in each of the files including our manifest, for this we use the combination CONTROL + SHIFT + R and a window will open in which we must copy indicate the text to replace:

remplace in Path

Then we go to the grandle file and synchronize it.

Now from the menu of our Android Studio:

Build -> Clean Project Build -> Rebuild Project

If everything went well, we would already have our project cloned. In case there is an error, it is likely that you need to copy some more file or folder that you created manually in the destination project.

In summary:

Create a project Replace /app/src/main Copy /app/libs Replace /app/src/main/AndroidManifest.xml Replace /app/build.gradle Replace /build.gradle Replace /gradle.properties Replace /gradle/wrapper Replace the package name Build -> Clean Project Build -> Rebuild Project

The order in which you want to replace the source files to the destination is up to you and logically does not influence anything.

I agree to receive announcements of interest about this Blog.

Introduction to Android Studio; we will see its requirements, how to install it, its tools, create projects, create virtual devices, Gradle files, key combinations and other tutorials or resources to take the first steps.

| 👤 Andrés Cruz

🇪🇸 En español