Getting Started With Android Studio

Filed Under: Android

Welcome to the series of tutorials on Android Development with Kotlin. This series is designed with the goal to help you build Android Applications using Kotlin. We’ll start with the absolute basics of Android Development and as the series progresses you’ll gain expertise in doing Android Development with Kotlin.

In this tutorial, we’ll start with the introduction of Android Studio. If you’ve used Android Studio in the past, do go through this tutorial to know the new features and changes that Android Studio 3.0 brought in.

Android Studio Getting Started

Android Studio is based on JetBrains’ IntelliJ IDEA software and is specifically used for Android Development. It is available for Windows, Mac, and Linux computers. You can download it for your relevant OS from this link.

Note: You need the Java Development Kit installed on your system to build and run Android Studio projects.

Let’s start our Android Studio IDE for the first time!

android studio tutorial

With the introduction of Android Studio 3.0, the loading screen looks cooler!

Updating Your IDE
If you have an older Android Studio IDE, do update it from the menu: Android Studio -> Check For Updates.
Subsequently, update the gradle plugin by the prompts that follow.

Your root build.gradle file looks like this:


buildscript {
    repositories {
        google()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
    }
}

Android Studio Features

Android Studio 3.0 is a big update over the previous 2.3.2 and is focused on aiding the developers.
Following are the major features that have arrived with this update:

  • Built-in Kotlin Support
  • Changes in Gradle Syntax
  • Extended Support for Java 8
  • Optimizing Using Android Profiler
  • Android Instant App Support

Built-in Kotlin Support

For pre-Android Studio 3.0 IDE following was the procedure to enable Kotlin support in your application:

Go to Android Studio | Preferences | Plugins | Install JetBrains plugin | Kotlin.

The following screen demonstrates the same:
Android Studio Kotlin Plugin

With the Android Studio 3.0 update, the Android SDK provides built-in Kotlin support while creating a new project as shown below.
Android Studio Kotlin Support

android studio target devices

Choose Target Devices

Note: What happens when instant support is enabled in the above window would be covered in a later section.

android studio activity type

The root build.gradle file looks like this:


buildscript {
    ext.kotlin_version = '1.1.51'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

To facilitate smaller and faster updates, Android Studio 3.0 utilizes Google’s Maven Repository google() by default instead of using the Android SDK Manager to find updates to Android Support Library, Google Play Services, and Firebase Maven dependencies.

The app module’s build.gradle is given below.


apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "net.androidly.androidstudiokotlin"
        minSdkVersion 16
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

Changes in Gradle Syntax

With the introduction of Android Studio 3.0, the keyword compile is deprecated. implementation and api are used instead.
Typically all compile statements are replaced with implementation.
An implementation statement rebuilds only the single module whereas the api statement would rebuild all modules that are dependent on the current one. So unless your module doesn’t leak its interfaces with other modules, implementation should be used.

compile 'com.android.support:appcompat-v7:26.1.0'

//changes to

implementation 'com.android.support:appcompat-v7:26.1.0'

Java 8 Support

Unlike the previous versions of Android Studio wherein you had to enable third-party plugins,
apply plugin: 'me.tatarka.retrolambda' Android Studio 3.0 has inbuilt support for Java 8.

It can be enabled from File | Project Structure as shown below:
android studio java 8 support

Android Profiler

The Android Profiler tool in Android Studio 3.0 replaces the Android Monitor tools. These new profiling tools provide real-time data for your app’s CPU, memory, and network activity.

To open the tool goto : View | Tool Windows | Android Profiler

android studio profiler

The tool displays the CPU, memory and network profiler timelines in a single frame.

Android Instant App Support

Android Studio 3.0 comes with the support for Instant Apps. Instant Apps allow the user to load a part of native application without the need to install the complete application. You must have come across hyperlinks in the browser that asks you to install the application to view the contents. Instant App rescues the user from this. It allows for viewing the native app in your browser without the need to download it from the play store.

Instant App Support is available for API > 23 and can be enabled from the following window.

android studio instant app target devices

android studio custom instant app support

This is how the project structure for an instant app looks like:
android studio project instant app support

Let’s look at each module separately.

  • Base feature module:
    The fundamental module of your instant app is the base feature module. All other feature modules must depend on the base feature module. The base feature module contains shared resources, such as activities, fragments, and layout files. This creates a feature APK when built.
    The build.gradle of this module looks like:

    apply plugin: 'com.android.feature'
    
    android {
        compileSdkVersion 26
        baseFeature true
        defaultConfig {
            minSdkVersion 23
            targetSdkVersion 26
            versionCode 1
            versionName "1.0"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }
    
    dependencies {
        api 'com.android.support:appcompat-v7:26.1.0'
        api 'com.android.support.constraint:constraint-layout:1.0.2'
        application project(':app')
        feature project(':feature')
    }
    
    
  • Instant App Module:
    The build.gradle of this module looks like:

    apply plugin: 'com.android.instantapp'
    
    dependencies {
        implementation project(':feature')
        implementation project(':base')
    }
    
    

    It builds the Instant App APK that the user views without downloading the app.

  • App Module:
    It builds our application’s APK.
  • Feature Module:
    This contains code for the part of application that would be shown in the instant APK

The structure of an instant app on a high level looks like:

android studio instant app structure

Note: It can contain multiple features too.

Summary

Besides the above major changes, Android Studio 3.0 has wholesome other changes. Majorly, performance improvements, build speed optimizations to accelerate your development.

We love the Dark Theme in Android Studio and recommend you the same. It’s available from Preferences | Appearances | Themes | Darcula as shown below.

android studio theme

This brings an end to Android Studio getting started tutorial. Let’s start with our Hello World Application Using Kotlin in our next tutorial.

Leave a Reply

Your email address will not be published. Required fields are marked *

close
Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages