Custom library module

Viewed 257

I am using the latest android studio (4.1 canary 2) and I am wondering if I can generate a custom android library module from the "create new module wizard.

enter image description here

The reason that I need something like that is because on my latest project I am trying to apply clean architecture principles and it is also multi-module but it is cumbersome to create everything from scratch for each module.

So ideally I want to create a module which will create data, domain, di and ui packages with the appropriate classed inside, create the gradle file with some basic libraries and the res folder for some UIs.

Is it possible? I know that I can create templates for java files but I have not found anything alike for modules.

1 Answers

This can probably be done using a gradle script or plugin instead. It could dynamically add or create classes, manage dependencies and add them to the compile path, and IDE's can also reference them after syncing or compiling once. Here's one I created for dynamically adding Android OpenCV native libs to a project in few amount of steps (with a lot of code behind the scenes) so one could build Android Apps that integrates with OpenCV easily.

For creating classes, I'd recommend checking out JavaPoet which allows for easy generation of Java code, since you need to have the packages of the generated code to be matching that of your project.

Related