PostHog Android SDK monorepo. Kotlin-first, targets JVM and Android.
posthog/— Core SDK (pure Kotlin/JVM, no Android dependencies)posthog-android/— Android-specific SDK (depends onposthog/)posthog-android-surveys-compose/— Compose survey UI (depends onposthog-android/, transitively onposthog/)posthog-server/— Server-side SDK (depends onposthog/)posthog-server-openfeature/— OpenFeature provider for the server-side SDK (depends onposthog-server/, Java 11+)posthog-android-gradle-plugin/— Gradle plugin for Android integrationsposthog-samples/— Sample apps
Prefer Make wrappers; see development commands for focused tests and formatting. Select JVM, Android or Compose survey checks for the affected module/behavior; Markdown-only edits need documentation checks, not SDK builds/tests.
- Kotlin, formatted via Spotless + ktlint
- No consecutive KDoc comments (ktlint
no-consecutive-commentsrule) - Use
@PostHogInternalannotation for public APIs meant only for internal SDK use internalvisibility for utilities not exposed to consumers- Prefer top-level functions over singleton objects for stateless utilities
- Preserve established ownership and synchronization. Use
@Volatilefor independent-state visibility where appropriate; protect compound state and mutable collections with established locks/atomics. A volatile reference does not protect mutable contents. - Test files live alongside source in
src/test/java/mirroring the main package structure - Test fixtures (JSON) go in
src/test/resources/json/
- Use MockWebServer (
okhttp3.mockwebserver) for HTTP tests andPostHogMemoryPreferencesfor in-memory preferences - Await relevant async work before assertions.
awaitExecution()is a nonterminal barrier only for previously submitted work on a serial executor, not arbitrary concurrent/chained work; otherwise use explicit completion signals. UseshutdownAndAwaitTermination()for terminal waits/cleanup; it disables future submissions. - Close SDK instances with
sut.close()(orPostHog.close()for singleton tests) and shut down any created mock servers withhttp.shutdown()in test cleanup
- Sign every commit;
mainrejects unsigned commits. Configure signing in the git config you commit with, as described in "Commit signing" in CONTRIBUTING.md. - Public API changes: follow "Public API changes" in CONTRIBUTING.md. As an agent, also:
- When reviewing or fixing someone else's PR, don't ask for or open an issue. Note an external contributor's public API change when it has neither an agreed issue nor an API-defining published spec.
- The author is a PostHog maintainer when the PR's
author_associationisMEMBERorOWNER(gh api repos/PostHog/posthog-android/pulls/<number> --jq .author_association) or, before a PR exists, whengh api orgs/PostHog/members/$(gh api user --jq .login)succeeds. If the check fails or can't run, treat the author as an external contributor. - A published sdk-spec that defines the API counts as the agreement, so no issue is needed.
- For an external contributor with no agreed issue and no spec, stop before implementing and draft the issue body for the user to post. Open it only if they ask.
- Before implementing or reviewing SDK behavior, check PostHog/sdk-specs for a spec covering it (its README lists every capability). If one exists, use it as the cross-SDK contract for the behavior the PR changes, and call out any divergence in that behavior in the PR description. Don't fix or flag discrepancies between the spec and code the PR doesn't touch. If none exists, carry on.
Before opening a PR, run pnpm changeset, select affected packages, semver bump and change summary, and commit the generated .changeset/*.md with the PR.
Use .github/pull_request_template.md; explain change intent and actual validation, and follow its Agent context, attribution and human-review requirements.