How to configure my plugin for working both with IntelliJ and Android Studio
Hello,
I'm (almost) a beginner in plugin creation (I created one a long time ago) and I would like to create a plugin that works BOTH with IntelliJ and with Android Studio (this to start with, because later I would like it to work also for Webstorm, PyCharm...). The principle is to use the parsing provided by IntelliJ (for Java for the moment, later for Kotlin, PHP...) thanks to the PSI. I've spent days reading and testing information at https://plugins.jetbrains.com/docs/intellij (and so on) and online tutorials, but I still can't configure my project (even before coding it). Can you help me?
Here is some information:
- I created the plugin ('empty' plugin for now) from the github template presented the online documentation. No problem for that I guess.
- I use a JDK 11. I guess this is what I have to do now (unlike before when I had to use the IntelliJ JDK).
- I want to code my plugin in Java (not in Kotlin). The template generated Kotlin code (MyBundle.kt, listeners, services...). What to write to replace these code in Java ?
- I don't know Kotlin (or very very little) and I usually develop in Java with Android Studio and Gradle. Should I keep the build.gradle.kst or replace it by build.gradle (and if yes, what to put in it ?) ? The formats of the parameters in these "build.gradle" are often written for one or the other and it is difficult for me to find my way around.
- When I'll have succeeded in this step, I must also add a library (a jar) for my plugin to work. Do I only have to add this jar in the libraries of the 'project settings' or do I have to do something else?
- Finally, when I run my 'empty' plugin, I get the errors :
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.intellij.ui.JreHiDpiUtil to method sun.java2d.SunGraphicsEnvironment.isUIScaleEnabled()
WARNING: Please consider reporting this to the maintainers of com.intellij.ui.JreHiDpiUtil
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
2022-02-28 14:35:43,095 [ 12910] WARN - j.internal.DebugAttachDetector - Unable to start DebugAttachDetector, please add `--add-exports java.base/jdk.internal.vm=ALL-UNNAMED` to VM options
2022-02-28 14:35:52,544 [ 22359] WARN - .diagnostic.PerformanceWatcher - UI was frozen for 8674ms, details saved to C:\Users\Jean-Claude\IdeaProjects\pluginTemplateGradle_1\build\idea-sandbox\system\log\threadDumps-freeze-20220228-143548-IC-211.7628.21-8sec
Is this normal? If not, what to do?
I join my gradle.properties and plugin.xml files (Upload id: 2022_03_01_E9bT1d2SGKmmFc7M (files: plugin.xml, gradle.properties)
Thanks for your help...
JC
Please sign in to leave a comment.
Hi,
Answers below.
You can remove Kotlin-related configuration from the gradle.build.kts file, so:
kotlinOptions.jvmTarget = it
}
After that remove src/main/kotlin and src/test/kotlin directories and create src/main/java and src/test/java. I hope the rest is obvious.
I suggest keeping the build.gradle.kts file. Groovy gradle.build file is IMHO harder to maintain and by using the Kotlin Script approach, it will be easier to update your build file when we update the template.
No, you should add it as Gradle project dependencies, e.g.:
build.gradle.kts:
Regarding the "errors", you can safely ignore them as they are warnings, not errors.
Thank you. I adapted my files as shown below. It seems that my empty plugin is well recognized by Android Studio and IntelliJ.
Do I need to write platformPlugins =['android','java'] to manage Java and Android code with my plugin in IntelliJ and Android Studio ?
Hi,
In the "platformPlugins" property you should add plugins that contain classes and functionalities required by your plugin. If you e.g., access Java PSI classes, then you should include com.intellij.java. If you plan to develop a plugin for Android Studio, take a look at:
https://plugins.jetbrains.com/docs/intellij/android-studio.html
Please note this is comma-separated list, without brackets.
Yes, as I said in the first post:
Here is my current configuration :
Hi,
Regarding:
No, it should be com.intellij.modules.java or com.intellij.java, depending on the versions you want to target, see:
https://plugins.jetbrains.com/docs/intellij/plugin-compatibility.html#modules-specific-to-functionality
and explanations under the table for the details.
Regarding:
It's not correct, see: https://plugins.jetbrains.com/docs/intellij/android-studio.html#configuring-the-plugin-buildgradle-file
Once you fix the above, the below should work:
Regarding:
The "android" plugin is important, the platform version from your file should be fine.
It is better, but I still have one problem in plugin.xml with android studio (see below). What to do ?
In build.gradle.KTS (I didn’t keep build.gradle as you proposed):
In gradle.properties, what to write?
In plugin.xml, always the same error with android studio:
Hi,
Did you configure the runIde task according to:
https://plugins.jetbrains.com/docs/intellij/android-studio.html#configuring-the-plugin-pluginxml-file
so it points to Android Studio installation?
Also, please do not post the same question in multiple channels (https://stackoverflow.com/questions/71335106/how-to-configure-my-plugin-for-working-both-with-intellij-and-android-studio) because it can engage multiple people trying to help you at the same time which is just a waste of resources. Please respect our time. If you do it (what is not recommended), then at least link in both places, so people can see if the problem is already solved. The recommended channel is this forum.
Hello
Sorry to waste your time, but as I had already wasted more than two weeks trying to find the solution to my problems by myself, reading all the Jetbrains docs (on plugins and others), dozens of posts here and there, without ever getting an answer to my problems, I had first launched a request on stackoverflow, and as I didn't get any answer, I looked for another place to post my questions.
When I will have a definitive answer to my problems, I was going to put the solution in my two posts, but for the moment, I still don't have it :-(
To answer your question, I don't know how to configure the runIde for the build.gradle.KTS, and moreover the doc indicates a path for Mac and no information for Windows. I tried all a set of writings, for example :
Hi,
You should set directory path, not to the exe file, according to runIde doc:
https://github.com/JetBrains/gradle-intellij-plugin#running-dsl
Of course you must have Android Studio installed locally. If your Android Studio is installed in C:\Program Files\Android Studio, then it should be (I assume you use Kotlin build.gradle.kts file):
It is fine to use "/" for Windows-specific paths in Gradle.
Hello
I still have the error in the dependencies, but otherwise it seems to work pretty well, at least enough for me to finally start coding the plugin.
I put below the 3 files, it may possibly help someone.
Thank you for your help.
JC