8

I want to commit my Android App code to a git repository. For this purpose I require a proper .gitignore file so that I can avoid commiting unnecessary and bloating stuff to the repo.

So I was wondering if anyone could provide me a good one for a kotlin project.

I have went through some questions here on StackOverflow, but those .gitignore are JAVA Project oriented, and I want one with kotlin orientation.

Ayush Gupta
  • 8,716
  • 8
  • 59
  • 92
  • 1
    It is pretty much the same gitignore file for kotlin than for java – donfuxx Dec 17 '17 at 16:00
  • Does this answer your question? [What should be in my .gitignore for an Android Studio project?](https://stackoverflow.com/questions/16736856/what-should-be-in-my-gitignore-for-an-android-studio-project) – lcnicolau Mar 29 '20 at 15:54

2 Answers2

0

The .gitignore file for a Java project and a Kotlin project can have some differences but they are likely to be minor. It could be depending on the frameworks used, the IDE, the build tools (Maven or Gradle) or the dependencies.

If you use Android Studio, it will automatically generate a rather complete gitignore.

But I can tell you the most important elements you need to exclude :

  • /.idea : This directory contains project-specific settings and configuration files for Android Studio. You can exclude this directory as it is not required for building the project.

  • /build : This directory contains the compiled code and build artifacts. You can exclude this directory as it can be rebuilt from the source code.

  • *.iml : This file is generated by Android Studio and contains information about the development module. You can exclude this file as it can be regenerated.

  • local.properties : This file contains the path to the Android SDK. You can exclude this file as it is specific to your local environment.

For example for a new empty project Android Studio generated me this gitignore:

*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties

Hope that will be useful!

Soufian
  • 51
  • 3
  • [According to JetBrains](https://intellij-support.jetbrains.com/hc/en-us/articles/206544839) you need to include most of `.idea` and `.iml` into VCS – Sergei Kozelko Mar 24 '23 at 14:20
  • You are right! For example for a new empty project Android Studio generated me this gitignore (I will add it to my answer) – Soufian Mar 25 '23 at 01:39
-1

There are no big differences between a gitignore from android with java to android with kotlin.

The differences are in the build directory, so since you should have a build entry in your .gitignore, this one will be enough.

One possible difference is if you have an entry like:

!**/src/java/build
!**/test/java/build

Then you will need to update it, but a better one can be:

!**/src/**/build
!**/test/**/build

If you don't have any .gitignore in your current repo, you can check this repo:

https://github.com/JetBrains/kotlin-examples/tree/master/gradle

It has a lot of examples of projects with android and kotlin and each one has a .gitignore that you can copy.

jonathanrz
  • 4,206
  • 6
  • 35
  • 58
  • It has a lot of unnecessary stuff, like Jira and Mongo files. If you are not using them, I recommend that you removing it. But besides it, this gitignore is really good, it has everything that I remember it needs. – jonathanrz Dec 17 '17 at 16:32