Reputation: 1593
I'm working on a project that was created before Gradle became the build system for Android development (LibreOffice Viewer for Android). When the project was migrated to Gradle, it didn't reorganize the folder structure to the new one Android is using, and so the Gradle config has things like:
main.manifest.srcFile 'AndroidManifest.xml'
main.assets.srcDirs = ['assets']
main.res.srcDirs = ['res']
main.java.srcDirs = ['../Bootstrap/src', 'src/java']
main.jniLibs.srcDirs = ['jniLibs']
in the build.gradle
file in the root of the project, while "usual" Gradle projects have one file in the root of the project, and one in each of the modules.
My question is, is it enough to create a new folder for the module, and create a new build.gradle
file within it (and then move the appropriate files etc.)? Is that the "correct" way of adding a new module manually, or do I have to "declare" that module somewhere else, for it to work correctly, and be recognized by Android Studio?
Upvotes: 4
Views: 6733
Reputation: 1007322
It is definitely possible to do this manually, as I did it for literally hundreds of book sample apps.
You listed these steps:
app
)build.gradle
file within itYou also need to:
Add your module to settings.gradle
, creating that file if needed (or copying it from an existing Android Studio project)
Have your app/build.gradle
correctly reflect the locations of the moved files, which could include removing stuff like main.assets.srcDirs
, if your files are now all in standard locations (the way that you would find in a newly-created Android Studio project)
Add a new project-level build.gradle
file, probably just copied from some standard Android Studio project
In terms of Android Studio itself, I strongly recommend doing this project reorganization outside of Studio. Then, delete generated Studio items (all .iml
files, .idea/
subdirectory, build/
directories), and finally import the project back into Studio.
Upvotes: 6