Crash plugin

Attention.

This is an archived version of documentation. You can find the current documentation for all platforms here.

AppMetrica lets you collect information about native and Java crashes. You can analyze them in the Crashes report. See also Crashes/errors.

To reduce the size of an app, optimize the code during a release build.

If the code was compressed and obfuscated during the build of an Android application, information about crashes is transmitted in obfuscated form. To extract data for analysis from such crash logs, AppMetrica performs server-side deobfuscation.

To do this, upload the mapping files or debug symbols of SO files to AppMetrica, either automatically when building the app or manually via the web interface.

To send files, enable the AppMetrica Build Plugin.

Note. Upload mapping files if you use ProGuard or R8. If you don't compress or obfuscate the code, don't enable the plugin.
  1. Connecting the plugin
  2. Manual loading
  3. Build errors
  4. Changelog

Connecting the plugin

Attention. To use the plugin, you need to install the AppMetrica SDK version not lower than 3.8.0.

To enable the plugin:

  1. Add the following dependency to the build.gradle root file:
    buildscript {
        ...
        dependencies {
            ...
            classpath 'com.yandex.android:appmetrica-build-plugin:0.7.0'
        }
     }
    Copied to clipboard
  2. Add to the app/build.gradle file:
    ...
    apply plugin: 'appmetrica-plugin'
    
    appmetrica {
        postApiKey = { applicationVariant -> "Post Api key for variant" }
        // or postApiKey = "Post Api key"
        enable = { applicationVariant -> true }    // Optional.
        mappingBuildTypes = ['release']            // Optional.
        offline = false                            // Optional.
        mappingFile = { applicationVariant -> null }   // Optional.
        enableAnalytics = true                     // Optional.
        ndk {    // Optional.
            enable = { applicationVariant -> false }
            soFiles = { applicationVariant -> listOfSoFiles }             // Optional.
            additionalSoFiles = { applicationVariant -> listOfSoFiles }   // Optional.
            addNdkCrashesDependency = { applicationVariant -> true }      // Optional.
        }
    }
    ...
    Copied to clipboard
    postApiKey *
    Post API key or lambda function that returns a Post API key for ApplicationVariant. Read more about ApplicationVariant in the Android and Javadoc documentation.

    You can get the Post API key in the AppMetrica Settings. It's used to identify your app.

    If offline = true, the parameter is optional.

    enable
    Lambda function that accepts ApplicationVariant and returns whether to use the plugin for this build option.

    If the plugin isn't used, the apk doesn't change and the mapping file doesn't load.

    By default, it returns true only for buildType = 'release'.

    Note. Use one of the parameters to specify assembly types: enable or mappingBuildTypes.
    mappingBuildTypes
    The list of build types, buildType, for which the mapping file will be sent.

    Default value: ['release'].

    To disable the uploading of mapping files for a specific type of build, delete that buildType from the list.

    Note. Use one of the parameters to specify assembly types: enable or mappingBuildTypes.
    offline

    Enables the offline mode. Boolean or a lambda function that accepts ApplicationVariant.

    Acceptable values:

    • true — Doesn't upload a file to AppMetrica. If enabled, it outputs the archive path to the log after the build is complete. You can upload it manually via the web interface.
    • false — Automatically uploads the mapping file.

    The default value is false.

    mappingFile

    A lambda function that accepts ApplicationVariant and returns the mapping file to upload. If it returns null, the default value is used.

    The default value is ApplicationVariant.mappingFileProvider.
    enableAnalytics

    Enables sending plugin usage statistics to AppMetrica. Boolean.

    Acceptable values:

    • true — Sending statistics is enabled.
    • false — Sending statistics is disabled.

    The default value is true.

    ndk

    This parameter is required for loading characters from the SO file to track native crashes.

    enable

    Lambda function that accepts ApplicationVariant and returns whether to load the characters from the SO files for this build option.

    The default value is false.
    soFiles

    Lambda function that accepts ApplicationVariant and returns a list of SO files.

    By default, the plugin searches for SO files in the Android Studio project folders.

    You need to redefine the path if your SO files are in an unusual location or the plugin can't find them.

    additionalSoFiles

    Lambda function that accepts ApplicationVariant and returns a list of additional SO files to load the characters from.

    addNdkCrashesDependency

    Lambda function that accepts ApplicationVariant and returns whether to add a dependency on mobmetricalib-ndk-crashes.

    The default value is true.

    Required

  3. If the ndk parameter is enabled, debug symbols are sent using the Gradle task upload${variant.name.capitalize()}Symbols. To call a task automatically, you can add it to a file app/build.gradle the following code:
    ...
    afterEvaluate {
        android.applicationVariants.forEach { variant ->
            def uploadSymbolsTask = project.tasks.named("upload${variant.name.capitalize()}Symbols")
            if (uploadSymbolsTask != null) {
                variant.assembleProvider.get()?.finalizedBy(uploadSymbolsTask) // Если используете apk
                project.tasks.named("bundle${variant.name.capitalize()}").get()?.finalizedBy(uploadSymbolsTask) // Если используете aab
            }
        }
    }
    ...
    Copied to clipboard

Manual loading

To manually load, enable and use the plugin in offline mode. This is necessary to link the mapping file to the app build.

  1. In the app/build.gradle file, enable offline mode and run the build.
    appmetrica {
        ...
        offline = true
    }
    Copied to clipboard
    offline
    Enables offline mode. Acceptable values:
    • true — Doesn't upload the mapping file to AppMetrica. If enabled, it outputs the archive path to the log after the build is complete.
    • false — Automatically uploads the mapping file.

    The default value is false.

  2. In the AppMetrica interface, go to the app settings from the menu on the left.
  3. Open Crashes → Android.
  4. Click Choose file and upload the ZIP archive.

Build errors

Possible errors during a build:

  • IllegalStateException — Enable code obfuscation using ProGuard or R8 Compiler.
  • HttpResponseException — Check your internet connection.

If you encounter further errors, please contact technical support.

Changelog

Version 0.7.0

Released April 19, 2023.

  • Added more details to the error reporting that mapping files are missing.
  • Added support for AGP up to version 7.4.+ and Gradle up to 7.5.

Version 0.6.2

Released July 28, 2022

  • Improved performance of the plugin.

Version 0.6.1

Released May 20, 2022

  • Improved performance of the plugin.

Version 0.6.0

Released May 17, 2022

  • Added the mappingFile parameter.
  • Fixed the Cannot query the value of this property because it has no value available error that occurred when trying to get a mapping file.

Version 0.5.0

Released April 21, 2022

  • Fixed the IndexOutOfBoundsException: toIndex (16) is greater than size (8) raised when processing an SO file.
  • Fixed the Cannot query the value of this property because it has no value available crash that occurred when using the flag.
  • Added the ndk.addNdkCrashesDependency flag.

Version 0.3.0

Released June 17, 2021

  • Added support for gradle 7.
  • Added sending analytics.

Version 0.2.4

Released May 26, 2021

  • Added support for AGP 4.2.0.
  • Improved performance and stability of the plugin.

Version 0.2.2

Released February 19, 2021

  • Fixed the Connection timed out error when loading mapping files or symbols and using a proxy.

Version 0.2.1

Released 3 November 2020

  • Added support for Android App Bundle.
    Attention. Don't run the apk and aab build with a single gradle command. This may lead to incorrect processing of crashes.
  • Added logging.
  • Improved SO file search and parsing.

Version 0.1.3

Released 12 June 2020

  • Added automatic loading of characters from the SO files to track native crashes.
  • Added the split_version_codes field to the info.txt file to store every loaded version_code of the app.

Version 0.1.2

Released 13 March 2020

  • Fixed a crash during configuration process if the Post API key is not specified. There is a check during the boot run.
  • Fixed the way to get mapping files.
  • Added information about an error during uploading mapping files.
  • Added the ability to specify custom plugin parameter values for different ApplicationVariant.

Version 0.0.1

Released 8 October 2019

If you didn't find the answer you were looking for, you can use the feedback form to submit your question. Please describe the problem in as much detail as possible. Attach a screenshot if possible.