ArticleTutorial

Android App Development Environment Setup

🚀 Ready to dive into Android app development without the bulk of Android Studio? In this comprehensive guide, learn how to set up a complete development environment using just VS Code, Android SDK command‑line tools, AVD Manager extension, and Kotlin! Happy coding! 😊🔧

Welcome! In this guide, I’ll show you how to set up a fully functional Android app development environment using only:

  • Visual Studio Code (VS Code)
  • Android SDK Command‑line Tools (no Android Studio!)
  • AVD Manager extension (for emulator management)
  • Kotlin (for app development)

Let’s get started!


📑 Table of Contents

  • 📋 Prerequisites
    1. Install Visual Studio Code (VS Code) 📝
    1. Set Up the Android SDK with Command‑line Tools Only 📦
    • A. Download the Command‑line Tools
    • B. Extract and Configure the SDK
    • C. Install Essential SDK Packages Using sdkmanager
    1. Install and Configure the AVD Manager Extension in VS Code 🖥️
    1. Install Kotlin and Set Up Kotlin in VS Code 💻
    • A. Download and Install the Kotlin Compiler
    • B. Install Kotlin VS Code Extensions
    1. Create and Run Your First Android App Project with Kotlin 📱
    • A. Project Structure Overview
    • B. Create the Gradle Build Files
    • C. Create Android App Files
    • D. Installing Gradle Temporarily
    • E. Generate the Gradle Wrapper
    • F. Build and Run Your App
    1. Frequently Asked Questions (FAQs) ❓
    1. Final Thoughts 🎉

📋 Prerequisites

Before we begin, ensure you have the following:

  • A computer running Windows, macOS, or Linux.
  • A reliable internet connection.
  • Java JDK 11+ installed (the JDK is required by the Android SDK and Kotlin).
  • Patience & curiosity! 😊

Note: All tools used here are free and open source.


1. Install Visual Studio Code (VS Code) 📝

  1. Download VS Code:

  2. Install VS Code:

    • Run the installer and follow on‑screen instructions.
    • Launch VS Code once installation is complete.
  3. Set Up a Workspace:

    • Create a new folder (e.g., MyAndroidApp) on your computer.
    • Open VS Code and use File > Open Folder… to select your new workspace folder.

2. Set Up the Android SDK with Command‑line Tools Only 📦

Since we’re not using Android Studio, we must download and configure the Android SDK manually using command‑line tools.

A. Download the Command‑line Tools

  1. Visit the Android Studio Download Page:

  2. Download “Command‑line Tools Only”:

    • Choose the package for your operating system (Windows/macOS/Linux).

B. Extract and Configure the SDK

  1. Extract the Tools:

    • Unzip the downloaded archive.
    • For example, on Windows, extract to:
      C:\android\sdk\
    • On macOS/Linux, extract to a folder such as:
      ~/android-sdk/
  2. Set Up Environment Variables:

    Windows:

    • Open the Environment Variables settings (Search for “Environment Variables” in the Start Menu).

    • Add a new system variable:

      • Variable Name: ANDROID_SDK_ROOT
      • Variable Value: C:\android\sdk\ (or your chosen directory)
    • Edit the Path variable and add:

      • C:\android\sdk\cmdline-tools\latest\bin
      • C:\android\sdk\platform-tools
      • C:\android\sdk\emulator

      Tip: If needed, create a folder named latest inside cmdline-tools and move the extracted contents there.

    macOS/Linux:

    • Open your terminal and edit your shell configuration file (e.g., ~/.bashrc, ~/.zshrc):
      export ANDROID_SDK_ROOT=~/android-sdk
      export PATH=$PATH:$ANDROID_SDK_ROOT/cmdline-tools/latest/bin
      export PATH=$PATH:$ANDROID_SDK_ROOT/emulator
      export PATH=$PATH:$ANDROID_SDK_ROOT/platform-tools
      
    • Save the file and run source ~/.bashrc (or equivalent) to apply the changes.

C. Install Essential SDK Packages Using sdkmanager

Now that your environment variable is set, use the sdkmanager (found in the cmdline-tools bin folder) to install required components:

  1. Open a terminal (or VS Code’s integrated terminal).

  2. Accept Licenses (if prompted):

    sdkmanager --licenses
    
  3. Install Core Packages:

    sdkmanager "platform-tools" "platforms;android-33" "build-tools;33.0.0" "emulator" "system-images;android-33;default;x86_64"
    

    Tip: Replace android-33 and 33.0.0 with the API level and build-tools version you need.


3. Install and Configure the AVD Manager Extension in VS Code 🖥️

The AVD Manager extension lets you manage virtual devices and start the emulator without Android Studio.

  1. Open VS Code.

  2. Access Extensions:

    • Click the Extensions icon in the Activity Bar (or press Ctrl+Shift+X).
  3. Search for “AVD Manager by Toroxx”:

    • Install the extension.
  4. Configure the Extension:

    • After installation, open Settings in VS Code.
    • Locate the AVD Manager extension settings.
    • Set the Android SDK Path to the folder you configured earlier (e.g., C:\android\sdk or ~/android-sdk).
  5. Launch a Virtual Device:

    • Use the Command Palette (Ctrl+Shift+P or Cmd+Shift+P on macOS).
    • Type “AVD Manager: Create AVD” and follow the prompts:
      • Select a device definition (e.g., Pixel 3).
      • Choose the system image you installed (e.g., API Level 33, default, x86_64).
      • Save the configuration.
    • Once created, you can also launch the emulator directly from the extension.

4. Install Kotlin and Set Up Kotlin in VS Code 💻

A. Download and Install the Kotlin Compiler

  1. Download the Kotlin Compiler:

  2. Extract the Kotlin Compiler:

    • Unzip the archive to a folder on your computer (e.g., C:\kotlin\ on Windows or ~/kotlin/ on macOS/Linux).
  3. Add Kotlin to PATH:

    Windows:

    • Edit your system Path environment variable to include:
      C:\kotlin\bin

    macOS/Linux:

    • In your shell configuration file, add:
      export PATH=$PATH:~/kotlin/bin
      
    • Save and source the file (e.g., source ~/.bashrc).
  4. Verify Installation:

    • Open a terminal and run:
      kotlinc -version
      
      You should see the Kotlin compiler version information.

B. Install Kotlin VS Code Extensions

  1. Open VS Code.

  2. Open Extensions:

    • Press Ctrl+Shift+X.
  3. Search and Install “Kotlin Language” by Mathias Fröhlich:

    • This extension provides syntax highlighting, basic IntelliSense, and code snippets for Kotlin.
    • Click Install.
  4. (Optional) For better code execution, install the “Code Runner” extension:

    • Search for “Code Runner” in the Extensions view.
    • Click Install.

5. Create and Run Your First Android App Project with Kotlin 📱

In this section, we’ll create a simple project that demonstrates building and running an Android app using only command‑line tools and VS Code.

A. Project Structure Overview

Your basic Android app project should include:

MyAndroidApp/
├── app/
│   ├── build.gradle
│   ├── src/
│   │   └── main/
│   │       ├── AndroidManifest.xml
│   │       ├── java/
│   │       │   └── com/example/myandroidapp/
│   │       │       └── MainActivity.kt
│   │       └── res/
│   │           └── layout/
│   │               └── activity_main.xml
├── build.gradle
├── gradle.properties
└── settings.gradle

Note: We use Gradle for building and packaging the app. All commands below use the command‑line.

B. Create the Gradle Build Files

  1. settings.gradle:
    Create a file named settings.gradle in your project’s root folder with:

    include ':app'
    
  2. build.gradle (Project-Level):
    Create a file named build.gradle with the following basic content:

    buildscript {
        repositories {
            google()
            mavenCentral()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:7.4.0'
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10"
        }
    }
    
    allprojects {
        repositories {
            google()
            mavenCentral()
        }
    }
    
  3. App-level build.gradle:
    Inside the app/ folder, create a build.gradle:

    apply plugin: 'com.android.application'
    apply plugin: 'kotlin-android'
    
    android {
        namespace "com.example.myandroidapp"
        compileSdkVersion 33
        defaultConfig {
            applicationId "com.example.myandroidapp"
            minSdkVersion 21
            targetSdkVersion 33
            versionCode 1
            versionName "1.0"
        }
        buildTypes {
            release {
                minifyEnabled false
            }
        }
    }
    
    dependencies {
        implementation "org.jetbrains.kotlin:kotlin-stdlib:1.7.10"
        implementation 'androidx.core:core-ktx:1.9.0'
        implementation 'androidx.appcompat:appcompat:1.5.1'
        implementation 'com.google.android.material:material:1.7.0'
        implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    }
    
  4. gradle.properties:
    Create a file named gradle.properties in your project’s root folder with:

    android.useAndroidX=true
    android.enableJetifier=true
    

