71

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?

Mladen
  • 2,070
  • 1
  • 21
  • 37
Prachi
  • 3,584
  • 2
  • 24
  • 39
  • Yes!!! when you develope gradle base project then .iml file store your project info so i think it good store on version control. – Haresh Chhelana Aug 26 '14 at 11:42
  • Check : http://stackoverflow.com/questions/16736856/what-should-be-in-my-gitignore-for-an-android-studio-project – Haresh Chhelana Aug 26 '14 at 11:53
  • 2
    IMHO, only pay attention to the answers from 2014 from [Haresh's link](http://stackoverflow.com/q/16736856/115145). – CommonsWare Aug 26 '14 at 11:55
  • I have read the question. As per answer from Lior Iluz, Git now allows to store *.iml files whilst other refuse to store it. – Prachi Aug 26 '14 at 11:56
  • 8
    I disagree that .iml files should be submitted to source control. They're entirely generated, and the IDE has freedom to rewrite them at will based on changes to the Gradle files. That makes them redundant with the Gradle files, and it will just be one more thing you need to check out, maintain, and check back in when the Gradle files change. – Scott Barta Aug 26 '14 at 21:25
  • 12
    In latest Android Studio (1.5.1) when you create a new Android project from scratch, the Android Studio creates .gitignore file automatically and adds *.iml in .gitignore. So now in 2016 the the answer would be "No, its not mandatory to save .iml files in Version Control System." – Anuroop Feb 26 '16 at 10:43
  • 3
    Personally, I've found that Android Studio is constantly making minor rearrangements and alterations to the .iml files, so maintaining them in version control is a hassle. – Sam Jun 14 '16 at 10:21
  • The key fact here is that they are **generated** based on other files in your project. That puts them on the level of keeping your project's compile output in version control. – Rikki Gibson May 06 '17 at 18:20

4 Answers4

68

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.

kryger
  • 12,906
  • 8
  • 44
  • 65
Marcin Szawurski
  • 1,313
  • 12
  • 15
  • I always get dual answers! The above comment from Haresh says yes, and you say 'no'. Where am I to go? I think it is doesn't matter because *.iml do not share any user's project path. So it seems fine to share. Can you share a link where all this is otherwise explained. – Prachi Aug 26 '14 at 11:50
  • 2
    I'm not sure if in the thread you invoke maven is taken into consideration - it is perfectly possible to have Idea project without maven, in which case it should be indeed commited (as it's the only place where project conf is stored). If you use maven however, and iml are only generated, I don't see the point. – Marcin Szawurski Aug 26 '14 at 11:55
15

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

cygnus
  • 195
  • 1
  • 12
2

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.

WesternGun
  • 11,303
  • 6
  • 88
  • 157
0

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

Vladimir
  • 1,120
  • 2
  • 11
  • 18