Is it mandatory to save *.iml files in Version control?

AndroidAndroid StudioVersion Control

Android Problem Overview


I have now switched to Android Studio and saving my projects in Git with Source Tree. Whenever I add or remove any library from my module, its .iml file also changes. It really doesn't matter if I commit the *.iml because they get auto-generated in others Android Studio. However, here it says you should store *.iml . My question is, do we really need to share our *.iml with others? If yes, why?

Android Solutions


Solution 1 - Android

General best practice is to:

  • make projects as IDE-agnostic as possible,
  • do not commit generated files.

So the answer is: it's better to make such files ignored for VCS.

Solution 2 - Android

Yes, .iml Files are suitable for version control (see this comment)

It is also true to make projects as IDE-agnostic as possible, however, sharing .iml files does not break anything for people developing with another IDE. For them, they are just a bunch of relatively small files that don't concern them.

A good practice for teams using different IDEs simultaneously is to store each IDE's project files in the VCS, only excluding those which contain paths, environment variables etc. specific to a single developers environment. This way, anyone using one of the supported IDEs can enjoy the benefits of a proper, shared setup, like for example:

  • sharing build configurations
  • sharing dependencies
  • configurations for automatic code quality checks

There are more use cases, depending on the specific IDEs in play. Edit: For IntelliJ, also see this FAQ

Solution 3 - Android

I agree that they are IDE-dependant files irrelevant to code and they should not be shared. But, then you should know how to regenerate them.

You may encounter with situations while your remote repo does not contain these files and when you clone the code and open in IDEA, it just shows a bunch of errors. Why? *.iml files are not regenerated.

You must import from IDEA with "File" - "New" - "Project from Version control". Only this can generated the files for you.

Solution 4 - Android

Rule of thumb - "Anything thats can be generated from source code should not be checked in" .

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPrachiView Question on Stackoverflow
Solution 1 - AndroidMarcin SzawurskiView Answer on Stackoverflow
Solution 2 - AndroidcygnusView Answer on Stackoverflow
Solution 3 - AndroidWesternGunView Answer on Stackoverflow
Solution 4 - AndroidVladimirView Answer on Stackoverflow