C. Create Android App Files

  1. AndroidManifest.xml:
    In the folder app/src/main/, create an AndroidManifest.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android">
        <application
            android:allowBackup="true"
            android:label="MyAndroidApp"
            android:theme="@style/Theme.AppCompat.Light.NoActionBar">
            <activity android:name=".MainActivity" android:exported="true">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>
    </manifest>
    
  2. MainActivity.kt:
    In app/src/main/java/com/example/myandroidapp/, create MainActivity.kt:

    package com.example.myandroidapp
    
    import android.os.Bundle
    import androidx.appcompat.app.AppCompatActivity
    import android.widget.TextView
    
    class MainActivity : AppCompatActivity() {
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            // Set the user interface layout for this Activity
            setContentView(R.layout.activity_main)
            
            // Initialize a TextView and set a message
            val textView: TextView = findViewById(R.id.textView)
            textView.text = "Hello, Android with Kotlin and VS Code! 🚀"
        }
    }
    
  3. activity_main.xml:
    In the folder app/src/main/res/layout/, create activity_main.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        
        <TextView
            android:id="@+id/textView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Welcome!"
            android:textSize="24sp"
            android:layout_centerInParent="true" />
    </RelativeLayout>
    

D. Installing Gradle Temporarily

Even though you don’t need a permanent global Gradle installation (since the Gradle wrapper makes your project self‑contained), you’ll need to install Gradle temporarily to generate the wrapper files if they are not already present.

Windows:

  • Manually:
    1. Download the latest Gradle binary-only distribution from https://gradle.org/releases/.
    2. Unzip it to a directory (e.g., C:\gradle\gradle-7.x).
    3. Add the bin folder (e.g., C:\gradle\gradle-7.x\bin) to your PATH environment variable.

macOS:

  • Using Homebrew:
    brew install gradle
    
  • Or SDKMAN!:
    sdk install gradle
    

Linux:

  • Using SDKMAN!:
    sdk install gradle
    
  • Or your package manager:
    sudo apt-get install gradle
    

E. Generate the Gradle Wrapper

  1. Open a terminal in your project’s root folder (the folder where your project’s settings.gradle and other files reside).
  2. Run the following command:
    gradle wrapper
    
    This command creates the following essential files:
    • gradlew (for Unix‑like systems)
    • gradlew.bat (for Windows)
    • The directory gradle/wrapper (which contains wrapper JAR and properties files)
  • After generating the wrapper, you can remove or ignore the temporary Gradle installation if desired.

F. Build and Run Your App

  1. Build the App:

    • Open a terminal in your project’s root folder.
    • Run the Gradle wrapper to build the APK:
      ./gradlew assembleDebug
      
    • On Windows, you might run:
      gradlew.bat assembleDebug
      
  2. Launch the Emulator:

    • List Available AVDs:
      emulator -list-avds
      
    • Start an Emulator:
      emulator -avd Your_AVD_Name
      
      Alternatively, use the AVD Manager extension in VS Code to launch your created device.
  3. Install the APK on the Emulator:

    • Once the emulator is running, install the APK using adb:
      adb install -r app/build/outputs/apk/debug/app-debug.apk
      
  4. Run Your App:

    • After installation, the app should automatically launch, displaying your “Hello, Android with Kotlin and VS Code! 🚀” message.

6. Frequently Asked Questions (FAQs) ❓

Q: Do I need Android Studio?
A: No. This guide uses only command‑line tools and the AVD Manager extension in VS Code.

Q: What if I encounter errors with the SDK tools?
A: Ensure your environment variables (e.g., ANDROID_SDK_ROOT and PATH entries) are set correctly. Run sdkmanager --licenses and accept all licenses.

Q: How do I update the SDK packages?
A: Use:

sdkmanager --update

Q: Can I develop fully in Kotlin with VS Code?
A: Yes! With the Kotlin compiler and Kotlin VS Code extensions, you have full support for writing, compiling, and debugging Kotlin code.


7. Final Thoughts 🎉

Congratulations! You now have a fully configured Android app development environment that uses only:

  • VS Code as your editor,
  • Command‑line tools for managing the Android SDK,
  • The AVD Manager extension to create and launch emulators, and
  • Kotlin for app development.

This setup is ideal if you’re looking for a lightweight, resource‑efficient way to start Android development without relying on Android Studio. Enjoy coding your next Android app entirely from the command line and VS Code!

If you have any questions or run into issues, feel free to refer back to the FAQ section or search for similar topics in online forums. Happy coding! 🚀

#android#kotlin#vs code#Android SDK Command‑line Tools#AVD Manager