Plugin throwing NoSuchMethodError on RecipeExecutor.save when creating a project from a custom template
Hi,
I want to create a plugin for Android Studio which adds a new project template. This template would be an Android project with additional files.
I created a plugin project in Intellij IDEA with the following build.gradle:
plugins {
id 'org.jetbrains.intellij' version '1.3.0'
id 'org.jetbrains.kotlin.jvm' version '1.6.0'
id 'java'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib"
}
intellij {
version = '203.7717.56'
type = 'IC'
plugins = ['android','java']
}
runIde {
ideDir = project.file('/opt/android-studio-2020.3.1.25-linux/android-studio')
}
I execute the task "runIde", Android Studio starts correctly with my plugin, I can see my template when creating a new project, but when I validate the creation, I get the following error:
Caused by: java.lang.NoSuchMethodError: 'void com.android.tools.idea.wizard.template.RecipeExecutor$DefaultImpls.save$default(com.android.tools.idea.wizard.template.RecipeExecutor, java.lang.String, java.io.File, boolean, boolean, int, java.lang.Object)'
It seems that the version of the Android API used to compile the plugin in not the same than the one used to execute it. The number of arguments of the method RecipeExecutor.save has changed in a recent version.
I set the Intellij platform version to 203.7717.56 since it is the base version of Android Studio 2020.3.1.
My Recipe is pretty simple:
fun RecipeExecutor.watchface(moduleData: ModuleTemplateData) {
val mainFolder = "src/main/"
createDirectory(File("${mainFolder}/java"))
createDirectory(File("${mainFolder}/resources"))
save("Sample text", File("${mainFolder}/java/MyFiletxt"))
}
What did I miss?
Please sign in to leave a comment.
Hi Thomas Delhomenie,
IDEA 2020.3 = IntelliJ Platform 2020.3 + Android Plugin 10.4.0
Android Studio 2020.3 = IntelliJ Platform 2020.3 + Android Plugin 2020.3.1 Final
IDA 2021.3 = IntelliJ Platform 2021.3 + Android Plugin 2020.3.1 Final
The class `com.android.tools.idea.wizard.template.RecipeExecutor` is from Android Plugin, that's why you need to match Android Plugin version, not platform version, to avoid `NoSuchMethodError`.
There are two possible solutions:
1. Use IDEA version that has Android Plugin 2020.3.1 on the board
2. Develop against Android Studio directly (see `
intellij.localPath
` attribute: https://github.com/JetBrains/gradle-intellij-plugin)Thanks for your answer!
I tried to use the version 213.5744.223 but the plugin is not loaded because of this error:
I test the plugin in the version 2020.3.1.25 of Android Studio.
Your second solution is the one I found also, it works fine, but I would like to avoid if possible since it is less portable.
By default intellij-gradle-plugin adds "
since-build
" and "until-build
" versions to plugin.xml that match selected IDE version (213 in your case). You can set compatibility range explicitly via `sinceBuild` and `untilBuild` attributes. E.g.sinceBuild="203.7717.56"
untilBuild="203.7717.56.*"
Ref.: https://github.com/JetBrains/gradle-intellij-plugin#patching-dsl
Another thing that you can do is you can create a gradle task that will download Android Studio from the internet (e.g., via direct link) and unzip it to some subdirectory of the `build` directory, and use it as `intellij.localPath`.
This works fine with the sinceBuild and untilBuild attributes, thanks a lot!