Deobfuscate
If you use ProGuard to obfuscate your code, Shake allows you to upload your mapping.txt files so it can deobfuscate stack traces.
Upload manually to Shake dashboard
By default, the mapping.txt file is created in your app's build directory: project/app/build/outputs/mapping/release/mapping.txt.
To upload your app's mapping files to the Shake dashboard:
- Visit Workspace administration โ Apps
- Click your app name to expand it
- Click the Mapping files button
- Drag and drop your mapping.txt file there
Using the script
If you prefer to do this automatically, you can do it using this script:
- Windows
- Mac
upload_mapper.bat
@echo offset PATH_TO_MAPPING_FILE=%1set CLIENT_ID=%2set CLIENT_SECRET=%3set VERSION_CODE=%4set VERSION_NAME=%5set APPLICATION_ID=%6rem Replace URL with valid Endpoint for file uploadingset FILES_ENDPOINT="https://api.shakebugs.com/api/1.0/crash_reporting/app_debug_file/%APPLICATION_ID%"rem Replace URL with valid Authentication Endpointset AUTH_ENDPOINT="https://api.shakebugs.com/auth/oauth2/token"if NOT exist %PATH_TO_MAPPING_FILE% (echo "Mapping file not found!"exit)echo "Mapping file found!"echo "Uploading mapping file..."FOR /F "tokens=*" %%G IN ('curl -X POST -u "%CLIENT_ID%:%CLIENT_SECRET%" -d "grant_type=client_credentials" %AUTH_ENDPOINT%')DO SET APP_TOKEN=%%Gset APP_TOKEN=%APP_TOKEN:"=%set "APP_TOKEN=%APP_TOKEN:~1,-2%"set "APP_TOKEN=%APP_TOKEN:: ==%"set "%APP_TOKEN:, =" & set "%"echo %access_token%echo %PATH_TO_MAPPING_FILE%FOR /F "tokens=*" %%A IN ('curl -H "Authorization: Bearer %access_token%" -F "file=@%PATH_TO_MAPPING_FILE%" -F "app_version_code=%VERSION_CODE%" -F "app_version_name=%VERSION_NAME%" -F "os=Android" -F "platform=Android" -X POST %FILES_ENDPOINT% -w "%%{http_code}"') DO SET STATUS=%%Aif %STATUS% NEQ 200 (echo "Failed to upload mapping file."exit)echo "Success! Mapping file uploaded successfully."exit
upload_mapper.sh
#!/bin/bashPATH_TO_MAPPING_FILE=$1CLIENT_ID=$2CLIENT_SECRET=$3VERSION_CODE=$4VERSION_NAME=$5APPLICATION_ID=$6# Replace URL with valid Endpoint for file uploadingFILES_ENDPOINT="https://api.shakebugs.com/api/1.0/crash_reporting/app_debug_file/$APPLICATION_ID"# Replace URL with valid Authentication EndpointAUTH_ENDPOINT="https://api.shakebugs.com/auth/oauth2/token"echo "Shake: Start mapping file upload: $PATH_TO_MAPPING_FILE"if [ ! -f $PATH_TO_MAPPING_FILE ]; thenecho "Mapping file not found!"exit 0fiecho "Mapping file found!"echo "Uploading mapping file..."APP_TOKEN=$(curl -X POST -u "$CLIENT_ID:$CLIENT_SECRET" \-d "grant_type=client_credentials" $AUTH_ENDPOINT )ACCESS_TOKEN=$(echo $APP_TOKEN | tr { '\n' | tr , '\n' | tr } '\n' | grep "access_token" | awk -F'"' '{print $4}')STATUS=$(curl -H "Authorization: Bearer $ACCESS_TOKEN" -F app_version_code="${VERSION_CODE}"\-F app_version_name="${VERSION_NAME}" -F os="Android"\-F platform="Android" -F "file=@${PATH_TO_MAPPING_FILE}"\-X POST "$FILES_ENDPOINT" --write-out %{http_code})if [ "${STATUS: -3}" != "200" ]; thenecho "Error while uploading mapping files"exit 0fiecho "Success! Mapping file uploaded successfully."
After that, add the following gradle task to your app's build.gradle file:
build.gradle
import org.apache.tools.ant.taskdefs.condition.Ostask uploadMappingFile {def client = 'client-key'def secret = 'secret-key'doLast {android.applicationVariants.all {def mappingFile = it.mappingFiledef applicationId = it.applicationIddef versionName = it.versionNamedef versionCode = it.versionCodeif (it.buildType.name == 'release' && mappingFile != null && mappingFile.exists()) {if (Os.isFamily(Os.FAMILY_WINDOWS)) {exec {commandLine 'cmd', '/c', 'start', 'upload_mapper.bat', mappingFile, client, secret, versionCode,versionName, applicationId}} else if (Os.isFamily(Os.FAMILY_UNIX)) {exec {commandLine 'sh', './upload_mapper.sh', mappingFile, client, secret, versionCode, versionName,applicationId}} else {throw new GradleException('Not supported OS!')}}}}}