Javatpoint Logo
Javatpoint Logo

Android Studio Ubuntu

What is Android Studio?

Android Studio is an official IDE (Integrated Development Environment) for the development of an Android app that is based on the IntelliJ IDEA. Android Studio provides more aspects that increase our productivity when creating Android apps on top of the strong code editor of IntelliJ.

Some of these aspects are mentioned below:

  • A formative build system (Gradle-based)
  • A feature-rich and fast emulator
  • A unified platform where we can develop for every Android device
  • Apply modifications for pushing resource changes and code to our running application without rebooting our application
  • Extensive testing frameworks and tools
  • Lint tools for catching performance, version compatibility, usability, and other issues
  • NDK and C++ support
  • Support (built-in) for Google Cloud Platform, trying to make it convenient for integrating App Engine and Messaging of Google Cloud

Project Structure of Android Studio

All projects in Android Studio show the files of our project in the view of Android Studio. The view is coordinated by modules for providing fast access to the key source files of our project. Every build file is visible under Gradle Scripts on the top level and all modules of the app contain folders. These folders are:

  • res: It contains each non-code resource like bitmap images, UI strings, and XML layouts.
  • java: It contains the source code files of Java such as JUnit test code.
  • manifests: It contains the file, i.e., AndroidManifest.xml.

On disk, the project structure of Android Studio differs through the flattened representation. We need to choose the Project using the drop-down of the Project to see the original project file structure. Also, we can customize the project file's view for focusing on the specific features of the development of our app.

For example, choosing the view, i.e., Problems of our project will show many links for the source files including any recognized syntax and coding errors like a missing element closing tag of XML inside the layout file.

By applying the Gradle flexibility, we can achieve each of them without changing the core source files of our app. Android Studio creates files are called build.gradle. These files are plain text files that apply Groovy syntax for configuring the build along with elements offered by the Android plugin for Gradle.

All projects have one file of top-level build for the whole project and isolate the files of module-level build for all modules. Automatically, Android Studio generates the mandatory build files when we import an available project.

What is a Gradle-based build system?

Android Studio applies Gradle as the build system's foundation along with more specific compatibilities of Android offered via the Android plugin for Gradle. The build system executes as a consolidated tool from the menu of Android Studio and the terminal or command line independently. We can use the aspects of this build system for doing the below:

  • Extend, configure, and customize the process of the build.
  • Establish more than one APK for our app along with different aspects using similar modules and projects.
  • Reuse resources and code across source sets.

Components of Gradle-based build system

Build Variants

A build system can support us to establish distinct versions of a similar application using one project. It is helpful when we have both a paid version and a free version of our app, or if we wish to distribute more than one APK for different configurations of devices on Google Play.

Android Studio Ubuntu

Multiple Support of APK

Multiple support of APK permits us for efficiently creating more than one APK that is based on ABI or screen density. For example, we can create different APKs of any app for the mdpi and hdpi screen densities, even still examining them one variant and permitting them for sharing for test APK, ProGuard settings, dx, and javac.

Resource Shrinking

In Android Studio, resource shrinking automatically deletes unused resources through our library dependencies and package app. For example, if our application is using services of Google Play for accessing the functionalities of Google Drive, and we are currently not using Google Sign-In, resource shrinking can delete several drawable assets for the button, i.e., SignInButton.

Managing dependencies

Many dependencies for our project are described by a name inside the file, i.e., build.gradle. Gradle will take care of finding our dependencies and enabling them available in our build. We can declare the dependencies of the module, dependencies of remote binary, and dependencies of local binary in our file, i.e., build.gradle. By default, Android Studio can configure projects using the repository of Maven Central. This configuration is added in the build file (top-level) for the project.

Profile and debug tools Gradle-based build system

Android studio and assist us in debugging and enhancing the performance of our code, including performance analysis tools and inline debugging.

Android Studio Ubuntu

Inline debugging

We can apply inline debugging for enhancing our code walk-throughs inside the view of the debugger along with inline verification of variable values, expressions, and references.

  • The information of inline debug includes:
  • Tooltip values
  • Operator and lambda expressions
  • Method return values
  • Referring many objects that can reference chosen object
  • Inline variable values

Performance profilers

Android Studio offers performance profilers so we can easily track the memory and CPU usage, analyze network requests, optimize graphics performance, locate memory leaks, and find deallocated objects of our app. We can open the tab, i.e., Android Profiler using our app running on an emulator or device.

Heap dump

Simultaneously we can dump the Java heap and start garbage collection to the heap snapshot within the Android-specific binary format file (HPROF) when we are profiling the usage of memory in Android studio.

