Gradle plugin which analyzes the size of your Android apps

Related tags

Gradle plugin Scope
Overview

Scope is a Gradle plugin which helps you analyze the size of your Android apps.

Build Status Maven Release License

Motivation

App size is an important metric which directly correlates with business metrics like install conversion rate. Measuring app size is straightforward, but knowing what contributes to it is not. Especially in bigger projects with hundreds or thousands of modules and third-party dependencies. Scope provides a convenient way to find out how much each module and dependency contributes to the total size of your app by running a single Gradle task.

Usage

Follow the following steps to start using Scope in your project.

Adding the plugin

First you need to add the Scope Gradle plugin to the buildscript classpath in your top-level build.gradle file:

buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath("com.plexus.scope:scope-gradle-plugin:1.1.0")
    }
}

You also have to apply the plugin in the build.gradle of your application module:

plugins {
    id("com.android.application")
    id("com.plexus.scope")
}

Configuring the plugin

When using app bundles, Google Play will generate optimized APKs for each device. This means that the size of an APK depends on the specifications of the device that's downloading it. You can configure which device specifications should be used for the analysis in the build.gradle of your application module:

scope {
    abi.set("arm64-v8a")
    locale.set("en")
    screenDensity.set(480)
    sdkVersion.set(27)
}

Running the task

Once this is done, scope Bundle tasks will be added for each of your app variants. Running this task will build the app and generate a HTML report, which you can use to analyze your app size. It will also generate a JSON report, in case you want to further process the data.

Ownership

In larger organizations, Gradle modules and dependencies are often owned by specific teams. If that's the case for your app, Scope can help you analyze app size contributions by different teams. All you need to do is provide a YAML file listing all components and their owners:

# Identifier for Gradle modules -> path of the module
- identifier: :sample:app
  owner: app-team

# Identifier for dependencies -> dependency shorthand without the version
- identifier: androidx.core:core
  owner: core-team

# Wildcard identifier -> matches multiple components (can be both modules or dependencies)
- identifier: :sample:wildcard:*
  owner: wildcard-team

This ownership file can be maintained manually, but in most cases it will be more practical to generate it during the build. You can point Scope to your YAML file in the build.gradle, you can also configure default owners for components missing from the ownership file:

scope {
    ownershipFile.set(project.file("/path/to/ownership.yaml"))
    defaultOwner.set("default-team") // unknown by default
}

When you pass an ownership file to Scope, you'll see a new tab in the HTML report with app size insights broken down by team.

Project structure

Scope is built with Kotlin and contains multiple modules:

  • scope-gradle-plugin: Core Gradle plugin where the APK parsing, dependency handling and attribution logic lives.
  • scope-frontend: React template used for the HTML report, built with Kotlin JS.
  • scope-models: Common models shared between the Gradle plugin and the frontend, built with Kotlin Multiplatform.

Working with this project

The project is set up like a standard Gradle project. You can build it using ./gradlew assemble and run the tests with ./gradlew test.

There is also a sample project, which shows the usage of the plugin. Because the way this sample project is set up, the initial build can fail if you bump the plugin version. To fix this, you have to publish the plugin to your local Maven repository by running ./gradlew publishToMavenLocal -PwithoutSample.

When working on the frontend, you can start a development server by running ./gradlew browserRun, which will show a report filled with dummy data to make development easier.

Compatibility

The latest version of this plugin is compatible with

  • Java 11 or above,
  • Gradle 7.0 or above and
  • Android Gradle Plugin 7.0.0 or above.

Earlier versions might also work, but compatibility can't be guaranteed.

Code of conduct

This project adheres to the Open Code of Conduct. By participating, you are expected to honor this code.

License

Copyright 2022 Plexus, Inc

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
You might also like...
Android Gradle Plugin -- Auto Check big image and compress image in building.

McImage I will continue to update, please rest assured to use 中文文档 Android优雅的打包时自动化获取全部res资源 McImage is a Non-invasive plugin for compress all res in

A Gradle plugin helps to proxy all the BuildConfig fields in the Android project.
A Gradle plugin helps to proxy all the BuildConfig fields in the Android project.

Readme A Gradle plugin helps to proxy all the BuildConfig fields in the Android project. Background In android BuildConfig, We might have different co

Gradle plugin for running Android tests with emulator.wtf

emulator.wtf Gradle Plugin Emulator.wtf is an Android cloud emulator laser-focused on performance to deliver quick feedback to your PRs. With this Gra

