Fixing .NET MAUI Android: Why VS Code + Android Studio Setup Matters

πŸ”₯ Running a .NET MAUI Android app from VS Code mostly worksβ€”until it doesn't. If you've ever faced rage-inducing errors like:

🚨 Android SDK directory could not be found...
πŸ’₯ Building with JDK version 23.0.1 is not supported...
πŸ“΅ No available device.

...then you know the pain. This guide is your escape hatchβ€”we'll walk through exactly what to install and why each step matters.


πŸ›  STEP 1: Install Android Studio (Your New Best Friend)

Why this matters πŸ’‘:
Android Studio isn't just an IDEβ€”it's your golden ticket to:

  • πŸ“¦ Android SDK (platforms, build tools, command-line tools)

  • πŸ“± Android Virtual Device (a lifelike emulator)

πŸš€ Get it here: Download Android Studio

πŸ” What to install:

ComponentWhat You Need
SDK PlatformsAndroid 14 (API 34) + Android 15 (API 35)
SDK ToolsBuild-Tools, Platform-Tools, Emulator

πŸ’‘ Pro Tip: This setup gives VS Code the Android muscle it lacks out of the box.Step 2: Install Java 21 (Not Java 23!)

β˜• STEP 2: Install Java 21 (Not Java 23!)

🚨 Critical Warning: .NET MAUI on Windows only plays nice with:

  • Java 17 βœ…

  • Java 21 βœ…
    It will rebel against newer JDKs! ❌

One-Command Magic ✨:

winget install --id EclipseAdoptium.Temurin.21.JDK -e

What happens if you ignore this?
You'll face the dreaded error:

πŸ’₯ Building with JDK version '23.0.1' is not supported. Please install JDK version '21.0'


πŸ€” Why Does a C# Project Need Java? A Quick History Lesson

You might wonder: "Why does .NET MAUI, a C# framework, need Java for Android development?" Here's the fascinating backstory:

1. Android's Java Roots (2008)

When Android was created, Java was chosen as its primary language because:

  • β˜• Ubiquity: Java was already widely adopted

  • πŸ—οΈ Portability: "Write once, run anywhere" philosophy

  • πŸ”’ Google's Decision: Oracle's Java was the industry standard

2. Xamarin Enters (2011)

Microsoft's Xamarin (which evolved into MAUI) needed to:

  • 🀝 Interoperate with Android's Java-based toolchain

  • βš™οΈ Use Android SDKs (written in Java)

  • πŸ› οΈ Compile to JVM bytecode for Android compatibility

3. The Build Process Quirk

.NET MAUI apps for Android still require:

  • 🧩 Java tooling for:

    • javac (Java compiler)

    • dx/D8 (Dalvik bytecode conversion)

    • aapt (Android asset packaging)

  • πŸ”„ Intermediate translation from .NET IL β†’ Java bytecode β†’ Android ART

4. Modern Dependencies

Even in 2024, you need Java because:

  • πŸ“¦ Android SDK tools are Java-based

  • πŸ”— .NET's Android bindings rely on Java Native Interface (JNI)

  • ⏳ Backward compatibility with millions of Java-based Android libraries


πŸ’‘ Key Takeaway

While you write C#, the Android build chain still speaks Java under the hood. This hybrid approach gives you:

  • C#'s productivity ✨

  • Access to Java's Android ecosystem πŸ“±

  • Performance close to native πŸ”₯

Fun Fact: This is why Flutter (Dart) and React Native (JavaScript) also need Java for Android builds!


βš™οΈ STEP 3: Configure Environment Variables (The Secret Sauce)

For Java:

[Environment]::SetEnvironmentVariable("JAVA_HOME", 
  "C:\Program Files\Eclipse Adoptium\jdk-21.0.7.6-hotspot", 
  "User")

[Environment]::SetEnvironmentVariable("Path", 
  "$([Environment]::GetEnvironmentVariable('Path','User'));%JAVA_HOME%\bin", 
  "User")

For Android:

[Environment]::SetEnvironmentVariable("ANDROID_SDK_ROOT", 
  "C:\Users\kelvi\AppData\Local\Android\sdk", 
  "User")

[Environment]::SetEnvironmentVariable("ANDROID_HOME", 
  "C:\Users\kelvi\AppData\Local\Android\sdk", 
  "User")

[Environment]::SetEnvironmentVariable("Path", 
  "$([Environment]::GetEnvironmentVariable('Path','User'));%ANDROID_SDK_ROOT%\platform-tools;%ANDROID_SDK_ROOT%\emulator", 
  "User")

Why this matters πŸ”:
These variables are like GPS coordinates for your tools. Without them:

  • You'll waste time typing full paths πŸ•’

  • Commands become ridiculously long πŸ“

  • Your sanity will slowly evaporate πŸ˜΅β€πŸ’«


πŸ“± STEP 4: Create Your Android Virtual Device (The Magic Phone)

Follow these steps πŸ‘‡:

  1. Open Android Studio

  2. Navigate to:
    Tools β†’ Device Manager (or click the πŸ“± phone icon)

  3. Click Create Device

  4. Choose: Pixel 5 (or your preferred model)

  5. Select: Android 34/35 system image (download if needed)

  6. Launch: Hit the ▢️ play button!

Why this is crucial ❗:
Your dotnet build -t:Run command needs a device target. No emulator?
You'll get:

❌ error XA0010: No available device.


πŸš€ STEP 5: Build & Deploy from VS Code (The Grand Finale)

Run this command in your project folder:

powershell

Copy

Download

dotnet build -t:Run -f net9.0-android `
  -p:AndroidSdkDirectory="C:\Users\kelvi\AppData\Local\Android\sdk" `
  -p:JavaSdkDirectory="C:\Program Files\Eclipse Adoptium\jdk-21.0.7.6-hotspot"

What happens πŸ”:
βœ”οΈ Builds your MAUI app for Android
βœ”οΈ Uses your configured SDKs/JDK
βœ”οΈ Auto-detects your running emulator
βœ”οΈ Installs and launches your app


🌟 Why This Setup Rocks

ComponentBenefit
Android StudioInstalls SDK + emulator in one go
Java 21Guarantees MAUI compatibility
Env VariablesEliminates repetitive path typing
EmulatorProvides instant testing environment
VS Code BuildOne-command deployment

🎁 Bonus Pro Tip

Automate this with .vscode/tasks.json for one-click builds (Ctrl+Shift+B)!
Want the config? Let us know in comments! πŸ’¬


πŸ“ TL;DR Cheat Sheet

  1. πŸ“₯ Install Android Studio (gets SDK + emulator)

  2. β˜• Get Java 21 via winget

  3. βš™οΈ Set environment variables

  4. πŸ“± Create Android emulator

  5. πŸ—οΈ Run dotnet build -t:Run

You're now MAUI-ready in VS Code! πŸŽ‰
Faster, cleaner, and no more SDK errors!

0
Subscribe to my newsletter

Read articles from Kelvin R. Tobias directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Kelvin R. Tobias
Kelvin R. Tobias