Search code examples
androidandroid-studioandroid-gradle-pluginandroid-buildgenerated-code

Mark folder as generated in Android Studio


Within our app we include classes that are generated by our backend. We keep them in a separate folder within our project. A new colleague overlooked the fact that these classes were located in the generated folder and started editing these.

So that made me wonder if there is a way to tell Android Studio that the generated folder contains generated classes and should not be edited. Much like if you try to edit a file under the build folder.

Android Studio build folder warning

I could off course just add a comment to every file, but it would be much more clear if Android Studio showed a warning.


Solution

  • In the projekt explorer (the one which comes up when you click ALT + 1) select the project or project files view. Next right click any folder and select Mark Directory as, which is in the bottom part of the context menu. There may already be options displayed like Sources Root or Generated Sources Root. If these options don't show up mark it as Excluded. For folders inside the excluded directory you should then be able to mark them as Generated Sources Root.

    Not sure why you can't always choose from all the options...