I automatic generated .gitignore in a Android Java project looks like this:
*.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
Why is the gradle directory not included in this file?
The gradle directory shouldn't be ignored because it hold the configuration for the Gradle Wrapper.
Checkout the docs for further information about the wrapper.
Some files in the gradle folder provide important information about how the project can be built. For that reason is suggested that you don't ignore the entire gradle folder.
e.g. the gradle wrapper:
Generates scripts (for *nix and windows) which allow you to build your project with Gradle, without having to install Gradle.
When a user executes a wrapper script the first time, the script downloads and installs the appropriate Gradle distribution and runs the build against this downloaded distribution. Any installed Gradle distribution is ignored when using the wrapper scripts.
The scripts generated by this task are intended to be committed to your version control system. This task also generates a small gradle-wrapper.jar bootstrap JAR file and properties file which should also be committed to your VCS. The scripts delegates to this JAR.
(source)
People argue though that this shouldn't be necessary (check comments on this thread). So it's down to you whether you want to ignore the entire folder or just the .gradle files.
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 was pushing my Android application project to my github repository. I saw two folder .gradle and gradle were not pushed but another folder called gradle/wrapper instead got pushed. I am not sure where this gradle/wrapper folder came from and if this is a normal thing that happens when pushing an Android app.
Edit: I closely inspected a bit more and the gradle folder that I was talking about is the gradle/wrapper folder. It is just that I didn't expand that folder initially. The .gradle folder is still not showing up in my Github repository though.
The .gradle folder should not be committed and should be included as part of the gitignore
https://www.gitignore.io/api/android,androidstudio
This is the directory used by the wrapper on your local machine to store the downloaded Gradle dependencies (as compared to installing Gradle separately yourself and configuring the IDE to use that)
build.gradle and settings.gradle should be the least amount of required files for any Gradle project, the wrapper is optional but recommended to standardize the version of Gradle used to build the project
if you don't see a file that you have pushed via git, please check your .gitignore file.
Gradle/wrapper folder is generated upon building.
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
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.
With the change to the Gradle build system, I've noticed a bunch of *.xml files added to the .idea/libraries project directory. I'd assume this is how Android Studio/IntelliJ links libraries to the project.
Is it ok/recommended to add .idea/libraries to .gitignore? Since gradle handles all dependencies, I'd think either way these would be added/overwritten. Hoping for some confirmation.
Yes, why not.
I've been ignoring the whole .idea directory in my .gitignore, to avoid unnecessary changes get into the repo. Those IDE configurations can be regenerated from Gradle files.