2. SETTING UP DEVELOPMENT ENVIRONMENTS FOR ANDROID AND IOS

SETTING UP DEVELOPMENT ENVIRONMENTS FOR ANDROID

Setting Up Development Environments for Android

Introduction

Android development requires a properly configured environment to build, test, and debug apps. This guide covers setting up tools like Android Studio, SDK, emulators, and essential configurations for Windows, macOS, and Linux.

Prerequisites

Hardware

  - 64-bit OS (Windows 8+, macOS 10.14+, or Linux).

  - 8 GB RAM (16 GB recommended).

  - 4 GB disk space (SSD preferred).

Software:

  - Java (OpenJDK bundled with Android Studio).

  - Internet connection for downloads.

Installing Android Studio

Download: Get the installer from (developer.android.com/studio](https://developer.android.com/studio).


Install

   - Windows: Run `.exe`, follow prompts, select Android SDK and Emulator.

   - macOS: Drag to Applications, configure SDK path.

   - Linux: Unzip, run `./studio.sh`, and configure.

First Launch: Choose a theme (Light/Dark) and install SDK components.

Configuring Android SDK

- SDK Manager: Open via `Tools > SDK Manager`.

  - Install SDK Platforms (latest stable API).

  - Add SDK Tools:

    - Android Emulator.

    - Android SDK Build-Tools.

    - Intel HAXM or Hyper-V (Windows Pro).

    - Google Play Services (if needed).

Environment Variables (optional):

  - Set `ANDROID_HOME` to SDK path (e.g., `~/Android/Sdk` on Linux).

Setting Up the Android Emulator (AVD)

1. AVD Manager: Open via `Tools > AVD Manager`.

2. Create Virtual Device:

   - Select hardware profile (e.g., Pixel 6).

   - Choose system image (e.g., Android 13 "Tiramisu" with Google APIs).

   - Configure RAM (4 GB), storage (16 GB), and enable Hardware Acceleration.

Performance Tips:

   - Use Quickboot Snapshots.

   - Enable Vulkan for graphics (optional).

   - Install HAXM (Windows/macOS) or KVM (Linux).

Connecting a Physical Device

1. Enable Developer Options:

   - Tap `Build Number` 7 times in `Settings > About Phone`.

2. USB Debugging:

   - Enable `Developer Options > USB Debugging`.

3. Drivers (Windows):

   - Install OEM drivers (Samsung, Google, etc.).

4. Authorize Device: Allow connection via USB prompt.

 Exploring Project Structure

- Key Directories:

  - `app/src/main/java`: Java/Kotlin code.

  - `app/src/main/res`: Resources (layouts, strings, images).

  - `app/build.gradle`: Module-level dependencies.

  - `AndroidManifest.xml`: App metadata.

Build Tools: Gradle

- Configure Dependencies: Edit `build.gradle` files.

  - Add libraries (e.g., `implementation 'com. google.android.material:material:1.6.0'`).

- Sync Project: Click "Sync Now" in Android Studio.

Version Control with Git

1. Initialize Repo: `git init` in project root.

2. gitignore: Exclude `build/`, `.gradle/`, and local configs.

3. Integrate with Android Studio: Use `VCS > Enable Version Control`.

Additional Tools

-Firebase: Add via `Tools > Firebase`.

-Profiler: Monitor CPU, memory, and network usage.

-Third-Party Libraries: Use Jetpack Compose, Retrofit, or Glide via Gradle.

Testing Your Setup

1. Create New Project: Select "Empty Activity".

2. Run the App: Click ▶️ (target emulator/device).

3. Hello World: Verify app launches with "Hello, Android!".

Troubleshooting (INCASE ERROR)

- Emulator Issues:

  - Enable virtualization in BIOS/UEFI.

  - Reinstall HAXM/KVM.

- SDK Licenses: Run `sdkmanager --licenses` in terminal.

- Gradle Errors: Disable offline mode (`File > Settings > Build > Gradle`).

- USB Connection: Revoke debugging authorizations and reconnect.

Best Practices

- Update Regularly: SDK, plugins, and Android Studio.

- Use Emulator Snapshots for faster testing.

- Backup Projects with Git or cloud storage