Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio: Why does my New project contain 2 modules

In a new Android Studio project, when I view Project Structure, there are 2 modules. One is "ProjectName" and the other is "ProjectName-ProjectName". Did I do something wrong when creating the project?

Android Studio Project Structure

like image 377
bgolson Avatar asked Jan 14 '23 08:01

bgolson


2 Answers

When creating new projects, we always create a top level project with a single module in it. Studio or IntelliJ will show both in the module list but the top one ("testing") doesn't output anyway.

We do this instead of a flat structure in the root project, so that it will allow you later to easily add new modules (like libraries) without having to convert the structure of your project.

what matters is the "testing-testing" module (we'll probably rename this "testing-main" at some point). the other module doesn't do anything. If you look at its build.gradle it's empty, while the other one declares an Android project.

like image 111
Xavier Ducrohet Avatar answered Jan 22 '23 00:01

Xavier Ducrohet


I got a similar set of .iml files as yours, using an older version of Android Studio, but after upgrading to a later version it created yet another .iml, so then there was a top-level project.iml with a module containing module.iml and module-module.iml.

As far as I could tell, the module-module.iml file was useless, and the key information was in module.iml. However, even if I deleted all the iml files, Android Studio would recreate all of them, so I realized it was storing enough information in the [project]/.idea/modules.xml to recreate the iml files from scratch.

So I exited Android Studio, deleted the .idea folder and the .iml files, then relaunched Android Studio and imported the project using the build.gradle files. It recreated only project.iml and module.iml, and everyone is happy.

SUMMARY: As long as your gradle.build files are clean, then you can delete the .idea and .iml files, import the project using the gradle files, and get a nice clean project structure.

like image 41
tompark Avatar answered Jan 22 '23 00:01

tompark