|
| 1 | +.. _add-mapping-file: |
| 2 | + |
| 3 | +********************************************************************* |
| 4 | +Add a mapping file |
| 5 | +********************************************************************* |
| 6 | + |
| 7 | + |
| 8 | +.. meta:: |
| 9 | + :description: Your uploaded mapping file enables Splunk RUM to convert stack traces back into a human-readable form. |
| 10 | + |
| 11 | + |
| 12 | +When you set the ``minifyEnabled`` property to true in your Android application source code, your build process minifies, optimizes, and obfuscates the code and generates a single mapping file, ``mapping.txt``. This mapping file contains the information Splunk RUM needs to convert stack traces containing obfuscated classes and filenames back into a human readable form. This conversion is called deobfuscation in Android. |
| 13 | + |
| 14 | +In order to associate a specific mapping file with a specific application build, Splunk RUM compares the ``applicationId`` and ``versionCode`` properties of the application to the parameters that you specify for the mapping file upload. You specify these parameters either as ``--app-id`` and ``--version-code`` in the ``splunk-rum android upload`` command or by including your application's merged or packaged manifest (``AndroidManifest.xml``), which includes these properties by default, in the ``splunk-rum android upload-with-manifest`` command. |
| 15 | + |
| 16 | + |
| 17 | +.. note:: |
| 18 | + Splunk recommends that you follow the steps on this page to upload your mapping files to Splunk RUM before you distribute corresponding binaries. To ensure that the mapping files you upload to Splunk RUM match the binaries you deploy to production, the best practice is to integrate the ``splunk-rum`` commands below into your CI pipeline so that whenever you re-build your Android application, you automatically re-upload its mapping file. Alternatively, you can :ref:`upload source maps on demand<mobile-connect-source-files>`. |
| 19 | + |
| 20 | + Splunk RUM stores your mapping files permanently. You cannot delete them from Splunk RUM at this time. |
| 21 | + |
| 22 | + |
| 23 | +Prerequisites |
| 24 | +===================================================================== |
| 25 | + |
| 26 | +* To support de-obfuscation of your application's stack traces, ensure that your ``proguard-rule.pro`` has the following two lines enabled: |
| 27 | + |
| 28 | + .. code-block:: |
| 29 | +
|
| 30 | + -keepattributes LineNumberTable,SourceFile |
| 31 | + -renamesourcefileattribute SourceFile |
| 32 | +
|
| 33 | +* Upgrade the following Splunk components: |
| 34 | + |
| 35 | + * :new-page:`splunk-otel-android<https://central.sonatype.com/artifact/com.splunk/splunk-otel-android>`: v1.10.0 |
| 36 | + |
| 37 | +* :ref:`Install the splunk-rum CLI<rum-gdi-install-cli>`. |
| 38 | + |
| 39 | + |
| 40 | +Uploads for production builds |
| 41 | +===================================================================== |
| 42 | + |
| 43 | +#. Upload your application's mapping file and specify its ``applicationID`` and ``versionCode`` properties. |
| 44 | + |
| 45 | + You can do this in either of these ways: |
| 46 | + |
| 47 | + * Run the ``upload`` command with the ``--app-id`` and ``--version-code`` parameters: |
| 48 | + |
| 49 | + .. note:: |
| 50 | + If you didn't set the ``SPLUNK_REALM`` and ``SPLUNK_ACCESS_TOKEN`` environment variables, you must also add the ``--realm <value>`` and ``--token <your-splunk-org-access-token>`` parameters to this command. |
| 51 | + |
| 52 | + .. code-block:: shell |
| 53 | +
|
| 54 | + splunk-rum android upload \ |
| 55 | + --app-id=<applicationID> --version-code=<versionCode> \ |
| 56 | + --path=<path-to-mapping-file> \ |
| 57 | + [optional-parameters] |
| 58 | +
|
| 59 | + * Run the ``upload-with-manifest`` command with the path to the application's merged or packaged ``AndroidManifest.xml`` file, along with path to the mapping file. Be sure to include the correct manifest, which is the one that's created when your application is built, and is located in the build output directory: |
| 60 | + |
| 61 | + .. note:: |
| 62 | + If you didn't set the ``SPLUNK_REALM`` and ``SPLUNK_ACCESS_TOKEN`` environment variables, you must also add the ``--realm <value>`` and ``--token <your-splunk-org-access-token>`` parameters to this command. |
| 63 | + |
| 64 | + .. code-block:: shell |
| 65 | +
|
| 66 | + splunk-rum android upload-with-manifest \ |
| 67 | + --manifest <path-to-merged-manifest> \ |
| 68 | + --path <path-to-mapping-file> \ |
| 69 | + [optional-parameters] |
| 70 | + |
| 71 | + |
| 72 | + |
| 73 | +#. (Optional) Verify that your upload succeeded: |
| 74 | + |
| 75 | + .. code-block:: shell |
| 76 | +
|
| 77 | + splunk-rum android list --app-id=<applicationID> |
| 78 | +
|
| 79 | +
|
| 80 | +
|
| 81 | +Uploads for pre-production builds |
| 82 | +===================================================================== |
| 83 | + |
| 84 | + If you're instrumenting pre-production builds where ``versionCode`` isn't updated for each build, add a unique identifier as metadata to the ``AndroidManifest.xml`` file in your source directory before building the application binary. This identifier must be named ``splunk.build_id``. To add this identifier, follow the steps below: |
| 85 | + |
| 86 | + |
| 87 | +#. Add this snippet to the ``<application>`` block of the ``AndroidManifest.xml`` file in your source directory: |
| 88 | + |
| 89 | + .. code-block:: xml |
| 90 | +
|
| 91 | + <meta-data |
| 92 | + android:name="splunk.build_id" |
| 93 | + android:value="${splunkBuildId}" /> |
| 94 | +
|
| 95 | +
|
| 96 | +#. Add the following code to the ``android {}`` block of the Gradle build script of your application. This code generates a new UUID for every application variant and adds it to the merged manifest file after the variant is assembled, where the Splunk RUM agent will retrieve it: |
| 97 | + |
| 98 | + * If you use Kotlin add this to ``build.gradle.kts``: |
| 99 | + |
| 100 | + .. code-block:: |
| 101 | +
|
| 102 | + applicationVariants.configureEach { |
| 103 | + val uniqueBuildId = UUID.randomUUID().toString() |
| 104 | + this.mergedFlavor.manifestPlaceholders["splunkBuildId"] = uniqueBuildId |
| 105 | +
|
| 106 | + logger.lifecycle("Splunk: Variant $name assigned build ID: $uniqueBuildId") |
| 107 | +
|
| 108 | + val capitalizedVariantName = name.replaceFirstChar { it.uppercase() } |
| 109 | + tasks.named("process${capitalizedVariantName}Manifest").configure { |
| 110 | + outputs.upToDateWhen { false } |
| 111 | + } |
| 112 | + } |
| 113 | +
|
| 114 | +
|
| 115 | + * If you use Groovy add this to ``build.gradle``: |
| 116 | + |
| 117 | + .. code-block:: |
| 118 | +
|
| 119 | + applicationVariants.configureEach { variant -> |
| 120 | + def uniqueBuildId = UUID.randomUUID().toString() |
| 121 | + variant.mergedFlavor.manifestPlaceholders.put("splunkBuildId", uniqueBuildId) |
| 122 | +
|
| 123 | + project.logger.lifecycle("Splunk: Variant ${variant.name} assigned build ID: ${uniqueBuildId}") |
| 124 | +
|
| 125 | + def capitalizedVariantName = variant.name.capitalize() |
| 126 | + tasks.named("process${capitalizedVariantName}Manifest").configure { |
| 127 | + outputs.upToDateWhen { false } |
| 128 | + } |
| 129 | + } |
| 130 | +
|
| 131 | +
|
| 132 | +#. Upload your application's mapping file and specify its ``applicationID`` , ``versionCode``, and ``splunk.build_id`` properties. You can do this in either of these ways: |
| 133 | + |
| 134 | + * Run the upload command with the ``--app-id``, ``--version-code``, and ``--splunk-build-id`` parameters. This option only works if you added ``splunk.build_id`` to your Gradle build script (in step 1). Get the build ID from the Gradle build output or from the merged manifest: |
| 135 | + |
| 136 | + .. note:: |
| 137 | + If you didn't set the ``SPLUNK_REALM`` and ``SPLUNK_ACCESS_TOKEN`` environment variables, you must also add the ``--realm <value>`` and ``--token <your-splunk-org-access-token>`` parameters to this command. |
| 138 | + |
| 139 | + .. code-block:: shell |
| 140 | +
|
| 141 | + splunk-rum android upload \ |
| 142 | + --app-id=<applicationID> --version-code=<versionCode> \ |
| 143 | + --splunk-build-id <value> \ |
| 144 | + --path=<path-to-mapping-file> \ |
| 145 | + [optional-parameters] |
| 146 | +
|
| 147 | +
|
| 148 | + * Run the ``upload-with-manifest`` command with the path to the application's merged or packaged ``AndroidManifest.xml`` file, along with path to the mapping file. Be sure to include the correct manifest, which is the one that's created when your application is built, and is located in the build output directory: |
| 149 | + |
| 150 | + .. note:: |
| 151 | + If you didn't set the ``SPLUNK_REALM`` and ``SPLUNK_ACCESS_TOKEN`` environment variables, you must also add the ``--realm <value>`` and ``--token <your-splunk-org-access-token>`` parameters to this command. |
| 152 | + |
| 153 | + .. code-block:: shell |
| 154 | +
|
| 155 | + splunk-rum android upload-with-manifest \ |
| 156 | + --manifest <path-to-merged-manifest> \ |
| 157 | + --path <path-to-mappping-file> \ |
| 158 | + [optional-parameters] |
| 159 | +
|
| 160 | +
|
| 161 | +#. (Optional) Verify that your upload succeeded: |
| 162 | + |
| 163 | + .. code-block:: shell |
| 164 | +
|
| 165 | + splunk-rum android list --app-id=<applicationID> |
| 166 | + |
| 167 | + |
| 168 | +
|
| 169 | +Syntax |
| 170 | +===================================================================== |
| 171 | + |
| 172 | +.. code-block:: shell |
| 173 | +
|
| 174 | + splunk-rum android [command] [parameters] |
| 175 | +
|
| 176 | +
|
| 177 | +
|
| 178 | +Command descriptions |
| 179 | +===================================================================== |
| 180 | + |
| 181 | +.. list-table:: |
| 182 | + :header-rows: 1 |
| 183 | + :widths: 20, 80 |
| 184 | + |
| 185 | + * - :strong:`Command` |
| 186 | + - :strong:`Description` |
| 187 | + |
| 188 | + * - ``upload --path <path> --app-id <value> --version-code <int> [optional-parameters]`` |
| 189 | + - Upload the mapping file ``mapping.txt`` with the application ID and version code that you specify. |
| 190 | + |
| 191 | + Parameters: |
| 192 | + |
| 193 | + * ``--path <path>`` Required. Path to the ``mapping.txt`` file. |
| 194 | + |
| 195 | + * ``--app-id <applicationID>`` Required. The ``applicationId`` property in your application's ``build.gradle`` file. |
| 196 | + |
| 197 | + * ``--version-code <int>`` Required. The ``versionCode`` property of your application. |
| 198 | + |
| 199 | + * ``--splunk-build-id <value>`` Optional. Splunk build ID for the upload. |
| 200 | + |
| 201 | + * ``--realm <value>`` Optional. Realm for your organization. For example, ``us0``. You can omit this parameter and set the environment variable ``SPLUNK_REALM`` instead. |
| 202 | + |
| 203 | + * ``--token <your-splunk-org-access-token>`` Optional. API access token. You can omit this parameter and set the environment variable ``SPLUNK_ACCESS_TOKEN`` instead. |
| 204 | + |
| 205 | + * ``--dry-run=[true|false]`` Perform a trial run with no changes made. Default: ``false``. |
| 206 | + |
| 207 | + * ``--debug`` Enable debug logs. |
| 208 | + |
| 209 | + * ``-h, --help`` Display help for this command. |
| 210 | + |
| 211 | + |
| 212 | + * - ``upload-with-manifest --manifest <path> --path <path> [optional-parameters]`` |
| 213 | + - Upload the Android ``mapping.txt`` file with required metadata extracted from the ``AndroidManifest.xml`` file. |
| 214 | + |
| 215 | + Parameters: |
| 216 | + |
| 217 | + * ``--manifest <path>`` Required. Path to the merged or the packaged ``AndroidManifest.xml`` file that is generated when the application is built. |
| 218 | + |
| 219 | + * ``--path <path>`` Required. Path to the ``mapping.txt`` file. |
| 220 | + |
| 221 | + * ``--realm <value>`` Optional. Realm for your organization. For example, ``us0``. You can omit this parameter and set the environment variable ``SPLUNK_REALM`` instead. |
| 222 | + |
| 223 | + * ``--token <your-splunk-org-access-token>`` Optional. API access token. You can omit this parameter and set the environment variable ``SPLUNK_ACCESS_TOKEN`` instead. |
| 224 | + |
| 225 | + * ``--dry-run=[true|false]`` Preview the file that will be uploaded and the parameters that will be extracted from ``AndroidManifest.xml``. |
| 226 | + |
| 227 | + * ``--debug`` Enable debug logs. |
| 228 | + |
| 229 | + * ``-h, --help`` Display help for command. |
| 230 | + |
| 231 | + |
| 232 | + * - ``list --app-id <value> [optional-parameters]`` |
| 233 | + - List the 100 most recently uploaded mapping files for the given application ID, sorted in reverse chronological order based on the upload timestamp. |
| 234 | + |
| 235 | + Parameters: |
| 236 | + |
| 237 | + * ``--app-id <applicationID>`` Required. The ``applicationId`` property in your app's ``build.gradle`` file. |
| 238 | + |
| 239 | + * ``--realm <value>`` Optional. Realm for your organization. For example, ``us0``. You can omit this parameter and set the environment variable ``SPLUNK_REALM`` instead. |
| 240 | + |
| 241 | + * ``--token <your-splunk-org-access-token>`` Optional. API access token. You can omit this parameter and set the environment variable ``SPLUNK_ACCESS_TOKEN`` instead. |
| 242 | + |
| 243 | + * ``--dry-run=[true|false]`` Perform a trial run with no changes made. Default: ``false``. |
| 244 | + |
| 245 | + * ``--debug`` Enable debug logs. |
| 246 | + |
| 247 | + * ``-h, --help`` Display help for this subcommand. |
| 248 | + |
| 249 | + |
0 commit comments