Android · DevOps
Android Project Docs with MkDocs, Dokka, and Firebase Hosting
Most Android projects ship with no documentation. Build a complete setup, MkDocs Material for the site, Dokka for API reference, Firebase Hosting for deployment, and a GitHub Actions pipeline that ships on every PR.
- Published
- Reading
- 8 min
- Author
- Fidelis Uwem Joseph
Series · Part 5 of 5Android Foundations
- Three Retrofit Clients in One Android App with Hilt Qualifiers
- Encrypted Token Storage on Android with EncryptedSharedPreferences and Hilt
- Seeding a Room Database via ADB BroadcastReceiver in Kotlin
- Printing Labels from Android Using the Brother QL SDK
- Android Project Docs with MkDocs, Dokka, and Firebase Hosting
Most Android projects ship without documentation. The few that have it rely on a Confluence page that is out of date by the time it is merged. This post covers the setup used in Unizonn Mobile v2: MkDocs Material for the documentation site, Dokka for generated API reference, Firebase Hosting for deployment, and a single GitHub Actions workflow that builds and ships everything on every PR targeting main or staging. The result is a live URL that reviewers can open from a pull request without cloning anything.
Prerequisites
- Python 3.12
- JDK 17
- Android project with the Gradle version catalog (
libs.versions.toml) - Firebase project with a service account holding the
Firebase Hosting Adminrole
Background
Dokka generates HTML from KDoc comments. MkDocs Material turns Markdown into a polished site. Firebase Hosting serves static assets from a CDN with a free tier sufficient for project documentation. The missing piece is glue: a Gradle task that builds both into the same output directory, a firebase.json that points at it, and a workflow that runs without manual intervention.
Implementation
1. Register Dokka in the version catalog
[versions]dokka = "1.9.20"
[plugins]dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }Adding it to the version catalog keeps the version in one place and makes it available to every module.
2. Apply the plugin at root and module level
plugins { alias(libs.plugins.androidApplication) apply false alias(libs.plugins.jetbrainsKotlinAndroid) apply false alias(libs.plugins.dokka) apply false}
subprojects { apply(plugin = "org.jetbrains.dokka")}apply false at the root level prevents the plugin from generating tasks where it has nothing to document. The subprojects block registers dokkaHtml in every module. Running ./gradlew dokkaHtml from the root generates HTML under each module’s build/dokka/html/ directory.
3. Scaffold the MkDocs site
Create a documentation/ directory at the project root:
documentation/├── docs/│ ├── index.md│ ├── architecture.md│ ├── guidelines.md│ └── api.md├── mkdocs.yml└── generate_docs.shsite_name: Unizonn Mobile Documentationsite_dir: htmltheme: name: material language: en palette: - scheme: default toggle: icon: material/toggle-switch-off-outline name: Switch to dark mode primary: teal accent: purple - scheme: slate toggle: icon: material/toggle-switch name: Switch to light mode primary: teal accent: lime
nav: - Getting Started: index.md - Guidelines: guidelines.md - Architecture: architecture.md - API: api/index.html
plugins: - searchsite_dir: html resolves relative to mkdocs.yml, so output lands at documentation/html/. Firebase Hosting is configured to serve from that exact path. Both values must stay in sync.
4. Write the build script
#!/bin/bashset -ex
python3 -m venv venvsource venv/bin/activatepip3 install mkdocs-materialmkdocs buildset -ex fails the script immediately on any error and prints each command before running it. Without it, a failed pip install silently produces an empty html/ directory and the CI step exits zero with nothing deployed.
5. Register the buildDocs Gradle task
val buildDocs = tasks.register<Exec>("buildDocs") { workingDir = file("$rootDir/documentation") commandLine = listOf("./generate_docs.sh") doLast { project.exec { workingDir = project.rootDir commandLine = listOf("./gradlew", "dokkaHtml") } } }generate_docs.sh runs first, building the MkDocs site. The doLast block runs dokkaHtml after the script exits, writing the API reference into the already-built site. Running ./gradlew buildDocs locally should produce documentation/html/ with the full site and documentation/html/api/ with the Dokka output.
6. Configure Firebase Hosting
{ "hosting": { "public": "documentation/html", "ignore": [ "firebase.json", "**/.*", "**/node_modules/**" ] }}Run firebase init hosting once to generate .firebaserc with your project ID. Commit .firebaserc, not firebase-debug.log.
7. Write the GitHub Actions workflow
name: Build documentation
on: pull_request: branches: - main - staging
jobs: deploy_documentation: runs-on: ubuntu-latest
steps: - name: Checkout code uses: actions/checkout@v4
- name: Set up Python uses: actions/setup-python@v5 with: python-version: '3.12.3'
- name: Set up JDK 17 uses: actions/setup-java@v4 with: java-version: 17 distribution: 'temurin' cache: gradle
- name: Set up Gradle uses: gradle/actions/setup-gradle@v3
- name: Build documentation run: ./gradlew buildDocs
- name: Deploy to Firebase Hosting uses: FirebaseExtended/action-hosting-deploy@v0 with: firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT }}" projectId: "${{ vars.PROJECT_ID }}" channelId: live
- name: Notify Slack uses: act10ns/slack@v2.0.0 with: webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }} status: ${{ job.status }} message: "Unizonn Mobile Documentation is live at https://unizonn-******.app/"channelId: live deploys to the live channel on every PR. To get per-PR preview URLs instead, remove this line. The action will create a temporary channel and post the URL back to the PR as a comment.
8. Store the required credentials
In your repository under Settings, Secrets and variables, Actions:
| Name | Type | Value |
|---|---|---|
FIREBASE_SERVICE_ACCOUNT | Secret | Service account JSON |
SLACK_WEBHOOK_URL | Secret | Incoming webhook URL |
PROJECT_ID | Variable | Firebase project ID |
The service account needs the Firebase Hosting Admin IAM role. Create it in the GCP console under the Firebase project, download the JSON key, and paste the contents into the secret.
Testing and Verification
Run the full build locally before pushing:
./gradlew buildDocsExpected output:
> Task :buildDocs+ python3 -m venv venv+ source venv/bin/activate+ pip3 install mkdocs-material...INFO - Building documentation to directory: /path/to/documentation/htmlINFO - Documentation built in 2.34 seconds
> Task :app:dokkaHtml...BUILD SUCCESSFUL in 38sConfirm the output directory structure:
ls documentation/html/# index.html 404.html assets/ api/ ...If api/ is missing, dokkaHtml did not write to the expected location. Check that no DokkaTaskPartial.outputDirectory override is redirecting the output.
Pitfalls
Production Considerations
channelId: live means every PR deploy goes straight to the live URL. For teams where documentation changes go through review, switch to preview channels and add a separate workflow that promotes to live on merge to main.
generate_docs.sh reinstalls mkdocs-material on every run because it creates a fresh virtual environment each time. Pin the version with pip3 install mkdocs-material==9.5.x and cache the virtual environment using actions/cache keyed on a requirements.txt. This cuts the step from roughly 30 seconds to under 5.
If the project grows beyond a single module, replace dokkaHtml with dokkaHtmlMultiModule and configure each module’s DokkaTaskPartial with an outputDirectory that writes into documentation/html/api/. The Firebase config and workflow do not need to change.
Going deeper
Make the build order explicit
Two details in the buildDocs task are easy to miss and expensive to debug.
First, mkdocs build cleans its output directory before writing, which is the default --clean behaviour. If Dokka ever runs first, MkDocs deletes the API reference it just generated. The current task gets the order right by accident of doLast, and any refactor that changes the order breaks the site without an error.
Second, project.exec inside a task action is deprecated in recent Gradle versions and slated for removal. Gradle prefers tasks that declare what they depend on.
Split the work into two tasks with an explicit order and point Dokka’s output straight into the site:
val mkdocsBuild = tasks.register<Exec>("mkdocsBuild") { workingDir = file("$rootDir/documentation") commandLine("./generate_docs.sh")}
project(":app").tasks.named<org.jetbrains.dokka.gradle.DokkaTask>("dokkaHtml") { outputDirectory.set(rootDir.resolve("documentation/html/api")) mustRunAfter(mkdocsBuild) // mkdocs cleans html/, so Dokka must write afterwards}
tasks.register("buildDocs") { dependsOn(mkdocsBuild, ":app:dokkaHtml")}mustRunAfter only orders tasks that are already scheduled, so ./gradlew :app:dokkaHtml on its own still works for quick API previews.
Write KDoc that is worth reading
Dokka only renders what you write. A few additions make the generated reference feel like documentation rather than a list of signatures:
tasks.withType<org.jetbrains.dokka.gradle.AbstractDokkaLeafTask>().configureEach { dokkaSourceSets.configureEach { includes.from("Module.md") // module overview page reportUndocumented.set(true) // warn on public API without KDoc sourceLink { localDirectory.set(projectDir.resolve("src")) remoteUrl.set(uri("https://github.com/your-org/unizonn-mobile/tree/main/app/src").toURL()) remoteLineSuffix.set("#L") } perPackageOption { matchingRegex.set(""".*\.internal.*""") suppress.set(true) // keep internal packages out of the reference } }}Module.md must start with # Module app (the module name) followed by Markdown. Source links add a “source” link to every declaration that jumps to the exact line on GitHub, which is the feature readers use most.
Inside KDoc, @sample pulls a real, compiled function into the docs as a usage example. Because the sample is compiled with the rest of the code, it cannot silently go out of date:
/** * Formats an amount in minor units for display. * * @sample com.unizonn.samples.formatCurrencySample */fun formatCurrency(minor: Long, currency: Currency): StringTurn documentation into a quality gate
Documentation rots when nothing fails as it decays. Two flags make the build catch it:
tasks.named<org.jetbrains.dokka.gradle.DokkaTask>("dokkaHtml") { failOnWarning.set(true) // with reportUndocumented, missing KDoc fails the build}mkdocs build --strict # broken links and missing nav targets become errorsTurn on failOnWarning once the existing public API is documented. Enabling it on a large undocumented codebase just teaches the team to switch it off.
Preview on pull requests, publish on merge
With channelId: live, every pull request overwrites the public site, including pull requests that are never merged. Split the workflow in two:
on: pull_request: branches: [main]
permissions: contents: read pull-requests: write # lets the action comment the preview URL
jobs: preview: runs-on: ubuntu-latest steps: # checkout, Python, JDK and ./gradlew buildDocs as before - uses: FirebaseExtended/action-hosting-deploy@v0 with: repoToken: ${{ secrets.GITHUB_TOKEN }} firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT }} projectId: ${{ vars.PROJECT_ID }} expires: 7don: push: branches: [main]
jobs: publish: runs-on: ubuntu-latest steps: # same build steps - uses: FirebaseExtended/action-hosting-deploy@v0 with: firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT }} projectId: ${{ vars.PROJECT_ID }} channelId: liveReviewers get a temporary URL in the pull request, and the live site only changes when code reaches main.
Cache the Python toolchain
Reinstalling MkDocs Material on every run is slow and makes builds depend on whatever version PyPI serves that day. Pin the dependencies in a file and let setup-python cache them:
mkdocs-material==9.5.39- uses: actions/setup-python@v5 with: python-version: '3.12' cache: pip cache-dependency-path: documentation/requirements.txtThen change generate_docs.sh to pip3 install -r requirements.txt. Gradle caching is already handled by setup-java with cache: gradle.
Versioned docs that do not expire
The wrap-up suggests a preview channel per release. Preview channels are temporary: the longest expiry Firebase allows is 30 days, after which the channel and its URL are deleted. They suit pull requests, not permanent release documentation.
For docs that should stay up, choose one of these:
- Path-based versions on the live site. Build each release into
html/v1.4/and keep previous releases in the deployed output, withhtml/latest/(or a redirect) pointing at the newest. Themikeplugin automates this pattern for MkDocs. - One Hosting site per major version. A Firebase project can hold several Hosting sites (
docs-v1,docs-v2). Deploy each major release to its own site and leave it alone.
Path-based versions are simpler when releases are frequent. Separate sites suit libraries with long-lived major versions.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
api/ missing from the deployed site | Dokka ran before mkdocs build cleaned the folder, or wrote to the module’s build/ | Set outputDirectory and mustRunAfter |
Permission denied running the script in CI | Executable bit not committed | git update-index --chmod=+x |
| Every PR changes the public docs | channelId: live on PR workflow | Separate preview and publish workflows |
| Old release docs return 404 | Preview channel expired | Path-based versions or a Hosting site per version |
| Build passes with broken links | MkDocs not in strict mode | mkdocs build --strict |
Wrapping Up
The result is a ./gradlew buildDocs command that builds the full documentation site and a GitHub Actions workflow that ships it to a live URL on every PR. No manual deploys, no stale Confluence pages.
The natural next step is versioned docs: a separate Firebase Hosting channel per release tag so older API reference stays accessible after upgrades. That is a firebase hosting:channel:deploy v1.0 call away from the same workflow.
- Full source: github.com/joseph-fidelis