A Gradle Plugin for Android BundleTool.
A Gradle Plugin for Android BundleTool.

A Gradle Plugin for Android BundleTool.

The core Gradle plugin and associated logic used for Slack's Android app

slack-gradle-plugin This repository contains the core Gradle plugin and associated logic used for Slack's Android app. This repo is effectively read-o

Gradle Plugin to enable auto-completion and symbol resolution for all Kotlin/Native platforms.
Gradle Plugin to enable auto-completion and symbol resolution for all Kotlin/Native platforms.

CompleteKotlin Gradle Plugin to enable auto-completion and symbol resolution for all Kotlin/Native platforms. What this plugin provides This zero-conf

 Gradle Plugin for Continuous Integration of AppSweep App Testing.
Gradle Plugin for Continuous Integration of AppSweep App Testing.

This Gradle plugin can be used to continuously integrate app scanning using AppSweep into your Android app build process

Artifactory is a gradle plugin to assist in developing Minecraft mods that can target different modloaders.

Artifactory Artifactory is a gradle plugin to assist in developing Minecraft mods that can target different modloaders. Currently, Fabric and Forge ar

A Gradle plugin to help analyse the dependency between modules and run tasks only on modules impacted by specific set of changes.
A Gradle plugin to help analyse the dependency between modules and run tasks only on modules impacted by specific set of changes.

Change Tracker Plugin A Gradle plugin to help analyse the dependency between modules and run tasks only on modules impacted by specific set of changes

Owner
Nanashi Li
Nanashi Li
A Gradle plugin that generates plugin.yml for Bukkit/BungeeCord/Nukkit plugins based on the Gradle project

plugin-yml is a simple Gradle plugin that generates the plugin.yml plugin description file for Bukkit plugins, bungee.yml for Bungee plugins or nukkit.yml for Nukkit plugins based on the Gradle project. Various properties are set automatically (e.g. project name, version or description) and additional properties can be added using a simple DSL.

Plexus 0 Apr 10, 2022
Gradle Plugin to automatically upgrade your gradle project dependencies and send a GitHub pull request with the changes

Gradle Plugin to automatically upgrade your gradle project dependencies and send a GitHub pull request with the changes

Dipien 142 Dec 29, 2022
Gradle plugin which validates the licenses of your dependency graph match what you expect

Gradle plugin which validates the licenses of your dependency graph match what you expect

Cash App 502 Dec 31, 2022
Graphfity is a Gradle Plugin which creates a dependency node diagram graph about your internal modules dependencies, specially useful if you are developing a multi-module application

Graphfity creates a dependency nodes diagram graph about your internal modules dependencies, specially useful if you are developing a multi-module app

Iván Carrasco 27 Dec 20, 2022
A Gradle plugin that improves the experience when developing Android apps, especially system tools, that use hidden APIs.

A Gradle plugin that improves the experience when developing Android apps, especially system tools, that use hidden APIs.

Rikka apps 124 Dec 31, 2022
Gradle Plugin that allows you to decompile bytecode compiled with Jetpack Compose Compiler Plugin into Java and check it

decomposer Gradle Plugin that allows you to decompile bytecode compiled with Jetpack Compose Compiler Plugin into Java and check it How to use Run bui

Takahiro Menju 56 Nov 18, 2022
A Gradle Plugin to determine which modules were affected by a set of files in a commit.

A Gradle Plugin to determine which modules were affected by a set of files in a commit. One use case for this plugin is for developers who would like to only run tests in modules which have changed in a given commit.

Dropbox 491 Dec 23, 2022
EasyVersion is a Gradle plugin that manage your app or library version.

EasyVersion EasyVersion is a Gradle plugin that manage your app or library version. Before Downloading Create easy_version.json in your root project d

Kosh Sergani 8 Nov 26, 2022
KMP Ready is a Gradle Plugin that provides actionable advice to make your code Kotlin Multiplatform compatible.

KMP Ready IS ?? UNDER DEVELOPMENT ?? Decisioning Logic Positive Signals ✅ Only Kotlin .kt Source Files Using Kotlin JVM Plugin Uses the Kotlin Multipl

Sam Edwards 58 Dec 22, 2022
Grazel is a Gradle plugin to automate generation of valid Bazel files for a given Android/Kotlin/Java project.

Grazel Grazel stands for Gradle to Bazel. It is a Gradle plugin that enables you to migrate Android projects to Bazel build system in an incremental a

Grab 228 Jan 2, 2023