Custom Android Studio Plugin with IntelliJ-platform-plugin-template

Eric Lee
4 min readMar 5, 2022
Photo by Joshua Sortino on Unsplash

When I make the code on a clean architecture, the boilerplate code is incidentally generated. You can think of layers and data flow of clean architecture just like this picture below:

Clean Architecture Guide (with tested examples): Data Flow != Dependency Rule

When making a screen with Activity, I have to make several files. For example, if making a SampleActivity, I have to create files like the following:

Android (com.github.libliboom.tmdb) 
├─ data/datasource/sample
| └─ SampleDatasource.kt
├─ data/repository/sample
| |─ ISampleDatasource.kt
| └─ SampleRepository.kt
├─ domain/sample
| |─ ISampleRepository.kt
| └─ SampleUsecase.kt
├─ presentation/sample
| |─ SampleAction.kt
| |─ SampleMiddleware.kt
| |─ SamplePresentation.kt
| └─ SampleReducer.kt
├─ ui/sample
| |─ SampleActivity.kt
| └─ SampleViewModel.kt
(app/src/main/res/layout)
└─ activity_sample.xml

In other words, I have to create 12 files in every Activity. Therefore, it will take up much of my time and energy. Hence, I wanted to make them all at once in just one click. But, how can this be achieved?

The solution is to use IntelliJ-platform-plugin-template. With this, I will share the steps in how to make it through this demo:

First, check the official document for the IntelliJ platform SDK

You can make the plugin with this official guide after Android studio 4.1+. I made the following environment:

  • intelliJ-platform-plugin-template: v1.1.2
  • Android studio version: 211.7618.21
  • OS: macOS

Second, use the IntelliJ platform plugin template in Github

You can clone the initial project through the template. For using this project, just click Use this template the button on the right top.

Third, set configuration for using Android Studio

When you run ./gradlew runIde in a terminal, you can see the result made. But initially, it runs on Intellij. That’s why it should set the config to use Android Studio with the following:

gradle.properties(commit:52efad4)
build.gradle.kts(commit:d572e4f)
plugin.xml(commit:9441eed)

You can run Android studio whenever you run ./gradlew runIde or Run pluginin configuration.

If your Android studio version is lower than 211, you have to set your current version of Android studio at pluginSinceBuild in gradlew.properties.

Fourth, you can create your own template

We don’t know well how to add UI widgets in IDE. But we already know Android studio code is open. Therefore, you can refer to the code here. For example, if you want to know about the code for New > Activity, right-click on the file tree in IDE. There, you can see it in the wizard directory.

For adding the menu in Android studio, you should add your WizardTemplateProviderImpl like the following.

And then register the class in plugin.xml file like in the following.

plugin.xml(commit:7b0ba2f)

You can check a code on how to add UI widget in files ending with Template and on how to create and add class files end with Recipe.

In my case, I added a Template on only one entry from New > Activity like the following.

Then files that I want to create are organized as seen below.

Workaround: I couldn’t find a way how to add <activity> in AndroidManifest.xml. So I just made a simple manifest file and merged it with the existing manifest file.

Fifth, install the plugin in Android Studio

You can install the plugin that you made with generated jar in build/libs folder. For jar, you can add it like in the following.

Now, everything is done. You can use the custom plugin function you have made from now on. You can see all steps at https://github.com/libliboom/Custom-Plugin-Template.

--

--