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
| Data | Attribute | Contents |
|---|---|---|
| Crashes, handled exceptions | exception.stacktrace | Frames of the throwing thread and its Caused by chain |
| Other threads at crash time | spz.android.threads | Thread 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.txtCAUTION — Mappings are per build
Rebuilding the same code can produce different obfuscated names. Upload the mapping.txt of the exact build you shipped.
Option 1: Gradle plugin (recommended)
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:
sophonz.baseUrl=https://app.sophonz.aiPut the credentials in sophonz-config.json. If either is empty, the upload task is not registered.
{
"app_id": "sophz",
"api_token": "sophonz_pat_..."
}| Key | Value |
|---|---|
api_token | The app's access token, issued in Settings > project > app > Access tokens |
app_id | A 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 assembleReleaseBehavior
- 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 property | Default | Description |
|---|---|---|
sophonz.baseUrl | — | Upload host. When empty, the build fails at the upload step |
sophonz.disableMappingFileUpload | false | true 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| Option | Description |
|---|---|
-f, --file | mapping.txt (required) |
-v, --version | App version; the SDK's service.version (versionName) |
-b, --build-id | Build ID; the SDK's app.build_id |
--type | R8 (default) or PROGUARD |
-t, --token | Access 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.txtHow matching works
Opening a stack trace looks for a mapping file in this order:
- A file whose build ID equals the trace's
app.build_id - 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| Field | Description |
|---|---|
type | R8 or PROGUARD |
file | mapping.txt; zstd- or gzip-compressed files are accepted |
version | App version |
buildId | Build ID |
One of version and buildId is required. The Gradle plugin reaches the same storage through POST /v2/store/proguard.
| Status | error | Cause |
|---|---|---|
401 | unauthorized | Token missing, invalid, expired or revoked |
400 | fileMissing / typeInvalid / versionRequired | Missing field |
413 | fileTooLarge | Larger than 500MB |
422 | mappingInvalid | Not readable as a mapping file |
500 | storageFailed | The server could not store the file |