Android
Tech principles
To inform decision-making when writing and reviewing code use the principles documented in: mobile/android/fenix/docs/Tech-Principles.md
Workflow
- Instead of
gradlew, use./mach gradleas the wrapper. Use-pargument of gradle if you need to run in a subdirectory - Instead of an
androidbinary fromPATH, use./mach android cli <args>. It runs theandroidlauncher from the Android SDK that the build uses, against that SDK. - Use
./mach android cli -- --helpfor the CLI's own help, because mach handleshelp,--helpand-hthat come before--. - Don't run
./mach android cli init. It installs files into agent skill directories. - Start emulators with
./mach android-emulator../mach android cli emulatordoes not list the AVDs that./mach bootstrapinstalled.
Android Frontend
When working in mobile/android/fenix, mobile/android/focus-android or mobile/android/android-components directories override instructions from the top-level AGENTS.md with:
./mach lintis the recommended way to run linters and format code all in one go.- It is currently too slow to run in fast feedback loops. Run it only at the end of implementing a change (or a major piece of a bigger change), like when checking if it's ready to submit a patch.
- In case you need a faster feedback loop, you can run a subset of fast linters with
./mach gradle ktfmtFormat detekt. It is not equivalent to./mach lintand doesn't guarantee patch submission readiness. - Default to running code formatting as part of
./mach lintor with./mach gradle ktfmtFormat. Don't run./mach formatin fenix/focus-android/android-components, because it skips android formatters. - Run
./mach buildonly when new changes are pulled into the work tree, or if./mach gradle ...commands do not succeed. - Run
./mach gradle [fenix|focus|components:<component>]:assembleDebugwhen you want to verify subsequent Android frontend code changes. - Don't run
./mach testwith--auto, it doesn't work on Android frontend code changes. Instead, run it for a file/feature you're working on with: ./mach test <file-name>to run all tests in the file./mach test <directory-name>to run all tests in the directory./mach test {fenix,focus,ac,android-components,geckoview}to run all tests in the specific project- When adding the first Robolectric test (
@RunWith(AndroidJUnit4::class)) to an android-components module: - Add
testImplementation libs.robolectricto itsbuild.gradle - Add
src/test/resources/robolectric.propertieswithsdk=37. CI fetches the Robolectric jars only for modules with this file, so don't add it to modules without Robolectric tests.