Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
213 views
in Technique[技术] by (71.8m points)

Android Studio create project template for new projects

First of all, I'm aware of this question; however I cannot follow the answer because there are no directories mentioned there.

When creating new Android Studio project I want the following to be created automatically:

  1. Specific packages and directories;
  2. Gradle dependencies
  3. Several classes (might be imported from somewhere else)

Is it possible to create an Android Studio template for these tasks?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Check out this folder under your android SDK folder:

android-sdkoolsemplatesprojects

enter image description here

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:

enter image description here

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>pluginsandroidlibemplates

enter image description here

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...