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?
- Yes!!! when you develope gradle base project then .iml file store your project info so i think it good store on version control.Hareshkumar Chhelana– Hareshkumar Chhelana2014-08-26 11:42:42 +00:00Commented Aug 26, 2014 at 11:42
- 2IMHO, only pay attention to the answers from 2014 from Haresh's link.CommonsWare– CommonsWare2014-08-26 11:55:33 +00:00Commented Aug 26, 2014 at 11:55
- 8I 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– Scott Barta2014-08-26 21:25:47 +00:00Commented Aug 26, 2014 at 21:25
- 12In 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– Anuroop2016-02-26 10:43:20 +00:00Commented Feb 26, 2016 at 10:43
- 3Personally, 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– Sam2016-06-14 10:21:53 +00:00Commented Jun 14, 2016 at 10:21
5 Answers
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.
2 Comments
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
Comments
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.
1 Comment
The current top answer - July 2025 is great for beginners, but most rules have exceptions, here's my 2 cents:
Rule of thumb:
"Don't commit generated files"
However...
- Is regeneration of the files straight forward?
- Can it be automated as part of on-boarding to your project (e.g. with package manager installation or init scripts)?
- Do the files change often enough to make 1 and 2 a headache?
- Do the files contain hardcoded local environment settings?
- (Specific to this Stack Overflow Question) Do most of your developers use the same IDE anyway?
Sometimes even though a file is generated, the benefits of source-controlling those files outweigh the best-practice benefits. In the case of IDE files, it enables sharing of common things like run configurations and module setup that could be tedious to import and maintain manually for medium to highly complex projects and does not have an easy means of automation integrated with the standard IDE-agnostic build/setup process of a project.
Intellij .idea folders contain some hard-coded environment variables, however there is a default .idea/.gitignore file generated when first importing a project that contains recommended ignore settings.
If you have the patience to monitor any changes in .idea folders that cause future conflicts, it could potentially speed up on-boarding when others use the same IDE.