Android new module

From Floorp-Projects/Floorp-Runtime · View interactive version

Android new module is an AI agent skill from the GitHub repository Floorp-Projects/Floorp-Runtime. Guide for creating new Android gradle modules in the android-components project.

How to use this skill

Skill file

Creating a new Android module

Overview

This skill helps you create new Android gradle modules following Mozilla's conventions and structure. Components are organized into categories: browser, concept, feature, lib, service, support, ui, and compose.

Component Categories

Steps to Create a New Component

Create a plan to execute the steps. The plan should include all nine steps below.

1. Determine Component Type and Name

Ask the user:

2. Create Directory Structure

mkdir -p mobile/android/android-components/components/{category}/{name}/src/main/java/mozilla/components/{category}/{name}
mkdir -p mobile/android/android-components/components/{category}/{name}/src/test/java/mozilla/components/{category}/{name}
mkdir -p mobile/android/android-components/components/{category}/{name}/src/test/resources

3. Create build.gradle

Reference the example at mobile/android/android-components/components/feature/example/build.gradle for the standard structure.

Key elements:

Add dependencies as needed:

4. Create AndroidManifest.xml

File: src/main/AndroidManifest.xml

<!-- This Source Code Form is subject to the terms of the Mozilla Public
   - License, v. 2.0. If a copy of the MPL was not distributed with this
   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<manifest />

5. (Optional) Create Main Kotlin Source

File: src/main/java/mozilla/components/{category}/{name}/{ComponentName}.kt

Reference the example at mobile/android/android-components/components/feature/example/src/main/java/mozilla/components/feature/example/ExampleFeature.kt.

Key elements for a feature component:

For simpler library components, a basic class with the necessary methods is sufficient.

6. (Optional) Create Test File

File: src/test/java/mozilla/components/{category}/{name}/{ComponentName}Test.kt

Reference the example at mobile/android/android-components/components/feature/example/src/test/java/mozilla/components/feature/example/ExampleFeatureTest.kt.

Key elements:

7. Create Robolectric Configuration

File: src/test/resources/robolectric.properties

sdk=35

This configures Robolectric to use Android SDK 35 for unit tests.

8. Create README.md

File: README.md

Reference the example at mobile/android/android-components/components/feature/example/README.md.

Key elements:

9. Register in .buildconfig.yml

Add the component to .buildconfig.yml in alphabetical order within its category:

  components:{category}-{name}:
    description: {Brief description}
    path: components/{category}/{name}
    publish: true

Find the correct insertion point by searching for the category (e.g., components:feature- for feature modules) and inserting in alphabetical order.

Then update the upstream_dependencies for the new buildconfig with this mach command:

./mach android update-buildconfig android-components

Also update taskcluster/config.yml to add the new module's display name to treeherder.group-names. Without this step, CI will fail with a buildconfig mismatch error.

Common Patterns

Package Naming

Class Naming

Dependency Types

Code Style

Verification

After creating the component, verify it builds with the debug variant:

./mach gradle :components:{category}-{name}:buildDebug

Run tests:

./mach gradle :components:{category}-{name}:testDebug

Format and lint:

./mach lint --fix mobile/android/android-components/components/{category}/{name}

Notes

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.