Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions featured-gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ mavenPublishing {
}

dependencies {
compileOnly("com.android.tools.build:gradle:9.1.0")
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AGP version is hardcoded here even though the repo uses a version catalog (gradle/libs.versions.toml has agp = "9.1.0"). Consider sourcing this dependency version from the catalog to avoid drift when AGP is bumped.

Suggested change
compileOnly("com.android.tools.build:gradle:9.1.0")
compileOnly("com.android.tools.build:gradle:${libs.versions.agp.get()}")

Copilot uses AI. Check for mistakes.
testImplementation(gradleTestKit())
testImplementation(libs.kotlin.testJunit)
testImplementation(libs.r8)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package dev.androidbroadcast.featured.gradle

import com.android.build.api.variant.AndroidComponentsExtension
import org.gradle.api.Project
import org.gradle.api.tasks.TaskProvider

/**
* Wires the generated ProGuard rules file into every Android variant via the AGP Variant API.
*
* Called lazily — only when `com.android.application` or `com.android.library` is present on
* the project. The task dependency is implicit through the [TaskProvider] chain, so no explicit
* `dependsOn` is required.
*/
internal fun wireProguardToVariants(
project: Project,
proguardTask: TaskProvider<GenerateProguardRulesTask>,
) {
val androidComponents =
project.extensions
.getByType(AndroidComponentsExtension::class.java)
androidComponents.onVariants { variant ->
variant.proguardFiles.add(
proguardTask.flatMap { it.outputFile },
)
Comment on lines +21 to +24
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wires the generated rules into variant.proguardFiles for all variants. For Android library modules, proguardFiles affects only the library’s own minification, while consumers typically pick up rules via consumerProguardFiles (see e.g. providers/sharedpreferences/build.gradle.kts). If the intent is for consuming apps to benefit from dead-code elimination, you likely need to add the generated file as a consumer ProGuard file for library variants (or wire both appropriately for app vs library).

Copilot uses AI. Check for mistakes.
}
Comment on lines +14 to +25
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This introduces new behavior that depends on the AGP Variant API (wiring into variants). There are unit tests for task registration, but no tests exercising this wiring on an actual Android project/variant (e.g., via Gradle TestKit) to verify the generated file is added for release variants and library consumer rules as intended. Adding an integration-style test would help prevent regressions across AGP upgrades.

Copilot uses AI. Check for mistakes.
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,15 @@ public class FeaturedPlugin : Plugin<Project> {

registerConfigParamTask(target, resolveTask)
registerFlagRegistrarTask(target, resolveTask)
registerProguardTask(target, resolveTask)
val proguardTask = registerProguardTask(target, resolveTask)
registerIosConstValTask(target, resolveTask)
registerXcconfigTask(target, resolveTask)
wireToRootAggregator(target, resolveTask)
listOf("com.android.application", "com.android.library").forEach { pluginId ->
target.plugins.withId(pluginId) {
wireProguardToVariants(target, proguardTask)
}
}
Comment on lines +58 to +62
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wireProguardToVariants() is only registered for com.android.application and com.android.library. This repo also applies com.android.kotlin.multiplatform.library (Android KMP) in multiple modules (e.g. core/build.gradle.kts), so those Android variants won't get the generated ProGuard rules automatically. Consider adding that plugin id (and any other Android plugin ids you support) to this wiring list so the behavior matches the PR's goal of auto-wiring for Android projects.

Copilot uses AI. Check for mistakes.
}

private fun registerResolveFlagsTask(target: Project): TaskProvider<ResolveFlagsTask> =
Expand Down Expand Up @@ -99,7 +104,7 @@ public class FeaturedPlugin : Plugin<Project> {
private fun registerProguardTask(
target: Project,
resolveTask: TaskProvider<ResolveFlagsTask>,
) {
): TaskProvider<GenerateProguardRulesTask> =
target.tasks.register(GENERATE_PROGUARD_TASK_NAME, GenerateProguardRulesTask::class.java) { task ->
task.group = "featured"
task.description = "Generates ProGuard/R8 -assumevalues rules for local flags in '${target.path}'."
Expand All @@ -108,7 +113,6 @@ public class FeaturedPlugin : Plugin<Project> {
task.outputFile.set(target.layout.buildDirectory.file("featured/proguard-featured.pro"))
task.dependsOn(resolveTask)
}
}

private fun registerIosConstValTask(
target: Project,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,8 @@ import org.gradle.api.tasks.TaskAction
* [ExtensionFunctionGenerator], so R8 can propagate the exact constant and eliminate
* dead branches in release builds.
*
* Wire the generated file into your Android module's ProGuard configuration:
* ```kotlin
* android {
* buildTypes {
* release {
* proguardFiles(
* getDefaultProguardFile("proguard-android-optimize.txt"),
* layout.buildDirectory.file("featured/proguard-featured.pro").get().asFile,
* )
* }
* }
* }
* ```
* For Android projects the generated file is automatically wired into all variants via the
* AGP Variant API — no manual ProGuard configuration is required.
*/
@CacheableTask
public abstract class GenerateProguardRulesTask : DefaultTask() {
Expand Down
Loading