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.

15 comments
Comment actions Permalink

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.

0
Comment actions Permalink

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?

0
Comment actions Permalink

I declared it like this: 

<extensions defaultExtensionNs="org.jetbrains.android">
<com.android.tools.idea.uibuilder.editor.multirepresentation.sourcecode.sourceCodePreviewRepresentationProvider
implementation="Sample" />
</extensions>

However, it is giving me error on the second line that it cannot resolve the second line. What should I do now?

0
Comment actions Permalink

`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.

0
Comment actions Permalink

Thanks, it works! However, now I am getting the following error:

Caused by: java.lang.NoClassDefFoundError: com/android/tools/idea/uibuilder/editor/multirepresentation/PreviewRepresentationProvider
0
Comment actions Permalink

I have already declared dependencies for Android as below:

<depends>org.jetbrains.android</depends>
<depends>com.intellij.modules.androidstudio</depends>
0
Comment actions Permalink

Strange, looks corrrect IMHO. Pinged colleague.

0
Comment actions Permalink

In Android Studio Bumblebee this class has been moved from the main android plugin to a dedicated `design-tools` plugin.

<depends>com.intellij.modules.platform</depends>
<depends>com.android.tools.design</depends>
<depends>com.intellij.modules.androidstudio</depends>
0
Comment actions Permalink

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?

0
Comment actions Permalink

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?

0
Comment actions Permalink

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?

0
Comment actions Permalink

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.

0
Comment actions Permalink

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

0

Please sign in to leave a comment.