How to use the PreviewRepresentation extension from the Android plugin?
Answered
I want to use this extension in my plugin: https://plugins.jetbrains.com/docs/intellij/extension-point-list.html#designerxml
The first one in the link: com.android.tools.idea.uibuilder.editor.multirepresentation.sourcecode.sourceCodePreviewRepresentationProvider is the one I want to use. I want to create a PreviewRepresentation using this extension point. However I don't know how to do this and I could not find any examples on how to implement this. So I would like to know how to implement this.
Please sign in to leave a comment.
Register implementation of com.android.tools.idea.uibuilder.editor.multirepresentation.PreviewRepresentationProvider
in plugin.xml extension point com.android.tools.idea.uibuilder.editor.multirepresentation.sourcecode.sourceCodePreviewRepresentationProvider and return your com.android.tools.idea.uibuilder.editor.multirepresentation.PreviewRepresentation implementation for suitable accepted PsiFile.
I have created the PreviewRepresentation implementation. However, I don't know which tag to use to register the class in the plugin.xml file. Could you please help me?
See https://plugins.jetbrains.com/docs/intellij/plugin-extensions.html#declaring-extensions
I declared it like this:
However, it is giving me error on the second line that it cannot resolve the second line. What should I do now?
`defaultExtensionNs` value is prepended to all nested extension points, so it must match their prefix. Set it to `com.android.tools.idea.uibuilder`, then <editor.multirepresentation...> tag should work.
Thanks, it works! However, now I am getting the following error:
Make sure to declare dependencies in `plugin.xml` https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
I have already declared dependencies for Android as below:
Strange, looks corrrect IMHO. Pinged colleague.
In Android Studio Bumblebee this class has been moved from the main android plugin to a dedicated `design-tools` plugin.
Thanks! It works but the old plugin's accept method had VirtualFile as an argument. However, in the new plugin, instead of VirtualFile, it is PsiFile. And it is giving me an error. Moreover, PreviewRepresentaionProvider interface from the new plugin is not available in Intellij IDEA. So how can I resolve that error?
You should develop two different plugins. One for Android Studio Arctic Fox, another one for Bumblebee. Android plugin in IDEA 2022.1 has version 2020.3 (i.e. the same as in Arctic Fox studio), so the plugin for Arctic Fox will likely work in IDEA as well.
I also recommend that you setup Android Studio (not Idea Community) as a dependency when developing against Android Studio.
Yann Cebron, could you please advice what is the recommended way to setup AS as a dependency? Is it still
intellij.localPath
as explained in https://github.com/JetBrains/gradle-intellij-plugin#intellij-platform-properties?Thanks! The plugin works perfectly in Arctic Fox. But rather than developing two different plugins, isn't there any other way through which to check if it is Arctic Fox or Bumblebee and then set dependencies accordingly? And even if I develop two different plugins, then will I be able to upload them both to the plugin marketplace?
There is no easy way to switch implementations on the fly. You can create a class which will contain both methods, so it will be binary-compatible with both IDEs, but it is still tricky to compile such a class.
Marketplace will allow you uploading both plugins. Make sure that you set since/until versions properly.
More information about matching IntelliJ IDEA vs Android Studio versions can be found here https://plugins.jetbrains.com/docs/intellij/android-studio.html and in the releases page https://plugins.jetbrains.com/docs/intellij/android-studio-releases-list.html
Andrei Kuznetsov I am now creating the plugin for Bumblebee. However on using the following code in `plugin.xml`:
I am getting error on line 4 and 7. Also I am not getting auto complete in line 7. I have already declared dependency on Android Studio itself in `build.gradle` file. So what should I do now? Also is the Android Studio source code available here the latest one: https://cs.android.com/android-studio/platform/tools/adt/idea ?
Parmarrivan, you need to declare dependency on `design-tools` in build.gradle file in order to make these classes available in compile time:
cs.android.com allows you to select branches (note drop down in top-left corner). By default it shows contents of mirror-goog-studio-main, which is Electric Eel now.
Ok, Thanks! That works!