Different gradle configurations depending on the way the android project is created


I would like to add some native code to my app.
As a starting point, I worked through the capacitor plugin guide which sets up a project with:

npx @capacitor/cli plugin:generate

Based on this template, I implemented the functionality and a small app that tests it (it’s really minimal).
By the way: It’s really a pleasure to work with capacitor. The plugin system works like a charm.

Now I need to port the functionality over to my actual project. Since it is not published to npm or anything, I would just like to copy over the Java/Kotlin code.

This brings up a problem: The gradle build systems that are created for a plugin project and for a “normal” ionic project with ionic cap add android seem very different.
For example, the project that was created for my plugin relies on google-services 4.3.3 and brings in an androidX dependency. While the project that is set up with ionic cap android only needs google-services 4.2.0 and no androidX. The file structure is very different, too. The plugin build system extracts lots of variables out to separate files, etc.

So far there was no custom android code in my project. So I deleted android/ and build/, updated all npm packages, both local and global, then recreated the android code.
It’s still the same: old google services, no androidX.

I think it should be straightforward to configure gradle to bring in the dependencies that my plugin code needs.
But to be honest, gradle is a bit scary to me. In my experience it’s super unstable and tends to go haywire when you misconfigure something.
So if possible, I would like to avoid reconfiguring the gradle buildchain.
Is there a way to set up ionic cap android to generate the same basis as for plugin development?

And what is the correct way to version control this?
Usually, I always add gradle to git. But then again, here it is created automatically. So that would be a good reason to keep it out of the repository. How do you deal with this?

The answer is quite simple:
I messed up the npm update process.

The gradle configuration seems to depend only on the versions of @capacitor/cli installed in your dev dependencies.
After upgrading that to the latest version, the android buildchain is also updated.