diff --git a/README.md b/README.md index 5c315a669..a98c75b5a 100644 --- a/README.md +++ b/README.md @@ -174,6 +174,29 @@ If your app doesn’t already access the microphone or photo library, we recomme **The permission alert for accessing the microphone/photo library will NOT appear unless users attempt to attach a voice note/photo while using Instabug.** + +## Auto Uploading Source Map Files + +For your app crashes to show up with a fully symbolicated stack trace, we will automatically generate the source map files and upload them to your dashboard on release build. To do so, we rely on your app token being explicitly added to `Instabug.startWithToken('YOUR_APP_TOKEN')` in JavaScript. + +If your app token is defined as a constant or you have different tokens for both iOS and Android apps, set the token as shown below. + +1. In Android, go to the `build.gradle` file of the library and you will find below code, replace `YOUR_APP_TOKEN` with your app token from the dashboard. + +```java +task upload_sourcemap(type: Exec) { + environment "INSTABUG_APP_TOKEN", "YOUR_APP_TOKEN" + commandLine 'sh', './upload_sourcemap.sh' +} +``` + +2. In iOS, go to the build phases of the project, you will find a build phase called `Upload Sourcemap`. Expand it you will find below lines of code, replace `YOUR_APP_TOKEN` with your token from the dashboard. + +```bash +export INSTABUG_APP_TOKEN="YOUR_APP_TOKEN" +bash "../node_modules/instabug-reactnative/ios/upload_sourcemap.sh" +``` + ## Documentation For more details about the supported APIs and how to use them, check our [**Documentation**](https://docs.instabug.com/docs/react-native-overview). diff --git a/android/build.gradle b/android/build.gradle index e0984de71..33ced30b7 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -31,6 +31,7 @@ dependencies { } task upload_sourcemap(type: Exec) { + environment "INSTABUG_APP_TOKEN", "YOUR_APP_TOKEN" commandLine 'sh', './upload_sourcemap.sh' } diff --git a/android/upload_sourcemap.sh b/android/upload_sourcemap.sh index fc177c162..0b8bd0fbd 100644 --- a/android/upload_sourcemap.sh +++ b/android/upload_sourcemap.sh @@ -2,6 +2,12 @@ cd .. cd .. cd .. +if [[ -s "$HOME/.nvm/nvm.sh" ]]; then +. "$HOME/.nvm/nvm.sh" +elif [[ -x "$(command -v brew)" && -s "$(brew --prefix nvm)/nvm.sh" ]]; then +. "$(brew --prefix nvm)/nvm.sh" +fi +export NODE_BINARY=node #Generate android sourcemap react-native bundle --platform android \ --entry-file index.js \ @@ -10,22 +16,24 @@ react-native bundle --platform android \ --sourcemap-output ./android-sourcemap.json && zip ./android-sourcemap.zip ./android-sourcemap.json -echo "Instabug: Looking for Token..." -if [ ! "${APP_TOKEN}" ]; then -APP_TOKEN=$(grep -r --exclude-dir={node_modules,ios,android} 'Instabug.startWithToken(\"[0-9a-zA-Z]*\"' ./ -m 1 | grep -o '\"[0-9a-zA-Z]*\"' | cut -d "\"" -f 2) -fi +if [ ${INSTABUG_APP_TOKEN} == "YOUR_APP_TOKEN" ]; then + echo "Instabug: Looking for Token..." + if [ ! "${INSTABUG_APP_TOKEN}" ]; then + INSTABUG_APP_TOKEN=$(grep -r --exclude-dir={node_modules,ios,android} 'Instabug.startWithToken(\"[0-9a-zA-Z]*\"' ./ -m 1 | grep -o '\"[0-9a-zA-Z]*\"' | cut -d "\"" -f 2) + fi -if [ ! "${APP_TOKEN}" ]; then -APP_TOKEN=$(grep -r --exclude-dir={node_modules,ios,android} "Instabug.startWithToken(\'[0-9a-zA-Z]*\'" ./ -m 1 | grep -o "\'[0-9a-zA-Z]*\'" | cut -d "\"" -f 2) + if [ ! "${INSTABUG_APP_TOKEN}" ]; then + INSTABUG_APP_TOKEN=$(grep -r --exclude-dir={node_modules,ios,android} "Instabug.startWithToken(\'[0-9a-zA-Z]*\'" ./ -m 1 | grep -o "\'[0-9a-zA-Z]*\'" | cut -d "\"" -f 2) + fi fi -if [ ! "${APP_TOKEN}" ] || [ -z "${APP_TOKEN}" ];then -echo "Instabug: err: APP_TOKEN not found. Make sure you've added the SDK initialization line Instabug.startWithToken" -exit 0 -else -echo "Instabug: Uploading files..." -#Upload android sourcemap -curl -X POST 'https://api.instabug.com/api/sdk/v3/symbols_files' -F "symbols_file=@./android-sourcemap.json" -F "application_token=${APP_TOKEN}" -F "platform=react_native" -F "os=android" -echo +if [ ! "${INSTABUG_APP_TOKEN}" ] || [ -z "${INSTABUG_APP_TOKEN}" ] || [ "${INSTABUG_APP_TOKEN}" == "YOUR_APP_TOKEN" ];then + echo "Instabug: err: INSTABUG_APP_TOKEN not found. Make sure you've added the SDK initialization line Instabug.startWithToken Or added it to the environment variable in the gradle" + exit 0 +else + echo "Instabug: Uploading files..." + #Upload ios sourcemap + curl -X POST 'https://api.instabug.com/api/sdk/v3/symbols_files' -F "symbols_file=@./ios-sourcemap.json" -F "application_token=${INSTABUG_APP_TOKEN}" -F "platform=react_native" -F "os=ios" + echo fi diff --git a/ios/upload_sourcemap.sh b/ios/upload_sourcemap.sh index aa7a2a5f0..f747eaa49 100644 --- a/ios/upload_sourcemap.sh +++ b/ios/upload_sourcemap.sh @@ -15,21 +15,24 @@ react-native bundle --platform ios \ --sourcemap-output ./ios-sourcemap.json && zip ./ios-sourcemap.zip ./ios-sourcemap.json -echo "Instabug: Looking for Token..." -if [ ! "${APP_TOKEN}" ]; then -APP_TOKEN=$(grep -r --exclude-dir={node_modules,ios,android} 'Instabug.startWithToken(\"[0-9a-zA-Z]*\"' ./ -m 1 | grep -o '\"[0-9a-zA-Z]*\"' | cut -d "\"" -f 2) -fi +if [ ${INSTABUG_APP_TOKEN} == "YOUR_APP_TOKEN" ]; then + echo "Instabug: Looking for Token..." + if [ ! "${INSTABUG_APP_TOKEN}" ]; then + INSTABUG_APP_TOKEN=$(grep -r --exclude-dir={node_modules,ios,android} 'Instabug.startWithToken(\"[0-9a-zA-Z]*\"' ./ -m 1 | grep -o '\"[0-9a-zA-Z]*\"' | cut -d "\"" -f 2) + fi -if [ ! "${APP_TOKEN}" ]; then -APP_TOKEN=$(grep -r --exclude-dir={node_modules,ios,android} "Instabug.startWithToken(\'[0-9a-zA-Z]*\'" ./ -m 1 | grep -o "\'[0-9a-zA-Z]*\'" | cut -d "\"" -f 2) + if [ ! "${INSTABUG_APP_TOKEN}" ]; then + INSTABUG_APP_TOKEN=$(grep -r --exclude-dir={node_modules,ios,android} "Instabug.startWithToken(\'[0-9a-zA-Z]*\'" ./ -m 1 | grep -o "\'[0-9a-zA-Z]*\'" | cut -d "\"" -f 2) + fi fi -if [ ! "${APP_TOKEN}" ] || [ -z "${APP_TOKEN}" ];then -echo "Instabug: err: APP_TOKEN not found. Make sure you've added the SDK initialization line Instabug.startWithToken" -exit 0 + +if [ ! "${INSTABUG_APP_TOKEN}" ] || [ -z "${INSTABUG_APP_TOKEN}" ] || [ "${INSTABUG_APP_TOKEN}" == "YOUR_APP_TOKEN" ];then + echo "Instabug: err: INSTABUG_APP_TOKEN not found. Make sure you've added the SDK initialization line Instabug.startWithToken Or added it to the environment variable in the gradle" + exit 0 else -echo "Instabug: Uploading files..." -#Upload ios sourcemap -curl -X POST 'https://api.instabug.com/api/sdk/v3/symbols_files' -F "symbols_file=@./ios-sourcemap.json" -F "application_token=${APP_TOKEN}" -F "platform=react_native" -F "os=ios" -echo + echo "Instabug: Uploading files..." + #Upload ios sourcemap + curl -X POST 'https://api.instabug.com/api/sdk/v3/symbols_files' -F "symbols_file=@./ios-sourcemap.json" -F "application_token=${INSTABUG_APP_TOKEN}" -F "platform=react_native" -F "os=ios" + echo fi diff --git a/link.rb b/link.rb index f93d0281e..5a060e2ae 100644 --- a/link.rb +++ b/link.rb @@ -24,6 +24,7 @@ INSTABUG_UPLOAD_NAME = "Upload Sourcemap" INSTABUG_UPLOAD_SCRIPT = <<-SCRIPTEND +export INSTABUG_APP_TOKEN="YOUR_APP_TOKEN" bash "../node_modules/instabug-reactnative/ios/upload_sourcemap.sh" SCRIPTEND diff --git a/package.json b/package.json index 6ed6219ba..3d84927d9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "instabug-reactnative", - "version": "8.2.3", + "version": "8.2.4", "description": "React Native plugin for integrating the Instabug SDK", "main": "index.js", "types": "index.d.ts",