Develop Android Home API App using Home API Knowledge Base and Gemini

1. Before you begin

What you'll build

In this codelab, you will extend an existing Android Home API sample app by using Home API Knowledge Base and Gemini in Android Studio to automate UI creation and API integration. You will add a debug interface that lets users dump logs and summarize their Home for debugging and development.

The Power Duo: Home API Knowledge Base + Gemini in Android Studio

This workflow relies on two critical components:

  • Home API Knowledge Base: A curated documentation file (google-home-api-knowledge-base.txt) that provides Gemini with the specific technical constraints, models, and methods required to interact with Google Home devices.
  • See: https://developers.home.google.com/apis/android/knowledge-base
  • Gemini in Android Studio: An AI-powered collaborator that lives directly within your IDE. It is context-aware of your code, resources, and terminal.

What you'll learn

  • How to provide the Home API Knowledge Base as context to Gemini in Android Studio.
  • How to vibe-code with Gemini in Android Studio to add new functionality to existing Home API Sample App.

2. Prerequisites & Setup

Make sure the following has been completed before continuing:

  • Build and Run Home APIs Android Sample APP: Follow the instructions at https://developers.home.google.com/apis/android/sample-app/build#build_the_app to build and run the sample app that our codelab is based on.
  • Environment Setup
  • Download Android Studio: Install the latest stable version (Koala or newer) from the official developer site.
  • Enable Gemini: Open the Gemini tool window (usually on the right-side strip). Sign in with your Google Account and accept the terms to activate the AI assistant. See https://developer.android.com/studio/gemini/get-started for instructions.
  • Knowledge Base File: Ensure you have the file google-home-api-knowledge-base.txt saved in your project directory.
  • Note: If you cloned the Sample App from the official GitHub sample app, this file is already included in the tools/ folder.

3. Create the AGENTS.md file

Instead of repeating instructions in every chat, create a persistent "brain" for Gemini.

In your project root, create a new file named AGENTS.md and paste the following context:

**Role:** You are an expert Android Home API Developer.

**Context:** This project uses the Google Home APIs.

**Source of Truth:** Always reference tools/google-home-api-knowledge-base.txt for Home API patterns, data models (Structures, Automations), and debugging methods.

**Guidelines:** Prioritize Material 3 Compose components and ensure all code is compatible with the latest Home API SDK.

In "Context", Select the checkbox next to AGENTS.md Files.

Android Studio Gemini Context settings showing AGENTS.md Files selected

Verify that the setup is successful. Prompt Gemini with:

Can you see the Agents.md file? Do you know what file you need to check first before developing with Google Home API?

You should see a similar result to the following screenshot, mentioning that Gemini is reading AGENTS.md and will use the Knowledge Base file!

Gemini in Android Studio confirming it read AGENTS.md and the Knowledge Base

4. Create a new Debug tab

Use Gemini + Knowledge Base to modify HomeAppView.kt and add a new navigation destination.

Before you begin, this is what your current Home APIs sample app should look like:

Home APIs Android sample app showing Devices and Automations tabs

Prompt Gemini to use a wheel icon to represent the new debug tab.

Can you help to add a wheel icon as the third tab in the HomeAppView .

The following screenshot shows a potential prompt-and-response dialogue with Gemini in Android Studio:

Gemini in Android Studio generating code to add a Debug tab

Now we can see a new "Debug" tab at the bottom:

Sample app bottom navigation bar showing the new Debug tab

5. Create 2 new buttons for "Dump Structure"and "Dump Automation"

Prompt Gemini:

Create two selectable buttons on the Debug page called "Dump Structure" and "Dump Automations".

Now we have 2 new buttons added on the Debug page:

Debug page showing Dump Structure and Dump Automations buttons

6. Implement the "Dump Structure" functionality

Prompt Gemini:

Implement the first button "Dump Structure" to call dumpStructure(structure: Structure) in Debugger.kt with current selected structure.

When you click the "Dump Structure" button, Structure logs are dumped to Logcat:

Android Studio Logcat displaying dumped structure logs

7. Implement the "Dump Automation" functionality

Prompt Gemini:

Now Implement the "Dump Automation" functionality to call dumpAutomationsInStructure(structure: Structure) in Debugger.kt with current selected structure.

When you click the "Dump Automation" button, Automation logs are dumped to Logcat:

Android Studio Logcat displaying dumped automation logs

8. Implement a "Summarize Home" button that lists the current Rooms and Devices

Prompt Gemini:

In Debug tab, add a button "Summarize Home" to find the current room and devices with Home API and show them on a dialog.

A new "Summarize Home" button appears on the Debug page:

Debug page showing the new Summarize Home button

And when you click it, a current summary of rooms and devices is displayed:

Summarize Home dialog listing current rooms and devices

9. Review the Changes

Gemini can also help to review the changes (or last git commit), find the potential issues, and fix that.

Prompt Gemini:

Review the uncommitted changes and find potential issues.

Gemini in Android Studio reviewing uncommitted code changes

10. Congratulations!

Congratulations! You successfully extended your Android Home API sample app by using the Home API Knowledge Base and Gemini to automate UI creation and API integration! Now that you know how to extend the sample app using AI-driven development, here are some other things you can try: