Mapping File Upload

Upload R8/ProGuard mapping.txt so obfuscated stack traces resolve to their original classes, methods and line numbers.

A release build shrunk by R8 leaves stack traces like a.b.c(Unknown Source:12). With that build's mapping.txt uploaded, Sophonz runs R8 retrace and shows the original names and line numbers. Mapping files are kept under the app's app version and matched exactly by build ID.

What gets resolved

DataAttributeContents
Crashes, handled exceptionsexception.stacktraceFrames of the throwing thread and its Caused by chain
Other threads at crash timespz.android.threadsThread names, states and frames

Methods R8 inlined expand back into several frames in their original call order. Platform packages (java., android., androidx., kotlin. …) are not obfuscated and are shown as they are.

Where mapping.txt is

Building a build type with isMinifyEnabled = true makes R8 write the mapping:

app/build/outputs/mapping/<build variant>/mapping.txt

CAUTION — Mappings are per build

Rebuilding the same code can produce different obfuscated names. Upload the mapping.txt of the exact build you shipped.

With the Sophonz Gradle plugin applied, mapping files upload automatically when the R8 task finishes. See Installation for applying the plugin.

Setup

Set the upload host in gradle.properties:

gradle.properties
sophonz.baseUrl=https://app.sophonz.ai

Put the credentials in sophonz-config.json. If either is empty, the upload task is not registered.

app/src/main/sophonz-config.json
{
  "app_id": "sophz",
  "api_token": "sophonz_pat_..."
}
KeyValue
api_tokenThe app's access token, issued in Settings > project > app > Access tokens
app_idA 5-character string the plugin requires. The Sophonz server identifies the app by the token and ignores this value, so any 5 characters work

NOTE — Do not commit the token

In CI, leave api_token out of sophonz-config.json and pass it as the SOPHONZ_API_TOKEN environment variable. app_id can also come from SOPHONZ_APP_ID.

- name: Build release
  env:
    SOPHONZ_API_TOKEN: ${{ secrets.SOPHONZ_TOKEN }}
    SOPHONZ_APP_ID: sophz
  run: ./gradlew assembleRelease

Behavior

  • The plugin generates a build ID for every build, embeds it in the app and uploads the mapping with the same value. The SDK reports it as app.build_id, so stack traces and mappings are joined per build.
  • The upload carries no version. Once the build sends telemetry, the file moves under the app version that build reported. Until then it appears in Settings under Builds with no known version yet.
  • Mapping files are sent zstd-compressed.
Gradle propertyDefaultDescription
sophonz.baseUrl—Upload host. When empty, the build fails at the upload step
sophonz.disableMappingFileUploadfalsetrue skips registering the mapping upload
sophonz.failBuildOnUploadErrors—Whether an upload failure fails the build

Option 2: @sophonz/cli

Without the Gradle plugin, or to run the upload as its own step, use the CLI. Requires Node.js 20 or later.

export SOPHONZ_TOKEN=sophonz_pat_...
 
npx @sophonz/cli upload-mapping \
  --file app/build/outputs/mapping/release/mapping.txt \
  --version 1.4.0
OptionDescription
-f, --filemapping.txt (required)
-v, --versionApp version; the SDK's service.version (versionName)
-b, --build-idBuild ID; the SDK's app.build_id
--typeR8 (default) or PROGUARD
-t, --tokenAccess token. Defaults to SOPHONZ_TOKEN

One of --version and --build-id is required.

- name: Build release
  run: ./gradlew assembleRelease
 
- name: Upload mapping
  env:
    SOPHONZ_TOKEN: ${{ secrets.SOPHONZ_TOKEN }}
  run: |
    # versionName from the metadata assembleRelease writes
    VERSION=$(jq -r '.elements[0].versionName' app/build/outputs/apk/release/output-metadata.json)
    npx @sophonz/cli upload-mapping \
      --file app/build/outputs/mapping/release/mapping.txt \
      --version "$VERSION"

Option 3: curl

curl -X POST https://app.sophonz.ai/api/v1/mapping-files \
  -H "Authorization: Bearer $SOPHONZ_TOKEN" \
  -F type=R8 \
  -F version=1.4.0 \
  -F file=@app/build/outputs/mapping/release/mapping.txt

How matching works

Opening a stack trace looks for a mapping file in this order:

  1. A file whose build ID equals the trace's app.build_id
  2. Otherwise, the most recently uploaded file whose version equals the trace's service.version

CAUTION — Uploading by version only

If several builds shipped under the same version, version matching uses the mapping uploaded last, and traces from earlier builds may resolve to the wrong names. Upload with a build ID if you reuse versions. The Gradle plugin always does.

Checking

Settings > project > app > Mapping files lists the app's versions. The list fills in from telemetry, and each version shows its mapping files and build IDs. A version that has sent telemetry without a mapping is flagged. Create a version ahead of release with Add version.

If the app uses WebViews, the same screen lists its web versions too; JavaScript errors in a WebView resolve with source maps.

When a crash or exception comes in, expand its row in Logs or Traces. The stack trace viewer puts the throwing thread first and lists Caused by and the other threads at crash time. Frames in your app's packages stand out and runs of platform frames are folded. A Symbolicated / Raw toggle shows the frames exactly as the device sent them.

Upload API

POST https://app.sophonz.ai/api/v1/mapping-files
Authorization: Bearer sophonz_pat_...
Content-Type: multipart/form-data
FieldDescription
typeR8 or PROGUARD
filemapping.txt; zstd- or gzip-compressed files are accepted
versionApp version
buildIdBuild ID

One of version and buildId is required. The Gradle plugin reaches the same storage through POST /v2/store/proguard.

StatuserrorCause
401unauthorizedToken missing, invalid, expired or revoked
400fileMissing / typeInvalid / versionRequiredMissing field
413fileTooLargeLarger than 500MB
422mappingInvalidNot readable as a mapping file
500storageFailedThe server could not store the file