Farbod Salamat-Zadeh
Farbod Salamat-Zadeh

Reputation: 20080

Gitignore not ignoring some build files in Android library

I have an Android library and for some reason, the files and folders I have specified in my .gitignore are not being ignored.

I have tried modifying my .gitignore and also following these steps, but this doesn't change anything.

Here is my top-level .gitignore (which can also be found on the GitHub repo):

# Gradle files
.gradle/
build/
*/build/

# Local configuration file (sdk path, etc)
local.properties

# IntelliJ
*.iml
/.idea

The module with the build folder that isn't being ignored has the following .gitignore:

/build/

I'm not sure why the build directory isn't being ignored, as it is being ignored in my sample app module, and in the top-level directory.

Also, I did commit changes to some files in the build directory when I updated versions of my library, if that's important.

Upvotes: 19

Views: 11947

Answers (4)

Safeer
Safeer

Reputation: 1467

In my case the .gitignore file was placed inside app directory instead of being in root of project directory.

I figured this out by:

  1. Open Project View in Android Studio
  2. Right-click on build folder
  3. Select Git
  4. Add to .gitignore

Upvotes: 1

Fakhriddin Abdullaev
Fakhriddin Abdullaev

Reputation: 4910

Add .gitignore file in your project, and set below lines:

*.iml
.gradle
/local.properties
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/build
/captures
.externalNativeBuild
.idea

enter image description here

Upvotes: 1

Farbod Salamat-Zadeh
Farbod Salamat-Zadeh

Reputation: 20080

This answer on Stack Overflow helped me solve my issue.

Here is part of that answer:

First commit any outstanding code changes, and then, run this command:

git rm -r --cached .

This removes any changed files from the index(staging area), then just run:

git add .

Commit it:

git commit -m ".gitignore is now working"

Upvotes: 50

Jekabz
Jekabz

Reputation: 41

You must remove the first / in your lower level gitignore before build, it will work then. Also, in top level, you only need this: build/ and then no lower level gitignore will be needed.

Upvotes: 3

Related Questions