Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create "New Project" Plugin for Android Studio

I would like to develop an Android Studio PLUG IN that appears in the New Project Wizard.

I am using Android Studio

Android Studio 3.4.2
Build #AI-183.6156.11.34.5692245, built on June 27, 2019
JRE: 1.8.0_152-release-1343-b01 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.14.6

The Standard Android Studio New Project wizard is accessed via

FILE > NEW > NEW PROJECT... > "CREATE NEW PROJECT" WIZARD

The wizard presented has five Tabs

"Phone and Tablet", "Wear OS", "TV", "Android Auto", and "Android Things"

I am unable add an additional project in the "Phone and Tablet" window or add an additional Sixth Tab.

I have been success in adding an additional "Activity" type to an existing project.

Is it possible to achieve my desired result?

Or is the "New Project" wizard "Locked Down" for Googles use only?

like image 583
Hector Avatar asked Nov 17 '22 02:11

Hector


1 Answers

Old question but since it took me a while to find the answer as well I will leave it here too. There's an extension point you can use now to add your own wizard. Here's what you need to do:

  1. Create a Jetbrains plugin project (use the Github template or something similar).

  2. In the resources/META-INF/plugin.xml add the following extension:

    <extensions defaultExtensionNs="com.android.tools.idea.wizard.template">
    <wizardTemplateProvider implementation="your.template.provider"/>
    
  3. Create the template provider class.

The template provider could be something like this:

class MyTemplateProvider: WizardTemplateProvider() {
      override fun getTemplates() = listOf(myTemplate)
}

val myTemplate = template {
    name = "My Template"
    description = "Foo"
    documentationUrl = "example.com"
    minApi = 21
    category = Category.Other
    formFactor = FormFactor.Mobile
    thumb = { Thumb(path = { <URL to an image> }) }
    screens = listOf(
        WizardUiContext.ActivityGallery,
        WizardUiContext.FragmentGallery,
        WizardUiContext.MenuEntry,
        WizardUiContext.NewProject,
        WizardUiContext.NewModule,
    )

    recipe = { data: TemplateData ->
        val config = data as ModuleTemplateData
        // TODO generate the template project
    }
}
like image 128
Gillian Avatar answered Jan 20 '23 13:01

Gillian