Capacitor Plugin- Gradle Keeps Downloading Android SDK 34

I have a Capacitor plugin that interfaces to the Lua scripting language, which allows Lua scripts to run from our Ionic/Capacitor mobile app.

I created the Capacitor plugin with the @capacitor/create-plugin package using “npx”. I can build my plugin from the command line by doing a “cd” to the android folder of the plugin, and then executing “./gradlew build”. It builds the plugin successfully and the plugin works. However, Gradle keeps trying to use the Android-34 SDK platform tools, and Gradle automatically downloads that version of the SDK if it is not present in my Android SDK folder.

I don’t want to use Android-34 SDK, but I want the build process to use Android-35 SDK.

I can’t figure out how to modify the build.gradle file to tell it to use Android-35 SDK. It seems like maybe I need to upgrade the AGP (Android Gradle Plugin) to a newer version, and then maybe it will use a newer version of the Android SDK. But I can’t really tell. And I’m even not sure if the Capacitor build framework will support using a newer version of AGP.

Can anyone help to get my Capacitor plugin Gradle system to stop downloading and using Android-34 and start using Android-35 (or Android-36) instead?

Thank you!

Can you try running the command adding @latest at the end to make sure you are getting latest update?

i.e. npx @capacitor/create-plugin@latest

1 Like

Re-creating the plugin from scratch like that is laborious, because you then have to go through all the files you customized and make the customizations again. Plus add all the source files in. Try to get everything just right so it will build again.

But it solved the problem, and it no longer tries to download & use the Android 34 API every time I do a gradle build. I spent some time comparing the resulting files in the new plugin, with the old files in the previous plugin with the problem. I could not find the difference. But it doesn’t matter, the problem is fixed.

So this brings the question: Each time there is a capacitor upgrade, must I recreate the plugin from scratch like that and recreate all the modifications and source files to guarantee that “everything” is upgraded and nothing is missed? I followed the guide on this web set when I upgraded this plugin from Capacitor 6.x to Capacitor 7.x, but apparently it wasn’t enough to upgrade “everything”. Or maybe I missed a step-- it’s hard to know since it was a while ago.

I was assuming it was a new plugin you just created, that’s why I recommended recreating it using @latest to make sure you were getting the latest generator.

For updating existing plugins we have a different command, npx @capacitor/plugin-migration-v6-to-v7@latest, but that’s mentioned in the guide you’ve read, not sure if you ran the command of if you followed the steps.

What determines the SDK is the compileSdkVersion and targetSdkVersion, documented here

Yes that’s the exact guide that I followed. I updated the files manually. There are 7 plugins in our mobile application, and I go through those manual steps for each of them. It was several months ago that I did that, so I don’t recall any of the details. But for whatever reason, updating the files according to that guide did not do the same thing as recreating the plugin from scratch. I was not able to determine what was different.