Android Studio Create Project Template for New Projects

Android Studio create project template for new projects

Check out this folder under your android SDK folder:

android-sdk\tools\templates\projects

Sample Image

There are three predefined templates as seen below, which we generally use.

Each template folder has different ftl files which are templates for each of the existing projects:

Sample Image

You can create a new template folder and design the ftl files as you want them to. And also define project structures.

Just open one of these and you'll get an idea of how the default templates are there. Extend those or create your own from scratch as you want.

With the above said, your questions can be answered as follows:

For creating packages create a folder structure in the root folder to match your package name.

For gradle dependencies add them to your *.gradle.ftl files, as required.

For copying/importing exiting classes/files look at recipe.xml.ftl to get an idea of how to copy.




UPDATE: After people reported it not to be working if changed in the above mentioned folder under Android SDK

I searched again and found another location where these templates are stored i.e. directly under the Android Studio installation folder and not the Android SDK folder.

Verified for Android Studio Version 1.5 & Android Studio Version 2.0 Beta:

<installation folder>\plugins\android\lib\templates

Sample Image

The file types and organization of them is same as mentioned earlier.

How do I create custom project templates to Android Studio 3.6 or above?

That's correct. In Android Studio 3.6 and 4.0 beta5 it is not possible to add new activity templates to "Mobile" form-factor in New Project Wizard, because the list of template titles is hard-coded in the source code. But it is possible to add templates to the other form-factors.

Note that even for mobile form-factor, the new activity template can be used after the project has been created (File > New > Activity > "New Template Title here")

Starting from Android Studio 4.0 the Template API will (hopefully) be opened in the form of extension point (see https://issuetracker.google.com/issues/154531807)

In the IntelliJ IDEA it is possible to create a template from existing project.

UPD: Templates provider API is now available in Android Studio 4.1. EP name is com.android.tools.idea.wizard.template.wizardTemplateProvider (https://android.googlesource.com/platform/tools/base/+/refs/heads/studio-master-dev/wizard/template-plugin/src/com/android/tools/idea/wizard/template/WizardTemplateProvider.kt)

How to build template project for Android Studio

Yes you can, but it is nothing different than building an Activity Template.

Have a look in the folder android-studio/plugins/android/lib/templates/activities. And more specifically in the MasterDetailFlow template. You see that you can add an arbitrary amount of activities, resources and layouts in your template. So the templates are not limiting you from creating a whole project as a template project.

In each of the files you can use the variables defined in the globals.xml.ftl.

Android Studio New Project Template Uses Plugins not Dependencies

Assuming these repositories in settings.gradle:

pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}

One can replace the buildscript block with:

plugins {
id 'com.android.application' version '7.1.2' apply false
id 'com.android.library' version '7.1.2' apply false
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
id 'androidx.navigation.safeargs' version '2.5.0-alpha02' apply false
id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin' version '2.0.0' apply false
}

Maybe with or without that -gradle-plugin suffix.



Related Topics



Leave a reply



Submit