Guide for creating new Android gradle modules in the android-components project.
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.
Create a plan to execute the steps. The plan should include all nine steps below.
Ask the user:
my-component)publish: true, examples are publish: false)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
Reference the example at mobile/android/android-components/components/feature/example/build.gradle for the standard structure.
Key elements:
com.android.library and kotlin-androidmozilla.components.{category}.{name}androidx.core.ktx, kotlinx.coroutinesjunit.bom, junit4, robolectric, kotlinx.coroutines.testAdd dependencies as needed:
implementation project(':components:support-base')libs.androidx.lifecycle.runtimeplatform(libs.androidx.compose.bom) and compose dependenciesimplementation project(':components:lib-state')implementation project(':components:browser-state')implementation project(':components:{category}:{component-name}')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 />
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:
mozilla.components.{category}.{name}LifecycleAwareFeature for lifecycle-aware featuresCoroutineDispatcher)start(), stop())For simpler library components, a basic class with the necessary methods is sufficient.
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:
StandardTestDispatcher from kotlinx.coroutines.test for testing coroutinesrunTest(testDispatcher) to run tests with coroutine supporttestDispatcher.scheduler.advanceUntilIdle() to advance virtual time`start triggers onUpdate callback`)File: src/test/resources/robolectric.properties
sdk=35
This configures Robolectric to use Android SDK 35 for unit tests.
File: README.md
Reference the example at mobile/android/android-components/components/feature/example/README.md.
Key elements:
# [android-components](../../../README.md) > {Category} > {Name}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.
mozilla.components.{category}.{name}mozilla.components.feature.examplemy-component → MyComponentapi - For interfaces and contracts (concept modules)implementation - For internal dependenciestestImplementation - For testing dependenciesandroidTestImplementation - For instrumented tests@VisibleForTesting for test-only visibilityAfter 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}
./mach gradle instead of gradlew to ensure the build system is executed in its entirety.publish: false for example/sample components because we do not want them to be distributed through the maven mirrors..buildconfig.yml.