Android Studio Plugin Development
Android Studio plugins extend or add functionality to the Android Studio IDE.
Android Studio plugins are not Android modules or apps to run in the Android operating system, such as smartphones or tablets.
Android Studio Plugin Setup
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.
To find the version of the IntelliJ Platform used to build Android Studio, use the Android Studio About dialog screen:
The actual Android Studio version doesn't entirely reflect the (YEAR.MAJOR.MINOR) version of the IntelliJ Platform. The Android Studio version presented here is 2021.1.1 Patch 1
, but the 2021.1
part marked with the green rectangle refers to the IntelliJ IDEA release.
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 the Gradle build script, both versions should be set: the build number and the release number. To figure out the exact release number based on the build number, see Android Studio Releases List.
The Gradle Build Script section below explains how to set the IntelliJ Platform version to match the target version of Android Studio.
Android Studio Releases Listing
For the full list of Android Studio releases with more details, see Android Studio Releases List.
Gradle Build Script
IntelliJ Platform Gradle Plugin (2.x)
Define a dependency using androidStudio()
, see Versions link on top of this page for all available versions. See Local IntelliJ Platform IDE Instance for using a local installation.
A dependency on the bundled org.jetbrains.android
plugin must be added using the bundledPlugin()
helper.
Minimum build.gradle.kts setup:
Gradle IntelliJ Plugin (1.x)
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 to191.8026.42
. Alternatively, specifyintellij.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 with ID
org.jetbrains.android
. Declare the dependency in the Gradle build script using theintellij.plugins
attribute.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.
plugin.xml
The dependency on the Android APIs must be declared in the plugin.xml file.
When using APIs from the Android plugin, declare a dependency:
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.
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.
Android Specific Extension Points
Additional Articles and Resources
Discussion of extending Android Lint - How to Register AndroidLintInspectionBase in IntelliJIdea Plugin
Grzegorz Matyszczak's article How I Automated Creating Files for a New Screen with My Own Android Studio Plugin
Marcos Holgado's article series Write an Android Studio Plugin (Part 1)
Open Source Plugins for Android Studio
When learning new development configurations, it is helpful to have some representative projects for reference:
ADB Idea plugin for Android Studio and IntelliJ IDEA that speeds up Android development.
Android postfix plugin for Android Studio.
Bal Sikandar's list of Android Studio plugins.
FAQ
How To Sync Gradle Project
Use GradleSyncInvoker.requestProjectSync()
for programmatic synchronization.