Skip to content

Add support for Android projects with new DSL i.e. built-in Kotlin#1016

Merged
wakingrufus merged 5 commits intoJLLeitschuh:mainfrom
mannodermaus:new-android-api-support
Feb 10, 2026
Merged

Add support for Android projects with new DSL i.e. built-in Kotlin#1016
wakingrufus merged 5 commits intoJLLeitschuh:mainfrom
mannodermaus:new-android-api-support

Conversation

@mannodermaus
Copy link
Copy Markdown
Contributor

@mannodermaus mannodermaus commented Dec 18, 2025

Android Gradle Plugin 9.0 introduces support for Android projects using "built-in Kotlin" (reference), a new way of integration between the AGP and Kotlin. The current Ktlint Gradle plugin doesn't recognize projects with this setup, because these projects don't rely on the org.jetbrains.kotlin.android plugin. Instead, a common way to approach this is to hook into the pairing of the com.android.base and KotlinBaseApi plugins (here is an example).

Resolves #1008.

@mannodermaus mannodermaus force-pushed the new-android-api-support branch from 7e5ec73 to 9fd1946 Compare January 5, 2026 05:36
Copy link
Copy Markdown
Owner

@JLLeitschuh JLLeitschuh left a comment

Choose a reason for hiding this comment

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

This looks fine to me, but I really want feedback from @wakingrufus

@JLLeitschuh
Copy link
Copy Markdown
Owner

Sorry this has taken us so long to look at. I've been rather unplugged the past few weeks with the holidays. We appreciate the contribution!

@JLLeitschuh
Copy link
Copy Markdown
Owner

Ah, first failure, this PR is going to need to have a CHANGELOG.md file addition in order to be accepted.

@mannodermaus
Copy link
Copy Markdown
Contributor Author

No worries at all! I hope you had a relaxing time over the holidays. 😊 I added a changelog entry as requested.

@wakingrufus
Copy link
Copy Markdown
Collaborator

I had a suggestion in the linked issue about using plugin Id which I think we should do

@mannodermaus mannodermaus force-pushed the new-android-api-support branch from 36d9419 to b9ee86c Compare January 28, 2026 23:18
@mannodermaus
Copy link
Copy Markdown
Contributor Author

In b9ee86c, I updated the integration test to the stable release of AGP 9.0.0 and refactored the reflective access slightly.

It seems that the com.android.base + KotlinBaseApiPlugin route is becoming more and more canonized by other projects wanting to support the built-in Kotlin route. While I'd prefer to remove the Class.forName lookup, we would need to bump the project's Kotlin version to something newer than 1.5 first...

@ShadowRZ
Copy link
Copy Markdown

@mannodermaus You can try with Kotlin 1.7.20, it should have the org.jetbrains.kotlin.gradle.plugin.KotlinBaseApiPlugin class.

Althought I'm not sure why this plugin used this very low Kotlin version.

@wakingrufus
Copy link
Copy Markdown
Collaborator

@mannodermaus You can try with Kotlin 1.7.20, it should have the org.jetbrains.kotlin.gradle.plugin.KotlinBaseApiPlugin class.

Althought I'm not sure why this plugin used this very low Kotlin version.

The project uses 2.2.21. we target a lower API for backwards compatibility

minimumJava = 11,
maximumJava = 17
),
AGP_9_0(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think this case should be for AGP 8.8.0, then TestVersions.maxAgpVersion should be changed to 9.0.0
with this change, I think this PR is ready to merge. thanks for doing this work!

@wakingrufus
Copy link
Copy Markdown
Collaborator

wakingrufus commented Jan 29, 2026

In b9ee86c, I updated the integration test to the stable release of AGP 9.0.0 and refactored the reflective access slightly.

It seems that the com.android.base + KotlinBaseApiPlugin route is becoming more and more canonized by other projects wanting to support the built-in Kotlin route. While I'd prefer to remove the Class.forName lookup, we would need to bump the project's Kotlin version to something newer than 1.5 first...

we can increase the baseline kotlin version with the next major version update
feel free to add a TODO to remind us to revisit this when that happens

@mannodermaus
Copy link
Copy Markdown
Contributor Author

I think this case should be for AGP 8.8.0, then TestVersions.maxAgpVersion should be changed to 9.0.0 with this change, I think this PR is ready to merge. thanks for doing this work!

we can increase the baseline kotlin version with the next major version update feel free to add a TODO to remind us to revisit this when that happens

Made the corresponding changes in 36735e9!

@StefMa
Copy link
Copy Markdown

StefMa commented Feb 10, 2026

Hey guys ✌️

I just updated our code using AGP 9, checked out @mannodermaus branch, pushed to maven local and tested it against our code.
I can confirm that it worked 🙃

With the current version, it reports
Screenshot 2026-02-10 at 10 02 01 AM

But using 14.1.0-dev.15+new.android.api.support.36735e9 from local maven, it finds the task and detect issues 🥳
Screenshot 2026-02-10 at 10 02 37 AM

From my side this is good to go.
Any other blockes for this @wakingrufus @JLLeitschuh ?

@wakingrufus wakingrufus merged commit f465518 into JLLeitschuh:main Feb 10, 2026
23 checks passed
@StefMa
Copy link
Copy Markdown

StefMa commented Feb 10, 2026

@wakingrufus can we also do a release ? 🫣 😁

@mannodermaus mannodermaus deleted the new-android-api-support branch February 11, 2026 07:47
@wakingrufus
Copy link
Copy Markdown
Collaborator

@wakingrufus can we also do a release ? 🫣 😁

Yeah I'll try to get to this tomorrow

hugoncosta pushed a commit to hugoncosta/ktlint-gradle that referenced this pull request Feb 15, 2026
…LLeitschuh#1016)

* Add support for Android projects with new DSL i.e. built-in Kotlin

* Add tests for AGP 9.0 with built-in Kotlin

* Add changelog entry

* Update test to AGP 9.0.0 stable & tidy up lookup in the plugin

* Add todo & change Android plugin tests around
@flaringapp
Copy link
Copy Markdown

Kindly ask you to publish a new release with this fix 🙏

@wakingrufus
Copy link
Copy Markdown
Collaborator

Yes. Sorry for the delay, I am working on some other possible inclusions for this release. It will come soon

@katajona-hero
Copy link
Copy Markdown

What is the current status of the new release?

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.

Add support for AGP 9 with built-in Kotlin

7 participants