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.
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"
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.
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
In my case the .gitignore file was placed inside app directory instead of being in root of project directory.
I figured this out by:
Open Project View in Android Studio
Right-click on build folder
Select Git
Add to .gitignore
Related
I am new to React Native and I work with a colleague on a new app. I created a new react native project which has generated a .gitgnore file as well. In it all the .gradle files (and thus the build.gradle file inside /android/ folder) are ignored.
When I pushed the project to Github and my colleague pulled, he npm install to download the node_modules (which are also excluded <- I have read the rational behind this) and then he run react-native run-android. This failed. We realised that if he creates the build.gradle file inside /android/ and copy-paste the contents of my build.gradle which I have locally (as is ignored by git) everything runs smoothly.
My main questions are:
1) Should the build.gradle file be ignored as react native does by default?
2) If yes, how are teams supposed to work on a react native project if they somehow need to get the build.gradle contents to run the project on their side?
3) What happens if my disk drive fails? I can pull everything from git but I will not have the build.gradle. Should I right it from scratch?
The contents of the .gitignore file:
# OSX
#
.DS_Store
# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate
project.xcworkspace
# Android/IntelliJ
#
build/
.idea
.gradle
local.properties
*.iml
# node.js
#
node_modules/
npm-debug.log
yarn-error.log
# BUCK
buck-out/
\.buckd/
*.keystore
# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/
*/fastlane/report.xml
*/fastlane/Preview.html
*/fastlane/screenshots
# Bundle artifact
*.jsbundle
It is .gradle file in .gitignore and not the *.gradle or build,gradle.
So the answer to your questions is build.gradle is not ignored and should not have to be ignored.
The android related things included in .gitignore are:
build/
.idea
.gradle
local.properties
*.iml
android/gradle.properties
For standard, you can refer to this below two sample .gitignore file.(you can replace your .gitignore contents with the below link contents and can check.)
enter link description here
https://github.com/facebook/react-native/blob/master/.gitignore
https://github.com/facebook/react-native/blob/master/local-cli/templates/HelloWorld/_gitignore
You have to check in your build.gradle files, only the .gradle directory should be ignored.
I'm new to Git and Android development and I could not find an answer to this question.
When I build a project in Android Studio a lot of files are created in the folder app/build.
I guess I don't need that files, but before ignoring them in the .gitignore, I would like to be sure to not mess my repo since from the first commit :D
I checked this question, but I cannot see in the example .gitignore the folder app/build.
Should I add it to my .gitignore?
P.S. I'm using Android Studio 2.2.3, if relevant
I guess I don't need that files, but before ignoring them in the .gitignore I would like to be sure to not mess my repo since from the first commit :D
You don't need build files in your repo.
Usually .gitignore file contains /build.
I checked this question but I cannot see in the example .gitignore the folder app/build.
You can place another one .gitignore file to app directory, the content of this file also contains /build.
/project
.gitignore
/app
.gitignore
If I copy/past the example .gitignore (which contains build/ ) in the app/ folder, build files are not ignored.
That would be because those files are already tracked.
Try:
cd app
git rm --cached -r build/
git add .
git commit -m "record build content deletion"
git push
Then app/build will be ignored.
Have a look at gitignore.io for generating gitignore files
Question partially related with gitignore file.
Now when you create an Android project, Android Studio creates .gitignore with your project.
BUT it does not help, these files would be ignored if your code is already in git repository and ignored files ARE NOT already pushed.
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
Now i create a project, Android Studio creates tons of other files including , .idea .IML and so on and i have no idea how can i clean these irrelevant files and folder so i can push clean code to he repository.
Should i do this manually
if ignored files are already in your repository then you should cut them to a new folder outside repository (ex. desktop) then commit deleted files and then turn them back to repository ! this time they will not been tracked by git because they are in your .gitignore file
You can use git rm to untrack files without removing them if you have access to a terminal with git.
I created a test project inside of Android Studio and then I used following: VCS -> Enable Version Control Integration -> Git -> Ok, then via Project -> Android -> app, I selected Git -> Add & Commit Directory.
And on another computer with Android Studio installed, I did following: Check out project from Version Control -> Git -> (I modified URL) Git Repository URL -> Clone, Android Studio asked me a lot of questions...
yet, project isn't same as on my original computer...
What am I doing wrong?
* UPDATE *
[alexus#wcmisdlin02 Test]$ git status | grep -A11 Untracked
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# .gitignore
# .idea/
# Test.iml
# build.gradle
# gradle.properties
# gradle/
# gradlew
# gradlew.bat
# settings.gradle
[alexus#wcmisdlin02 Test]$ cat .gitignore
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
[alexus#wcmisdlin02 Test]$
The *.gradle files are required in order to build the app project successfully. In other words, these files should be included in the VCS.
build.gradle contains part of manifest and list of library dependencies.
settings.gradle contains depended projects. Some projects provide entire source code.
The simplest choice is to include all files in the project folder to VCS except files under .idea folder. The .idea folder has IDE(Android Studio) specific files. For reference, the name idea is come from original program IntellJ IDEA.
If you do not want to give permission to change apk file by others, it is better to exclude keystore file.
Upon your editted question, I appended descriptions accordingly as below.
.gradle : .gradle folder has gradle execution files.
/local.properties : the keystore file location or computer-depended information like JDK path are described in here.
/.idea/workspace.xml : it has your IDE panel location or trivial IDE settings.
/.idea/libraries : it is automatically created/regenerated when you clean and build the project. The jar files of dependencies listed in build.gradle are downloaded and stored in here.
.DS_Store : Macintosh OSX specific folder description file.
/build : build results.
/captures : This is not a common thing. It might be your project specific folder.
In Eclipse, I had the custom of adding bin and gen directories to SVN ignore. But now, using Android Studio (based on IntelliJ IDEA), which files should I ignore?
I added the following items in my .gitignore, it should be the same for SVN:
gradle
.idea
*.iml
build
.DS_Store (for mac only)
See this IntelliJ IDEA KB article: "How to manage projects under Version Control Systems".
Add to Subversion:
all files under /.idea directory in the project root but ignore workspace.xml and tasks.xml,
all .iml module files.
I've used the following SVN ignore list sucessfully:
.gradle
local.properties
.idea/workspace.xml
.idea/libraries
.DS_Store
build
The ignore should be applied recursively.
Reference: Same question, for git