Skip to content

Apply configuration new variants API only when Plugins are present #414

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 13, 2023

Conversation

cdsap
Copy link
Member

@cdsap cdsap commented Jan 13, 2023

Issue #412 describes the issue when using AGP 7.4 and the Plugin throws:

Failed to apply plugin 'org.gradle.android.cache-fix'.
> Cannot invoke method selector() on null object

This is caused when the plugin is configuring a project without Android plugins applied.
I can reproduce the error when in the project nowinandroid I remove the apply false in the plugin definition. That means the rootProject is trying to retrieve the androidComponents:

 def androidComponents = project.extensions.findByName("androidComponents")

when they are not applied. This is a change in the AGP not reproducible in 7.3.1.

Similar to the old implementation this PR only applies the configuration when a project contains the Android plugins.

@eboudrant
Copy link

I looked also and noticed we apply the plugin using this in our root build.gradle:

subprojects { subProject ->
    apply plugin: "org.gradle.android.cache-fix"

The error probably happen because we apply it regardless it's a project with or without android plugin. We should probably fix our build script too, thanks for looking quickly at the issue!

@cdsap cdsap marked this pull request as ready for review January 13, 2023 19:46
@cdsap cdsap requested a review from a team January 13, 2023 19:46
Copy link
Contributor

@runningcode runningcode left a comment

Choose a reason for hiding this comment

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

let's add a test for this as well.

@cdsap
Copy link
Member Author

cdsap commented Jan 13, 2023

@runningcode added unit tests covering plugin block configuration with/wo applying the plugin by default

@cdsap cdsap merged commit f120fa4 into main Jan 13, 2023
@cdsap cdsap deleted the apply_new_variant_by_plugin branch January 13, 2023 23:36
@cdsap cdsap mentioned this pull request Jan 14, 2023
configureNewVariants(project, configureVariants)
}

project.plugins.withId("com.android.library") {
Copy link

Choose a reason for hiding this comment

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

It's already merged, but shouldn't the plugin also apply to modules that use com.android.test plugin?

Choose a reason for hiding this comment

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

I think it should also apply to modules with com.android.dynamic-feature plugin.

Copy link
Member Author

Choose a reason for hiding this comment

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

@daio @eboudrant you're right.
Checking the hierarchy of the plugins:
Screen Shot 2023-01-15 at 10 38 40 AM
I'm wondering if checking by com.android.base would be enough. Next week will work on this

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.

4 participants