Skip to content

Make Protobuf Gradle Plugin AGP 9 compatible#797

Open
omarismail94 wants to merge 3 commits intogoogle:masterfrom
omarismail94:master
Open

Make Protobuf Gradle Plugin AGP 9 compatible#797
omarismail94 wants to merge 3 commits intogoogle:masterfrom
omarismail94:master

Conversation

@omarismail94
Copy link

@omarismail94 omarismail94 commented Jan 30, 2026

Establish AGP 8.7 as the minimum supported version and adhere to the new Variant APIs. This ensures forward compatibility with AGP 9.0 while optimizing for the majority of the active ecosystem.

To achieve forward compatibility with AGP 9, the plugin must eliminate all reliance on the "Old Variant API" (BaseVariant, AppExtension, registerJavaGeneratingTask).

The PR does the following

In the first commit, we upgrade to Gradle 8.9 and Java 17

  • Upgrade Gradle Wrapper to 8.9 in project and examples.
  • Update build.gradle dependencies and configuration for Gradle 8.9 compatibility.
  • Update Spock to version 2.3-groovy-3.0.
  • Fix CodeNarc violations and resolve Groovy static compilation issues.
  • Update Android test projects to use 'namespace' DSL and remove 'package' attribute from manifests to support Android Gradle Plugin 8.0+.
  • Update test matrices to use AGP versions compatible with Gradle 8.9 (e.g., 8.1.0, 8.3.0, 8.13.0).
  • Fix 'assertJavaCompileHasProtoGeneratedDir' verification in test projects to work with configuration caching changes.

In the second commit we upgrade to AGP 8.7.3 and migrate to the variant API:

  • Upgrade project dependency to Android Gradle Plugin 8.7.3.
  • Migrate ProtobufPlugin to use the AndroidComponentsExtension (Variant API) instead of the deprecated BaseVariant API.
  • Replace registerJavaGeneratingTask with variant.sources.java.addGeneratedSourceDirectory for source registration.
  • Remove ProjectExt and legacy variant iteration logic.
  • Remove deprecated AndroidSourceSet extension in Kotlin.

FIXES: Issue #787 , #793

TESTED:

  • Compilation passed: Ran ./gradlew assemble
  • All tests passed: Ran ./gradlew test
  • Published local snapshot, uploaded to AndroidX, and set android.newDsl to true and the build passed. See here

- Upgrade Gradle Wrapper to 8.9 in project and examples.
- Update build.gradle dependencies and configuration for Gradle 8.9 compatibility.
- Update Spock to version 2.3-groovy-3.0.
- Fix CodeNarc violations and resolve Groovy static compilation issues.
- Update Android test projects to use 'namespace' DSL and remove 'package' attribute from manifests to support Android Gradle Plugin 8.0+.
- Update test matrices to use AGP versions compatible with Gradle 8.9 (e.g., 8.1.0, 8.3.0, 8.13.0).
- Fix 'assertJavaCompileHasProtoGeneratedDir' verification in test projects to work with configuration caching changes.
- Upgrade project dependency to Android Gradle Plugin 8.7.3.
- Migrate `ProtobufPlugin` to use the `AndroidComponentsExtension` (Variant API) instead of the deprecated `BaseVariant` API.
- Replace `registerJavaGeneratingTask` with `variant.sources.java.addGeneratedSourceDirectory` for source registration.
- Remove `ProjectExt` and legacy variant iteration logic.
- Remove deprecated `AndroidSourceSet` extension in Kotlin.
Refactors ProtobufAndroidSupport.groovy to improve readability and maintainability.
- Uses HostTest and DeviceTest for variant type checks.
- Simplified source set inclusion logic.
- Updated ProtobufExtension to expose mainSourceSet.
- Bumped minimum Gradle and Android Plugin versions in tests to handle
  inclusion of HostTest and DeviceTest classes
@michnovka
Copy link

Hello, wondering if this is merge ready, or we need something to be done? This is the last blocker for us to move to AGP9 fully. Thanks!

@omarismail94
Copy link
Author

@michnovka Im just waiting for someone from the owning team to review the change. The regular reviewer is out of office this week, but will try to find someone else. If I don't, then expect it to be reviewed next week

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants