{"id":15910546,"url":"https://github.com/2bab/polyfill","last_synced_at":"2025-03-22T08:30:49.090Z","repository":{"id":39796173,"uuid":"150435649","full_name":"2BAB/Polyfill","owner":"2BAB","description":"An artifact repository to assist writing Gradle Plugins for Android build system.","archived":false,"fork":false,"pushed_at":"2023-12-28T06:50:23.000Z","size":794,"stargazers_count":84,"open_issues_count":1,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-14T22:35:55.198Z","etag":null,"topics":["android","android-gradle-plugin","artifact","extend","polyfill","variant"],"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":"2018-09-26T14:00:16.000Z","updated_at":"2025-01-11T02:07:33.000Z","dependencies_parsed_at":"2022-08-09T15:25:59.460Z","dependency_job_id":"69030adf-a677-4da0-8e55-b7c8279a2f96","html_url":"https://github.com/2BAB/Polyfill","commit_stats":{"total_commits":226,"total_committers":2,"mean_commits":113.0,"dds":0.004424778761061954,"last_synced_commit":"86b198afbd5616c80eb54063cc11034a3577865e"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2BAB%2FPolyfill","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2BAB%2FPolyfill/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2BAB%2FPolyfill/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2BAB%2FPolyfill/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/2BAB","download_url":"https://codeload.github.com/2BAB/Polyfill/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244931366,"owners_count":20534005,"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":["android","android-gradle-plugin","artifact","extend","polyfill","variant"],"created_at":"2024-10-06T15:08:29.572Z","updated_at":"2025-03-22T08:30:48.566Z","avatar_url":"https://github.com/2BAB.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg src=\"./Polyfill.png\" alt=\"Polyfill\" width=\"507px\"\u003e\n\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/me.2bab/polyfill/badge.svg)](https://search.maven.org/artifact/me.2bab/polyfill)\n[![Actions Status](https://github.com/2bab/Polyfill/workflows/CI/badge.svg)](https://github.com/2bab/Polyfill/actions)\n[![Apache 2](https://img.shields.io/badge/License-Apache%202-brightgreen.svg)](https://www.apache.org/licenses/LICENSE-2.0)\n\n[English] [[中文]](./README_zh.md)\n\n🚧 **It's currently under incubating...**\n\nPolyfill is an artifact repository to assist writing Gradle Plugins for Android build system. It provides addtional artifacts in similar API styles of AGP Artifacts ones for third party plugin developers.\n\nIf you are not familiar with new Artifact/Variant API of AGP (since 7.0), please check the tutorial [Gradle and AGP build APIs - MAD Skills](https://www.youtube.com/playlist?list=PLWz5rJ2EKKc8fyNmwKXYvA2CqxMhXqKXX) by @AndroidDevelopers. More information can be found on \"Why Polyfill\" section below.\n\n\n## Quick Start\n\n1. Add Polyfill to dependencies of your Plugin project (standalone plugin project or `buildSrc`):\n\n``` kotlin\ndependencies {\n    compileOnly(\"com.android.tools.build:gradle:8.1.2\")\n    implementation(\"me.2bab:polyfill:0.9.1\")  \u003c--\n}\n```\n\n2. Apply the Polyfill plugin to your plugin before everything:\n\n``` Kotlin\nimport org.gradle.kotlin.dsl.apply\n\nclass TestPlugin : Plugin\u003cProject\u003e {\n    override fun apply(project: Project) {\n        project.apply(plugin = \"me.2bab.polyfill\")  \u003c--\n        ...\n    }\n}    \n```\n\n3. Config your `TaskProvider` (for `get/getAll()`) or `PolyfillAction`(for `use()` as well as `get/getAll()`) with the help of Polyfill's `variant.artifactsPolyfill.*` AIs, which has similar style with `variant.artifacts` ones of AGP:\n\n``` kotlin\nval androidExtension = project.extensions.getByType(ApplicationAndroidComponentsExtension::class.java)\nandroidExtension.onVariants { variant -\u003e\n\n    // get()/getAll()\n    val printManifestTask = project.tasks.register\u003cPreUpdateManifestsTask\u003e(\n        \"getAllInputManifestsFor${variant.name.capitalize()}\"\n    ) {\n        beforeMergeInputs.set(\n            variant.artifactsPolyfill.getAll(PolyfilledMultipleArtifact.ALL_MANIFESTS)  \u003c--\n        )\n    }\n    ...\n\n    // use()\n    val preHookManifestTaskAction1 = PreUpdateManifestsTaskAction(buildDir, id = \"preHookManifestTaskAction1\")\n    variant.artifactsPolyfill.use(\n        action = preHookManifestTaskAction1,\n        toInPlaceUpdate = PolyfilledMultipleArtifact.ALL_MANIFESTS\n    )\n}\n\n... \nclass PreUpdateManifestsTaskAction(\n    buildDir: File,\n    id: String\n) : PolyfillAction\u003cList\u003cRegularFile\u003e\u003e {\n\n    override fun onTaskConfigure(task: Task) {}\n\n    override fun onExecute(artifact: Provider\u003cList\u003cRegularFile\u003e\u003e) {\n        artifact.get().let { files -\u003e\n            files.forEach {\n                val manifestFile = it.asFile\n                // Check per manifest input and filter whatever you want, remove broken pieces, etc.\n                // val updatedContent = manifestFile.readText().replace(\"abc\", \"def\")\n                // manifestFile.writeText(updatedContent)\n            }\n        }\n    }\n    \n}\n```\n\nAll supported Artifacts are listed below: \n\n|PolyfilledSingleArtifact|Data Type|Description|\n|:---:|:---:|:---:|\n|MERGED_RESOURCES|`Provider\u003cDirectory\u003e`|To retrieve merged `/res` directory.|\n\n\n| PolyfilledMultipleArtifact |Data Type|                                       Description                                       |\n|:--------------------------:|:---:|:---------------------------------------------------------------------------------------:|\n|       ALL_MANIFESTS        |`ListProvider\u003cRegularFile\u003e`| To retrieve all `AndroidManifest.xml` regular files that will paticipate merge process. |\n|       ALL_RESOURCES        |`ListProvider\u003cDirectory\u003e`|         To retrieve all `/res` directories that will paticipate merge process.          |\n|        ALL_JAVA_RES        |`ListProvider\u003cRegularFile\u003e`|               To retrieve all Java Resources that will paticipate merge process.               |\n\nIn addition, `Artifact.Single\u003cFILE_TYPE\u003e`，`Artifact.Multiple\u003cFILE_TYPE\u003e` and their implementations such as `InternalArtifactType` are  supported by `get(...)/getAll(...)`. You can access more internal Artifacts of AGP through them.\n\n4. If aforementioned API sets are not satisfied for your requirement, a public data pipeline mechanism with a bunch of variant tools that provided by Polyfill are opening to customized Artifacts registry.（PR is welcome as well!)\n\n``` Kotlin\nproject.extensions.getByType\u003cPolyfillExtension\u003e()\n    .registerTaskExtensionConfig(DUMMY_SINGLE_ARTIFACT, DummySingleArtifactImpl::class)\n```\n\nCheck more examples in `./polyfill-test-plugin` and `./polyfill/src/functionalTest`.\n\n\n## Why Polyfill?\n\nAs its name suggests, the lib is a **middle-ware** between **AGP** (Android Gradle Plugin) and **3rd Gradle Plugin** based on AGP context. For example, the [ScratchPaper](https://github.com/2BAB/ScratchPaper) is a plugin to add an overlay to your app icons which based on AGP, it consumes:\n\n1. SDK Locations / BuildToolInfo instance (to run aapt2 commands)\n2. All input resource directories (to query the source of launcher icons)\n3. Merged AndroidManifest.xml (to get the resolved icon name)\n\nBy the time I created ScratchPaper, AGP does not provide any public API for above 3 items, I had to deal them with a few hacky hooks. In 2018, I started to consider if we can make a Polyfill layer for 3rd Android Gradle Plugin developers, and finally released the first version in 2020 as you can see here. The name \"Polyfill\" comes from the FrontEnd tech-stack, which makes the JS code compatible with old/odd browser APIs.\n\nSince AGP 7.0.0, the AGP team provides a new public API set called **\"Variant/Artifact API\"**. You can check all latest AGP exported Artifacts here: [SingleArtifact](https://developer.android.com/reference/tools/gradle-api/current/com/android/build/api/artifact/SingleArtifact), [MultipleArtifact](https://developer.android.com/reference/tools/gradle-api/current/com/android/build/api/artifact/MultipleArtifact) (On \"Known Direct Subclasses\" section). At this early stage AGP only provides less than 10 artifacts' API, **AGP released 2-3 minor versions per year, developers need to stay tuned for new Artifacts releasing.** Back to the example, only item 3 is provided by the new Artifacts API in public. For rest two items you may need to handle(hack) by yourself. to fulfill thoes requirements that are not satisfied by new Artifacts so far, probably we can:\n\n1. Raise requests to corresponding issue tracker thread of [AGP](https://issuetracker.google.com/issues?q=componentid:192709). \n2. In the meantime, create a similar data pipeline to populate our hooks as what `artifacts.use()/get()/getAll()` looks like, it's a temporary workaround and easy to migrate to official Artifacts API once available.\n\nThat's the reason why I created Polyfill and wish one day we can 100% migrate to Artifacts API. Find more Variant/Artifact API news from links below:\n\n- [gradle-recipes](https://github.com/android/gradle-recipes): An official repo for Variant/Artifact API showcases.\n- [New APIs in the Android Gradle Plugin](https://medium.com/androiddevelopers/new-apis-in-the-android-gradle-plugin-f5325742e614): A brief orientation for new Variant/Artifact API.\n- [Extend the Android Gradle plugin](https://developer.android.com/studio/build/extend-agp): The official doc of Variant/Artifact API that was released in Oct 2021.\n\n\n## Compatible Specification\n\nPolyfill is only supported \u0026 tested on latest **2** Minor versions of Android Gradle Plugin.\n\n**Changelog** can be found from [Github Releases](https://github.com/2BAB/Polyfill/releases).\n\n|  AGP Version  |      Latest Support Version      |\n|:-------------:|:--------------------------------:|\n| 8.1.x / 8.0.x |              0.9.1               |\n| 7.2.x / 7.1.x |              0.8.1               |\n| 7.2.x / 7.1.x |              0.7.0               |\n|     7.1.x     |              0.6.2               |\n|     7.0.x     |              0.4.1               |\n|     4.2.0     | 0.3.1 (Migrated to MavenCentral) |\n\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\nmake sure everyone will make a **meaningful** commit message.\n\nSo far we haven't added any hook tool, but follow the regex below:\n\n```\n(chore|feat|docs|fix|refactor|style|test|hack|release)(:)( )(.{0,80})\n```\n\n\n## License\n\n\u003e\n\u003e Copyright Since 2018 2BAB\n\u003e\n\u003e 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\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 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.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2bab%2Fpolyfill","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F2bab%2Fpolyfill","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2bab%2Fpolyfill/lists"}