Reputation: 4867
I am working on extending my Android Library, and in the library I want to have a directory that has the ability to add many different and working sample Android apps in their own modules.
I have already created one sample app that I would like to move and rename I guess; however, I need the ability to add other ones easily.
These two solutions that allow to create a module exactly how I want structurally; however, these solutions will only create a standard java module. I specifically need an Android App module.
Another option that I have tried was to directly use Android Studio's New Module Wizard. This option allows me to create an Android App Module; however, it will not put it in the correct structure.
Project Module
|- Android Library Module
|- "samples" Android App Module (Complex)
Project Module
|- Android Library Module
+- "samples" Directory
|- "sample-basic" Android App Module
|- "sample-complex" Android App Module
So what am I missing? I have seen other git repos that have Android app modules inside of subdirectories. So it appears to be possible.
Upvotes: 0
Views: 416
Reputation: 4867
The following is correct way to get everything specified above...
First use the Android Studio's New Module Wizard
to create 2 Android Modules; one for the basic sample, and another for the in-depth sample.
In the settings.gradle
file, copy the code below.
This will create 3 modules
as direct child modules to the project. Further steps are needed to create the subdirectory
and put the correct modules in it.
All of that without creating a module for the subdirectory.
Please note: that the outcome of this are 3 basic java modules. However, the :accessibility
module was already declared as an Android Library Module
before. So the real outcome is the creation of 2 additional Java Modules
.
This is not quite what I want...but it is very close!
include ':accessibility', ':samples-basic', 'samples-indepth'
// Set the root projects name - the Project Module
rootProject.name = 'accessibility'
// For each module within the project - i.e. "app" module, etc...
rootProject.children.each { project ->
// Only modify modules that contain the selected word. Note: do whatever logic is needed to sort and move the correct modules
if (project.name.contains("samples")) {
// Move the module into a specific subdirectory
String projectDirName = "samples/$project.name"
project.projectDir = new File(settingsDir, projectDirName)
assert project.projectDir.isDirectory()
assert project.buildFile.isFile()
}
}
Now that you have all the code finished, just take the 2 Android Sample Modules and move them to the samples subdirectory. Once the move is complete, you are finished
"Accessibility" Project Module
|- "accessibility" Library Module
+- "samples" Directory
|- "samples-basic" Android App Module
|- "samples-complex" Android App Module
Upvotes: 1