214

What are .iml files in Android Studio project? I read that it is configuration file for modules. I do not understand how it works, and can't I just use gradle scripts to integrate with external modules that you add to your project.

Also, most of the time AS generates them, so I cannot control project behaviour. If I have a team that works in different IDEs like Eclipse and AS, is it possible to setup my project so it's IDE agnostic?

I don't fully understand how this system works.

shadox
  • 3,238
  • 4
  • 24
  • 38

4 Answers4

194

What are iml files in Android Studio project?

A Google search on iml file turns up:

IML is a module file created by IntelliJ IDEA, an IDE used to develop Java applications. It stores information about a development module, which may be a Java, Plugin, Android, or Maven component; saves the module paths, dependencies, and other settings.

(from this page)

why not to use gradle scripts to integrate with external modules that you add to your project.

You do "use gradle scripts to integrate with external modules", or your own modules.

However, Gradle is not IntelliJ IDEA's native project model — that is separate, held in .iml files and the metadata in .idea/ directories. In Android Studio, that stuff is largely generated out of the Gradle build scripts, which is why you are sometimes prompted to "sync project with Gradle files" when you change files like build.gradle. This is also why you don't bother putting .iml files or .idea/ in version control, as their contents will be regenerated.

If I have a team that work in different IDE's like Eclipse and AS how to make project IDE agnostic?

To a large extent, you can't.

You are welcome to have an Android project that uses the Eclipse-style directory structure (e.g., resources and manifest in the project root directory). You can teach Gradle, via build.gradle, how to find files in that structure. However, other metadata (compileSdkVersion, dependencies, etc.) will not be nearly as easily replicated.

Other alternatives include:

  • Move everybody over to another build system, like Maven, that is equally integrated (or not, depending upon your perspective) to both Eclipse and Android Studio

  • Hope that Andmore takes off soon, so that perhaps you can have an Eclipse IDE that can build Android projects from Gradle build scripts

  • Have everyone use one IDE

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • 3
    what happen if I remove the iml file? it's will be okay? – Eggy Jul 17 '16 at 16:16
  • 1
    @E-Place: If you are using Android Studio, you will need to have Android Studio re-generate it, typically by importing the project. Android Studio cannot function without it. – CommonsWare Jul 17 '16 at 16:18
  • 1
    how the iml can created? i have more than 4 iml file – Eggy Jul 17 '16 at 16:26
  • @E-Place: Normally, you will have one `.iml` file in the project root, plus one `.iml` file in each module directory (e.g., `app/`). You might try Tools > Android > Sync Project with Gradle Files. Otherwise, you may need to re-import the project. If you have additional concerns in this area, please ask a fresh Stack Overflow question. – CommonsWare Jul 17 '16 at 16:32
  • 2
    You *can* have everyone use the same IDE, at least in respect to the `*.iml` files and `.idea/` directory, assuming you're distributing / synchronizing the files using `git` or similar. For `git`, just make sure the files you don't want to sync are referenced in the `.gitignore` file, as @Pavel Synek suggests, below. You'll need to delete them from the repository and regenerate / restore them locally, but that's just `mv`, `git commit`, and `mv`. – Sarah Messer Mar 16 '17 at 17:46
  • To be noted, not only java application that developed using IntelliJ has .iml file. I have PhpStorm which is one of IntelliJ variant and i develop web application with it, it will still generate .iml file. – HendraWD Jun 07 '17 at 08:20
  • A Google search on iml file turns up: this question. – Mikhail Oct 28 '20 at 18:37
  • i have case on flutter, i alr deleted .iml already restart AS its didnt automatically created, how about in flutter ? i run its okey there is no problem did u know why ? – Yogi Arif Widodo Apr 08 '22 at 23:43
82

Add .idea and *.iml to .gitignore, you don't need those files to successfully import and compile the project.

Pavel Synek
  • 1,191
  • 8
  • 13
  • 22
    Ok, but what are they? How they work and which impact do they have? I'm looking through source of another project and there is a module in iml file that is present only there, for gigya for example and I don't see it in any other place except manifest. So, is that module present in the project or no? – shadox Jun 09 '15 at 16:11
  • 5
    `.idea` as a whole should never be ignored. It contains several files, like lint rules and custom dictionaries, that a team would absolutely want checked into version control. – M-Pixel Apr 12 '19 at 18:45
  • 5
    This doesn't even attempt to answer the question. – K-- May 06 '20 at 15:17
  • @M-Pixel I always ignore `.idea` and `.iml` files and nothing happened. On our school not everyone uses the same IDE. – Remzi Cavdar Dec 08 '22 at 17:59
  • 1
    @RemziCavdar that's precisely the problem, that "nothing happened". If `.idea` folder is ignored entirely, and you check-in changes to lint rules or additions to custom dictionary, your colleagues will never ever see your changed rules or added words. It's not likely to be of any concern to students in a school scenario, but should be expected to matter in a professional environment where consistency of both style and development environment (e.g. everyone using the same version of the same IDE) can make a difference of tens of thousands of dollars of productivity per year. – M-Pixel Dec 09 '22 at 18:35
16

They are project files, that hold the module information and meta data.

Just add *.iml to .gitignore.

In Android Studio: Press CTRL + F9 to rebuild your project. The missing *.iml files will be generated.

Redwolf
  • 540
  • 4
  • 17
2

Those files are created and used by Android Studio editor.

You don't need to check in those files to version control.

Git uses .gitignore file, that contains list of files and directories, to know the list of files and directories that don't need to be checked in.

Android studio automatically creates .gitingnore files listing all files and directories which don't need to be checked in to any version control.

Arnav Rao
  • 6,692
  • 2
  • 34
  • 31