The viewer of HPROF shows classes, a reference tree, and instances of all classes for helping us to find memory leaks and track the usage of memory.

Memory profiler

We can use a memory profiler for tracking the allocation of memory and see where the objects are allocated if we perform many actions. Understanding these allocations makes us for optimizing the performance and memory use of our app by managing the method calls corresponding to those actions.

Access of data file

The tools of Android SDK like logcat and Systrace generate debugging and performance data for complete app analysis. We need to open the tool window, i.e., Captures for viewing the available produced data files.

We need to double-click on any file for viewing the data inside the list of the produced files. We need to right-click on any file, i.e., .hprof for converting them to a standard file format, i.e., Investigate our RAM usage.

Code inspections

Automatically, Android studio executes configured Lint and other types of IDE inspections for helping us easily recognize and solve problems along with the structural quality of our code.

The Lint tool can check the source files of our Android project for internationalization, accessibility, usability, performance, security, potential bugs, and optimization development for correctness. Also, Android studio performs the code inspection of IntelliJ and validates many annotations for streamlining the workflow of our coding in inclusion to Lint checks.

Android Studio Annotations

Android Studio can support annotations for return values, parameters, and variables for helping us catch bugs like resource type conflicts and null pointer exceptions. The manager of Android SDK can package the library of Support-Annotations within the support repository of Android for application with Android Studio. Also, Android Studio can validate many configured annotations at the time of code inspection.

Log messages

We can check the adb output and the log messages of the device inside the Logcat window if we build and execute our app using Android Studio.

Performance profiling

We need to start the Android Profiler by selecting View > Tool Windows > Android Profiler if we wish to profile the network performance, memory, and CPU of our app.

User Interface of Android Studio

Some of the important components of the user interface of Android Studio are mentioned below:

Android Studio Ubuntu
  • Toolbar: It lets us carry out a huge variety of actions such as launching the tools of Android and running our app.
  • Navigation bar: It helps us to navigate to our project and start files to edit. It gives a more compact structure view that is visible inside the window, i.e., Project.
  • Editor Window: It is where we build and change code. The editor can modify depending on the latest file type. For example, the editor shows the Layout Editor if viewing the layout file.
  • Tool Window bar: It executes around the IDE window's outside and includes the buttons that permit us for expanding or collapsing single tool windows.
  • Tool Windows: It gives us access to unique tasks such as version control, search, project management, and more. We can spread them and collapse them.
  • Status bar: It shows the status of the IDE itself, our project, and any messages or warnings.

We can organize the primary window for giving ourselves more space on the screen by moving or hiding tool windows and toolbars. Also, we can use the shortcuts of the keyboard for accessing almost all features of IDE.

We can search across the components of the user interface, actions, databases, source code, and so on, by double-clicking on the key, i.e., Shift, or pressing the magnifying glass inside the upper right-hand side of the Android Studio window. It can be very helpful when, for example, we are trying to locate a specific action of IDE that we have forgotten how to trigger.

Tool Windows

Android Studio pursues our context and brings up corresponding to windows automatically as we work rather than applying pre-set perspectives. The most generally used tool windows are by default pinned to a tool window are at many applications window edges.

  • For expending or collapsing a tool window, we need to click on the name of the tool inside the tool window bar. Also, we can attach, detach, unpin, pin, and drag tool windows.
  • For returning to our current layout of the default tool window, we need to select Window > Restore Default Layout or customize our default layout by pressing Window > Store Current Layout as Default.
  • For showing or hiding the whole tool window bar, we need to select the icon, i.e., the window inside the bottom left-hand side of the Android Studio Window.
  • For locating a particular tool window, we need to hover on the icon of the window and choose the tool window using the menu.

Also, we can use the shortcuts of the keyboard for opening the tool windows.

Code completion of Android studio

Android studio contains three code completion types that we can access with keyboard shortcuts.

A few keyboard shortcuts for Android studio code completion are mentioned below:

Type Explanation Linux and Windows Mac
Basic completion It shows basic recommendations for expressions, methods, types, variables, and so on. If we call common completion twice within a row, then we will see more outputs like non-imported static members and private members. Ctrl+Space Ctrl+Space
Smart completion It shows corresponding options that are based on a context. This completion type is known to the data flows and expected type. If we call this completion twice within a row, then we will see more outputs like chains. Ctrl+Shift+Space Ctrl+Shift+Space
Statement completion It completes the latest statement for us adding missing braces, brackets, formatting, etc. Ctrl+Shift+Enter Shift+Command+Enter

Also, we can display intention actions and perform quick fixes by clicking Alt+Enter.

Find sample code in Android Studio

