{"id":17880795,"url":"https://github.com/2bab/bundle-tool-gradle-plugin","last_synced_at":"2025-03-22T08:31:14.785Z","repository":{"id":43060589,"uuid":"437886029","full_name":"2BAB/bundle-tool-gradle-plugin","owner":"2BAB","description":"A Gradle Plugin for Android BundleTool.","archived":false,"fork":false,"pushed_at":"2023-12-30T02:15:08.000Z","size":489,"stargazers_count":60,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-14T22:35:54.386Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/2BAB.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-12-13T13:35:29.000Z","updated_at":"2025-03-10T05:22:23.000Z","dependencies_parsed_at":"2024-10-28T12:55:46.523Z","dependency_job_id":"f4e24f1f-678f-4c26-96cf-867e04bc6513","html_url":"https://github.com/2BAB/bundle-tool-gradle-plugin","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2BAB%2Fbundle-tool-gradle-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2BAB%2Fbundle-tool-gradle-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2BAB%2Fbundle-tool-gradle-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2BAB%2Fbundle-tool-gradle-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/2BAB","download_url":"https://codeload.github.com/2BAB/bundle-tool-gradle-plugin/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244931480,"owners_count":20534008,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-28T12:28:39.425Z","updated_at":"2025-03-22T08:31:12.434Z","avatar_url":"https://github.com/2BAB.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg src=\"./banner.png\" alt=\"bundle tool gradle plugin\" width=\"771px\"\u003e\n\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/me.2bab/bundle-tool-plugin/badge.svg)](https://search.maven.org/artifact/me.2bab/bundle-tool-plugin)\n[![Actions Status](https://github.com/2bab/bundle-tool-gradle-plugin/workflows/CI/badge.svg)](https://github.com/2bab/bundle-tool-gradle-plugin/actions)\n[![Apache 2](https://img.shields.io/badge/License-Apache%202-brightgreen.svg)](https://www.apache.org/licenses/LICENSE-2.0)\n\nA Gradle Plugin for Android BundleTool, powered by [New Variant/Artifact API](https://developer.android.com/studio/build/extend-agp) \u0026 [Polyfill](https://github.com/2BAB/Polyfill). It supports:\n\n1. Generate **\".apks\"** artifacts by `build-apks` command.\n2. Install **\".apks\"** artifacts by `install-apks` command.\n3. Calculate **\".apks\"** size by `get-size total` command and export to **\".csv\"** files.\n4. When running `build-apks` command in Universal build mode, it also extracts universal **\".apk\"** artifact.\n5. The plugin features can be enabled/disabled for per variant respectively.\n\n## Usage\n\n**0x01. Add the plugin to classpath:**\n\n``` kotlin\nbuildscript {\n    repositories {\n        ...\n        mavenCentral()\n    }\n    dependencies {\n        classpath(\"com.android.tools.build:gradle:8.1.2\")\n        classpath(\"me.2bab:bundle-tool-plugin:1.3.0\")\n    }\n}\n```\n\n**0x02. Apply Plugin:**\n\n``` kotlin\n// For your application module\nplugins {\n    id(\"me.2bab.bundletool\")\n}\n```\n\n**0x03. Advanced Configurations**\n\n``` kotlin\nimport me.xx2bab.bundletool.*\n\n// Run `./gradlew TransformApksFromBundleForStagingDebug` for testing all features.\nbundleTool {\n    // The plugin can be enabled by variant, for instance,\n    // BundleToolFeature.GET_SIZE feature is disabled for \"productionDebug\" buildTypes,\n    // BundleToolFeature.INSTALL_APKS feature is enabled for \"debug\" buildTypes only,\n    // while other combinations are supported/enabled.\n    enableByVariant { variant, feature -\u003e\n        when(feature) {\n            BundleToolFeature.GET_SIZE -\u003e {\n                !(variant.buildType == \"debug\" \u0026\u0026 variant.flavorName == \"production\")\n            }\n            BundleToolFeature.INSTALL_APKS -\u003e {\n                variant.buildType == \"debug\"\n            }\n            else -\u003e true\n        }\n    }\n\n    // Each of them will create a work action with `build-apks` command.\n    buildApks {\n        create(\"universal\") {\n            buildMode.set(ApkBuildMode.UNIVERSAL.name)\n        }\n        create(\"pixel4a\") {\n            deviceSpec.set(file(\"./pixel4a.json\"))\n            // `deviceId` will be used for INSTALL_APKS feature only,\n            // set the `deviceId` to indicate that you want to install the apks after built.\n            deviceId.set(pixel4aId)\n        }\n        create(\"pixel6\") {\n            deviceSpec.set(file(\"./pixel6.json\"))\n        }\n    }\n    \n    // Each of them will create a work action for above \"buildApks\" list items' output.\n    getSize {\n        create(\"all\") {\n            dimensions.addAll(\n                GetSizeDimension.SDK.name,\n                GetSizeDimension.ABI.name,\n                GetSizeDimension.SCREEN_DENSITY.name,\n                GetSizeDimension.LANGUAGE.name\n            )\n        }\n    }\n}\n```\n\n**0x04. Build your App and Enjoy!**\n\n```shell\n# Please check \"enableByVariant\" config to ensure you are running the one\n# that enabled features you want already.\n./gradlew TransformApksFromBundleForStagingDebug\n```\n![](./transform_result.png)\n\n**0x05. Extend the build flow. (Optional)**\n\nIf you would like to do something after bundletool's execution, \"to upload all those products\" for example. This plugin provides the output directory `Provider` for other developers to use, check the sample below:\n\n```kotlin\n// Run `./gradlew UploadApksForStagingDebug` for testing.\nandroidComponents {\n    // Pls use the same rule as `enableByVariant{...}` over\n    onVariants(selector().withBuildType(\"debug\")) { variant -\u003e\n        tasks.register\u003cUploadTask\u003e(\"UploadApksFor${variant.name.capitalize()}\") {\n            // You must apply the \"me.2bab.bundletool\" in the build script\n            // or in your plugin before calling `variant.getBundleToApksOutputDir()`.  \n            this.outputDirProperty.set(variant.getBundleToApksOutputDir())\n        }\n    }\n}\n\nabstract class UploadTask : DefaultTask() {\n\n    @get:org.gradle.api.tasks.InputDirectory\n    abstract val outputDirProperty: DirectoryProperty\n\n    @org.gradle.api.tasks.TaskAction\n    fun upload() {\n        outputDirProperty.get().asFile.listFiles().forEach { artifact -\u003e\n            logger.lifecycle(\"Uploading bundle-tool outputs: ${artifact.absolutePath}\")\n            // upload(artifact)\n        }\n    }\n}\n```\n\n## Compatible\n\nbundle-tool-gradle-plugin is only supported \u0026 tested on LATEST 2 Minor versions of Android Gradle Plugin.\n\n| AGP    | BundleTool | bundle-tool-gradle-plugin |\n|--------|------------|---------------------------|\n| 8.1.x  | 1.14.0     | 1.3.0                     |\n| 7.1.x  | 1.8.0      | 1.2.0                     |\n| 7.0.x  | 1.6.0      | 1.1.0                     |\n\nTips:\n\n1. How to swiftly find the companion BundleTool version from AGP: create/open a vanilla Android project, take a look at the *External Libraries* -\u003e *Gradle Script dependencies* -\u003e you will see something like *builder-8.1.2-sources.jar* \u0026 *bundletool-1.14.0.jar*, which means the AGP 8.1.2 uses the BundleTool 1.14.0.  \n2. How to determine the BundleTool features' compatibility: check the [`VersionGuardedFeature`](https://github.com/google/bundletool/blob/0b00e4a8d3129cdfa2a98119fe7a3373ff49cdd3/src/main/java/com/android/tools/build/bundletool/model/version/VersionGuardedFeature.java) Enumeration file.\n\n## Git Commit Check\n\nCheck this [link](https://medium.com/walmartlabs/check-out-these-5-git-tips-before-your-next-commit-c1c7a5ae34d1) to make sure everyone will make a **meaningful** commit message.\n\nSo far we haven't added any hook tool, but follow a regex rule like below:\n\n```\n(chore|feature|clean|upgrade|docs|fix|refactor|style|test|hack|release)(:)( )(.{0,80})\n```\n\n## License\n\n\u003e\n\u003e Copyright 2016-2022 2BAB\n\u003e\n\u003eLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\u003e\n\u003e   http://www.apache.org/licenses/LICENSE-2.0\n\u003e\n\u003e Unless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2bab%2Fbundle-tool-gradle-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F2bab%2Fbundle-tool-gradle-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2bab%2Fbundle-tool-gradle-plugin/lists"}