IntelliJ Platform Plugin SDK Help

Android Studio Plugin Development

Android Studio plugins extend or add functionality to the Android Studio IDE. Plugins can be written in Kotlin or Java, or a mix of both, and are created using IntelliJ IDEA and the IntelliJ Platform. It's also helpful to be familiar with Java Swing. Once completed, plugins can be packaged and distributed at JetBrains Marketplace.

Android Studio plugins are not Android modules or apps to run in the Android operating system, such as smartphones or tablets.

Configuring IntelliJ Platform Projects for Android Studio Plugin Development

To create a new Android Studio plugin project, follow the tutorial on the Getting Started with Gradle page. The tutorial produces a skeleton project suitable to use as a starting point for an Android Studio plugin. On the New Project Screen, choose IDE Plugin from the project generators list as described in the tutorial, not Android. Some minor modifications to the skeleton project are needed, as discussed below.

Matching Versions of the IntelliJ Platform with the Android Studio Version

For API compatibility, it is essential to match the version of the IntelliJ Platform APIs used for plugin development with the target version of Android Studio. The version number of Android Studio contains the version of the underlying IntelliJ Platform APIs that were used to build it.

The actual Android Studio version doesn't entirely reflect the (YEAR.MAJOR.MINOR) version of the IntelliJ Platform. The Android Studio version presented below is 2021.1.1 Patch 1, but the 2021.1 part marked with the green rectangle refers to the IntelliJ IDEA release.

To find the version of the IntelliJ Platform used to build Android Studio, use the Android Studio About dialog screen. An example is shown below. In this case, the (BRANCH.BUILD.FIX) version of the IntelliJ Platform is 211.7628.21 – marked with the blue rectangle – is corresponding to the IntelliJ IDEA version 2021.1.3.

In your Gradle build script, you should set both versions – build number and the release number – to the intellij.version property. To figure out the exact release number based on the build number, visit the IntelliJ Repository Releases listing and check the com.jetbrains.intellij.idea section.

The Gradle build script configuration steps section below explains how to set the IntelliJ Platform version to match the target version of Android Studio.

Example Android Studio About Dialog

Android Studio Releases Listing

Below, you may find a list of recent Android Studio releases mapped to the relevant IntelliJ IDEA versions:

Release Name

Channel

Release Date

Version

IntelliJ IDEA Version

Koala \| 2024.1.1 Canary 3

Canary

April 2, 2024

2024.1.1.1

AI-241.14494.158.2411.11648550

2024.1

241.14494.158

Koala \| 2023.3.2 Canary 2

Canary

March 22, 2024

2023.3.2.2

AI-233.14475.28.2332.11606850

2023.3.4

233.14475.28

Jellyfish \| 2023.3.1 RC 1

RC

April 4, 2024

2023.3.1.16

AI-233.14808.21.2331.11643467

2023.3.5

233.14808.21

Jellyfish \| 2023.3.1 Beta 2

Beta

March 27, 2024

2023.3.1.15

AI-233.14808.21.2331.11608968

2023.3.5

233.14808.21

Jellyfish \| 2023.3.1 Beta 1

Beta

March 21, 2024

2023.3.1.14

AI-233.14808.21.2331.11574862

2023.3.5

233.14808.21

For the full list of Android Studio releases with more details, visit the Android Studio Releases List page.

Configuring the Plugin Gradle Build Script

The use-case of developing for a non-IntelliJ IDEA IDE is reviewed in the Plugins Targeting Alternate IntelliJ Platform-Based IDEs section. The particular example in that section discusses configuring a plugin project for PhpStorm, so the details for an Android Studio plugin project are reviewed here.

Here are the steps to configure the Gradle build script for developing a plugin to target Android Studio:

  • The Gradle plugin attributes describing the configuration of the IntelliJ Platform used to build the plugin project must be explicitly set. Continuing with the example above, set the intellij.version value to 191.8026.42. Alternatively, specify intellij.localPath to refer to a local installation of Android Studio.

  • Android Studio plugin projects that use APIs from the android plugin must declare a dependency on that plugin. Declare the dependency in the Gradle build script using the intellij.plugins attribute, which in this case lists the directory name of the plugin.

  • The best practice is to use the target version of Android Studio as the IDE Development Instance. Set the Development Instance to the (user-specific) absolute path to the target Android Studio application.

The snippet below is an example of configuring the Setup and Running DSLs in a Gradle build script specific to developing a plugin targeted at Android Studio.

intellij { // Define IntelliJ Platform against which to build the plugin project. // Same IntelliJ IDEA version (2019.1.4) as target 3.5 Android Studio: version.set("191.8026.42") // Use IntelliJ IDEA CE because it's the basis of the IntelliJ Platform: type.set("IC") // Require the Android plugin (Gradle will choose the correct version): plugins.set(listOf("android")) } tasks { runIde { // Absolute path to installed target 3.5 Android Studio to use as // IDE Development Instance (the "Contents" directory is macOS specific): ideDir.set(file("/Applications/Android Studio.app/Contents")) } }
intellij { // Define IntelliJ Platform against which to build the plugin project. // Same IntelliJ IDEA version (2019.1.4) as target 3.5 Android Studio: version = '191.8026.42' // Use IntelliJ IDEA CE because it's the basis of the IntelliJ Platform: type = 'IC' // Require the Android plugin (Gradle will choose the correct version): plugins = ['android'] } runIde { // Absolute path to installed target 3.5 Android Studio to use as // IDE Development Instance (the "Contents" directory is macOS specific): ideDir = file('/Applications/Android Studio.app/Contents') }

Configuring the Plugin plugin.xml File

When using APIs from the android plugin, declare a dependency:

<depends>org.jetbrains.android</depends>

As discussed in the Plugin Dependencies section of this guide, a plugin's dependency on Modules Specific to Functionality must be declared in plugin.xml. When using Android Studio-specific features (APIs), a dependency on com.intellij.modules.androidstudio must be declared as shown in the code snippet below. Otherwise, if only general IntelliJ Platform features (APIs) are used, then a dependency on com.intellij.modules.platform must be declared as discussed in Plugin Compatibility with IntelliJ Platform Products.

<depends>com.intellij.modules.androidstudio</depends>

Android Specific Extension Points

See Android Plugin Extension Point and Listener List.

Additional Articles and Resources

Open Source Plugins for Android Studio

When learning new development configurations, it is helpful to have some representative projects for reference:

FAQ

How To Sync Gradle Project

Use GradleSyncInvoker.requestProjectSync() for programmatic synchronization.

See Also

IntelliJ Android Plugin README

Last modified: 15 April 2024