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.

0
18 comments

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

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

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

`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

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

I have already declared dependencies for Android as below:

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

Strange, looks corrrect IMHO. Pinged colleague.

0

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

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

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

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

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

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

Andrei Kuznetsov I am now creating the plugin for Bumblebee. However on using the following code in `plugin.xml`:

<depends>com.intellij.modules.platform</depends>
<depends>org.jetbrains.android</depends>
<depends>com.intellij.modules.androidstudio</depends>
<depends>com.android.tools.design</depends>

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

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 ?

0

Parmarrivan, you need to declare dependency on `design-tools` in build.gradle file in order to make these classes available in compile time:

intellij {
....
plugins = ["design-tools","android",...]
}

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.

0

Ok, Thanks! That works!

0

Please sign in to leave a comment.