In Android Studio, the browser of the Code Sample supports us to find Google-provided and high-quality samples of Android code that are based on the highlighted symbol currently in our project.

Navigation

Here are a few tips to support us to move across Android Studio:

  • Switching between our accessed files (recently) with the help of an action, i.e., Recent Files. We need to click Control+E for bringing up the Recent Files action.
  • Viewing the current file's structure with the help of an action, i.e., File Structure. We need to click Control+F12 for bringing up the File Structure action.
  • Navigate to and search for a particular class in our project with the help of an action, i.e., Navigate to Class. We need to click Control+N for bringing up the Navigate to class action.
  • Navigate to a folder or file with the help of an action, i.e., Navigate to File. We need to click Control+Shift+N for bringing up the Navigate to File action.
  • Navigate to a field or method by name with the help of an action, i.e., Navigate to Symbol. We need to click Control+Shift+Alt+N for bringing up the Navigate to Symbol action.

Formatting and Style

Automatically, Android Studio uses styles and formatting as described in the style settings of our code as we edit. We can customize the style settings of the code using programming languages line describing conventions for blank lines, braces, wrapping, spaces, indents, and tabs.

For customizing the style settings of our code, we need to press File > Settings > Editor > Code Style > (Android Studio > Preferences > Editor > Code Style in a Mac system).

However, the IDE uses formatting automatically as we work. Also, we can call the action, i.e., Reformat Code explicitly by clicking Control+Alt+L or auto-indent every line by clicking Control+Alt+l.

Prerequisites

  • 64-bit distro capable of executing 32-bit applications.
  • Min 3 GB RAM and 1 GB for Android emulator.
  • GNU C library 2.19 or later.
  • Min space of the disk of 2 GB.
  • The min resolution of the screen must be 1280*800.

First Method: Using the Ubuntu Software Centre

Android Studio can easily be installed using the Ubuntu Software Centre. However, the desired application should available within the software store.

  • We need to check out the Ubuntu Software Centre for installing Android Studio and find Android Studio.
    Android Studio Ubuntu
  • We will need to select the button, i.e., Install when we found the application.
    Android Studio Ubuntu
  • We will be asked for a password for confirming the process of the installation. Within the application tray, we will have the icon of Android Studio when the process of the installation gets finished.
  • We can see the section of the final setup when it is successfully installed.

Second Method: With the Snap Tool

It will become very convenient to install the software packages if the snap tool exists. We don't need to change any type or file in any command. However, we require to have the Snap that is installed in our computer inside the first position. Snap can be installed with the help of the following command:


Android Studio Ubuntu

We can continue installing Android Studio when the installation process of Snap is completed. It can be done with the help of the following command:


Android Studio Ubuntu

We will have to wait for some time as it might take some minutes. It should be successfully installed, but for a few reasons, when it gives an error, then we need to include a parameter, i.e., --classic in the command as mentioned below:


Android Studio Ubuntu

We can see the section of the final setup when it is successfully installed.

Third Method: With the Zip File

Install Java OpenJDK

We need the 8th version of the OpenJDK to be installed on our system for installing Android Studio. We will first install OpenJDK 8. We can simply begin by updating a package index as the installation process is very easy:

We can use the following command for updating the package index:


Android Studio Ubuntu

We will now install the 8th package version of the OpenJDK with the help of the following command:


Android Studio Ubuntu

We can enter the following command for verifying the installation process to see the version:


Android Studio Ubuntu

Install Android studio

We need to open the terminal with the help of the keyboard shortcut, i.e., Ctrl+Alt+T, and enter the following command for downloading and installing the snap package of the Android studio:


Android Studio Ubuntu

We will find the below output when the process of installation is finished:

Android studio is installed on the Ubuntu desktop successfully.

Getting started with Android studio

We can begin Android Studio from our terminal or command line by entering android-studio in the terminal or by pressing the icon of Android Studio when the Android Studio application has been installed in our system with the help of the above methods.

The following window will occur prompting us for importing the settings of Android Studio using the previous installation when we begin the Android Studio application for the very first time.

The window, i.e., Setup Wizard will occur when we press on the button, i.e., OK. We need to press the next button for starting the post-installation steps and initial configuration. Now option to select the setup type we wish for Android Studio will occur. We can choose the options, i.e., Standard or Custom if we wish to customize the Android studio.

We can choose the theme of UI and the Setup Wizard in the upcoming step. This step will help us to download and install the needed components of SDK. This process might take some time relying on the connection speed and our system. The welcome page would be represented when the IDE of Android Studio is loaded.


Next TopicAnyDesk Ubuntu





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA