# Size Analysis | Sentry for Flutter

[Size Analysis](https://docs.sentry.io/product/size-analysis.md) helps monitor your mobile app's size in pre-production to prevent unexpected size increases (regressions) from reaching users. Aside from being courteous to your users, a smaller app size helps boost installation and retention rates, especially for customers with limited storage or slower connections.

## [Getting Started - iOS](https://docs.sentry.io/platforms/dart/guides/flutter/size-analysis.md#getting-started---ios)

Size Analysis is most effective when part of your CI pipeline. To set up, follow our guide on [integrating into CI](https://docs.sentry.io/product/size-analysis/integrating-into-ci.md).

**Accepted Upload Formats**: XCArchive (preferred) | IPA

**Upload Mechanisms**: [Fastlane Plugin](https://docs.sentry.io/platforms/dart/guides/flutter/size-analysis.md#uploading-ios-builds-with-fastlane) *or* [Sentry CLI](https://docs.sentry.io/platforms/dart/guides/flutter/size-analysis.md#uploading-ios-builds-with-the-sentry-cli)

### [Uploading iOS Builds With Fastlane](https://docs.sentry.io/platforms/dart/guides/flutter/size-analysis.md#uploading-ios-builds-with-fastlane)

The Fastlane plugin can be used to upload XCArchive or IPA builds to Sentry. On GitHub Actions, Fastlane will automatically detect your [build's metadata](https://docs.sentry.io/platforms/dart/guides/flutter/size-analysis.md#upload-metadata) and include it in the upload. In other Continuous Integration (CI) environments, you may need to manually set metadata values.

1. Configure the [Sentry Fastlane plugin](https://docs.sentry.io/platforms/apple/guides/ios/dsym.md#sentry-fastlane-plugin) (version `1.36.0`):

   ```ruby
   bundle exec fastlane add_plugin fastlane-plugin-sentry
   ```

2. Set up `SENTRY_AUTH_TOKEN` in your environment (you can generate a token [here](https://sentry.sentry.io/settings/auth-tokens/))

3. In `FastFile`, add a call to `sentry_upload_build` after your build step:

   `Fastfile`

   ```ruby
   lane :upload_to_sentry do
      build_ios_app(
        scheme: 'YourScheme',
        configuration: 'Release',
      )
      sentry_upload_build(
        org_slug: 'your-org',
        project_slug: 'your-project',
        build_configuration: 'Release' # Adjust to your configuration
      )
   end
   ```

4. After an upload has successfully processed, confirm the metadata is correct in the Sentry UI

The Fastlane plugin automatically detects all build metadata. If needed, the metadata values can be overridden by passing parameters to `sentry_upload_build`:

`Fastfile`

```ruby
lane :upload_to_sentry do
  build_ios_app(
    scheme: 'YourScheme',
    configuration: 'Release',
  )
  sentry_upload_build(
    org_slug: 'your-org',
    project_slug: 'your-project',
    build_configuration: 'Release',
    # Optional metadata overrides:
    head_sha: 'abc123',
    base_sha: 'def456',
    vcs_provider: 'github',
    head_repo_name: 'organization/repository',
    base_repo_name: 'organization/repository',
    head_ref: 'feature-branch',
    base_ref: 'main',
    pr_number: '42'
  )
end
```

See the [Fastlane repo](https://github.com/getsentry/sentry-fastlane-plugin) for more information.

### [Uploading iOS Builds With the Sentry CLI](https://docs.sentry.io/platforms/dart/guides/flutter/size-analysis.md#uploading-ios-builds-with-the-sentry-cli)

1. Install the [sentry-cli](https://docs.sentry.io/cli.md) (version `3.1.0`)

   We recommend using the latest version for the best possible experience, but at a minimum version `2.58.2` is required.

2. Authenticate the Sentry CLI by [following these steps](https://docs.sentry.io/cli/configuration.md#to-authenticate-manually)

3. Build your app to create an XCArchive (preferred) or IPA

4. Invoke the following CLI command to trigger the upload:

   ```bash
   sentry-cli build upload app.xcarchive \
     --org your-org \
     --project your-project \
     --build-configuration Release
   ```

5. After an upload has successfully processed, confirm the metadata is correct in the Sentry UI

## [Getting Started - Android](https://docs.sentry.io/platforms/dart/guides/flutter/size-analysis.md#getting-started---android)

Size Analysis is most effective when part of your CI pipeline. To set up, follow our guide on [integrating into CI](https://docs.sentry.io/product/size-analysis/integrating-into-ci.md).

**Accepted Upload Formats**: AAB (preferred) | APK

**Upload Mechanisms**: [Sentry CLI](https://docs.sentry.io/platforms/dart/guides/flutter/size-analysis.md#uploading-android-builds-with-the-sentry-cli) | [Gradle](https://docs.sentry.io/platforms/dart/guides/flutter/size-analysis.md#uploading-android-builds-with-gradle)

### [Uploading Android builds with the Sentry CLI](https://docs.sentry.io/platforms/dart/guides/flutter/size-analysis.md#uploading-android-builds-with-the-sentry-cli)

1. Install the [sentry-cli](https://docs.sentry.io/cli.md) (version `3.1.0`)

   We recommend using the latest version for the best possible experience, but at a minimum version `2.58.2` is required.

2. Authenticate the Sentry CLI by [following these steps](https://docs.sentry.io/cli/configuration.md#to-authenticate-manually)

3. Build your app to create an AAB (preferred) or APK

4. Invoke the following CLI command to trigger the upload:

   ```bash
   sentry-cli build upload app.aab \
     --org your-org \
     --project your-project \
     --build-configuration Release
   ```

5. After an upload has successfully processed, confirm the metadata is correct in the Sentry UI

### [Uploading Android Builds With Gradle](https://docs.sentry.io/platforms/dart/guides/flutter/size-analysis.md#uploading-android-builds-with-gradle)

The Gradle plugin automatically detects build metadata from your git repository. On GitHub Actions, all metadata is automatically detected. On other CI systems, you may need to manually set some values using the `vcsInfo` extension.

1. Configure the
   <!-- -->
   [Sentry Android Gradle plugin](https://docs.sentry.io/platforms/android/configuration/gradle.md)
   <!-- -->
   with at least version `6.0.0-rc.1`

2. Set the auth token as an environment variable to be used when running your release build.

   ```
   export SENTRY_AUTH_TOKEN=___ORG_AUTH_TOKEN___
   ```

3. Enable uploading for <!-- -->size analysis<!-- --> for CI builds.

   `build.gradle.kts`

   ```
   sentry {
     sizeAnalysis {
       enabled = providers.environmentVariable("GITHUB_ACTIONS").isPresent
     }
   }
   ```

4. Invoke the following Gradle tasks to build your app and trigger the upload.

   `aab`

   ```
   ./gradlew bundleRelease
   ```

5. After an upload has successfully processed, confirm the metadata is correct in the Sentry UI

   ![Upload metadata](https://docs.sentry.io/_next/image/?url=%2Fplatforms%2Fandroid%2Fbuild-distribution%2Fimages%2Fandroid-metadata.png\&w=828\&q=75)

### Overriding Metadata

The Gradle plugin automatically detects build metadata from your git repository. On GitHub Actions, all metadata is automatically detected. On other CI systems, you may need to manually set some values using the `vcsInfo` extension.

Configure overrides in your Gradle build configuration:

`build.gradle.kts`

```
sentry {
  sizeAnalysis {
    enabled = providers.environmentVariable("GITHUB_ACTIONS").isPresent
  }

  vcsInfo {
    headSha.set("abc123")
    baseSha.set("def456")
    vcsProvider.set("github")
    headRepoName.set("organization/repository")
    baseRepoName.set("organization/repository")
    headRef.set("feature-branch")
    baseRef.set("main")
    prNumber.set(42)
  }
}
```

Available `vcsInfo` properties:

| Property       | Type   | Description                       |
| -------------- | ------ | --------------------------------- |
| `headSha`      | String | Current commit SHA                |
| `baseSha`      | String | Base commit SHA (for comparison)  |
| `vcsProvider`  | String | VCS provider (e.g., "github")     |
| `headRepoName` | String | Repository name (org/repo format) |
| `baseRepoName` | String | Base repository name              |
| `headRef`      | String | Branch or tag name                |
| `baseRef`      | String | Base branch name                  |
| `prNumber`     | Int    | Pull request number               |

## [Upload Metadata](https://docs.sentry.io/platforms/dart/guides/flutter/size-analysis.md#upload-metadata)

We use build metadata to organize builds in the UI and ensure correct comparisons.

| Field                   | Description                                                                                               |
| ----------------------- | --------------------------------------------------------------------------------------------------------- |
| `org`\*                 | Sentry organization slug                                                                                  |
| `project`\*             | Sentry project slug                                                                                       |
| `build-configuration`\* | Build configuration describing how the app was built, for example `Release` or `Debug` or `Release-Bazel` |
| `head-sha`              | Current commit SHA                                                                                        |
| `base-sha`              | Base commit SHA (for comparisons, recommended to use the branch's merge-base)                             |
| `head-repo-name`        | Repository name (`org/repo`)                                                                              |
| `pr-number`             | Pull request number                                                                                       |
| `head-ref`              | Branch or tag name                                                                                        |
| `base-ref`              | Base branch name                                                                                          |

\* *required field*

### [Build Configuration](https://docs.sentry.io/platforms/dart/guides/flutter/size-analysis.md#build-configuration)

Build configuration metadata keeps comparisons scoped to like-for-like builds. The Android Gradle plugin sends the build variant (for example, `freeDebug` or `paidRelease`). On iOS, set this to your Xcode build configuration, such as `Debug`, `Staging`, or `Release`.

* #### [Insights](https://docs.sentry.io/platforms/dart/guides/flutter/size-analysis/insights.md)

  Preview how Size Analysis highlights Flutter build trends.

## Pages in this section

- [insights](https://docs.sentry.io/platforms/dart/guides/flutter/size-analysis/insights.md)
