Upload mappings for Android

  1. Install hog

    Required

    Gradle plugin 1.9.0 or later uploads with hog

    Install hog, PostHog's CLI:

    curl -fsSL https://posthog.com/install.sh | sh

    In GitHub Actions, install hog with the PostHog/setup-hog action:

    YAML
    - uses: PostHog/setup-hog@v1

    Builds without hog

    When hog isn't installed, the Gradle plugin uploads with posthog-cli and warns that posthog-cli is deprecated. Earlier plugin versions only run posthog-cli, version 0.7.4 or later. To keep posthog-cli while hog is installed, set postHogExecutable = "posthog-cli". See Migrate from posthog-cli to hog.

  2. Authenticate

    Required

    Log in to PostHog. This opens your browser, where you approve the login:

    Terminal
    hog auth login

    If posthog-cli is already logged in on this machine, import that login instead:

    Terminal
    hog auth migrate

    hog reads only the HOG_* names. The PostHog build plugins and upload scripts still pass the old POSTHOG_CLI_* names to hog for now, with a warning for each one. A hog command you run yourself needs the HOG_* names. The migration guide lists each rename.

  3. Inject and upload

    Required

    AGP v8 or later

    Automatic mappings uploading is handled through the Gradle build process on Android.

    Install the PostHog Android Gradle Plugin on your app's build.gradle.kts file.

    Kotlin
    // Available through mavenCentral()
    plugins {
    id("com.android.application")
    id("com.posthog.android") version "$version"
    ...
    }

    If you are running this in CI/CD, you can configure hog directly on the Gradle task instead of relying on the HOG_HOST, HOG_PROJECT_ID, and HOG_PERSONAL_API_KEY environment variables:

    Kotlin
    import com.posthog.android.PostHogCliExecTask
    tasks.withType<PostHogCliExecTask> {
    postHogHost = "https://eu.posthog.com"
    postHogProjectId = "my-project-id"
    postHogApiKey = "my-personal-api-key"
    }

    postHogApiKey is optional. Without it, hog uses the job's OIDC login from hog ci setup, or the machine's hog auth login.

    You can also set postHogExecutable to a custom CLI path. The plugin runs it as hog when the file is named hog, and as posthog-cli otherwise.

  4. Upload native debug symbols (NDK)

    Optional

    Requires PostHog Android SDK 3.60.0 or later with errorTrackingConfig.captureNativeCrashes enabled, Gradle plugin 1.5.0 or later. Uploads with posthog-cli need CLI 0.7.32 or later.

    If your app includes native C or C++ code built with the NDK, upload the .so debug symbols so native crash stack traces resolve to function names, files, and line numbers.

    Enable the upload in your app's build.gradle.kts:

    Kotlin
    posthog {
    uploadNativeSymbols.set(true)
    }

    When enabled, the Gradle plugin's uploadPostHogNativeSymbols<Variant> task reads the variant's unstripped native libraries and uploads every one carrying debug info and a build ID, automatically after assemble, install, or bundle. This covers native code you build with the NDK as well as .so files bundled from jniLibs or dependencies, for minified and non-minified builds alike. Debuggable variants are skipped, so day-to-day debug builds don't upload symbols.

    To include source context around resolved crash frames, also bundle the project sources referenced by the debug info:

    Kotlin
    posthog {
    uploadNativeSymbols.set(true)
    includeNativeSymbolSources.set(true)
    }

    You can also run the upload task explicitly, for any variant, without enabling the automatic upload:

    Terminal
    ./gradlew uploadPostHogNativeSymbolsRelease

    You can also upload a directory of .so files directly, without the Gradle plugin:

    Terminal
    hog error-tracking upload app/build/intermediates/merged_native_libs/release --kind elf

    PostHog matches crash frames to uploaded symbols by each library's GNU build ID, which the NDK emits by default. Each build has its own build ID, so symbols must be re-uploaded for every build you ship.

    Native crash events are captured on the next app launch, so event properties like $app_version reflect the app at capture time, not at crash time. If the app updated in between, check the crash's release (matched by build ID) rather than the event's version properties when investigating.

  5. Verify mappings upload

    Checkpoint
    Confirm that mappings are successfully uploaded to PostHog.Check symbol sets in PostHog

Still have questions?

Was this page useful?