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.
Related
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.
I would like to commit changes which I did in my AS project. But I see that changeslist contains release folder:
It means that I will commit workable apk file and some config files which were generated during building installer. I can also untick these files but when I will try to make commit at the next time I will see these files again. Maybe I can remove these files totally from my changes list and prevent its appearing at all next times. I think it happens because I tried some commands at the terminal and one command can add these files, I think it was:
git commit --am
So, how I can solve this problem without damaging all project?
UPDATE:
Can I solve my problem with the command:
git rm --app-release.apk ?
First Things first:
You can add a .gitignore file to your repository, via terminal, by the commands below:
In Terminal, navigate to the location of your Git repository.
Enter touch .gitignore to create a .gitignore file.
Second, you should pay attention that, If you already have a file checked in and you want to ignore it, Git will not ignore the file if you add a rule later. In those cases, you must untrack the file first, by running the following command in your terminal:
$ git rm --cached FILENAME
for more information on this follow https://help.github.com/en/articles/ignoring-files
First add the file/folder to your .gitignore file (In your case, the app-level one and not the project-level one)
Go to the Terminal in Android Studio and type in these commands:
git rm -r the-directory-to-remove In which case your the-directory-to-remove is the release folder.
The above command will remove the specified directory from git.
git commit -m "Delete release folder"
The above command commits the changes, you can change "Delete release folder" to whatever you like.
git push origin <your-git-branch>
The above command pushes the changes to Github (or BitBucket).
Now, if you want to delete the file from Github/BitBucket ONLY but not from the entire git filesystem, run git rm -r --cached myFolder instead of the first command.
you need to add those files in your ignored files under version control area in your android studio. For navigation go to
Open File -> Settings -> Version Control -> Ignored Files.
Add files those you don't want to commit or include. Another way of doing it like the other answer suggested to do it with .gradle tools.
I'd recommend using https://www.gitignore.io/ for generating .gitignore file for your android project and put it in your root folder of the project.
https://www.gitignore.io/api/android gives a headstart for your android project(Modify this according to your requirement. But for most cases this should be out-of-the-box solution).
Also, to add to the point. This is expected behaviour of git and not related anyway to android studio/android.
Step 1: Remove file's from staging area using below command
git reset HEAD file
check this
similar post
Step 2: add release folder and other generated file's to your .gitignore
Ref:
If you have a gitignore file then add this line
# Built application files
*.apk
*.ap_
*.aab
# Files for the ART/Dalvik VM
*.dex
# Java class files
*.class
# Generated files
bin/
gen/
out/
# Gradle files
.gradle/
build/
# Local configuration file (sdk path, etc)
local.properties
# Proguard folder generated by Eclipse
proguard/
# Log Files
*.log
# Android Studio Navigation editor temp files
.navigation/
# Android Studio captures folder
captures/
# IntelliJ
*.iml
.idea/workspace.xml
.idea/tasks.xml
.idea/gradle.xml
.idea/assetWizardSettings.xml
.idea/dictionaries
.idea/libraries
.idea/caches
# Keystore files
# Uncomment the following lines if you do not want to check your keystore
files in.
#*.jks
#*.keystore
# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild
# Google Services (e.g. APIs or Firebase)
google-services.json
# Freeline
freeline.py
freeline/
freeline_project_description.json
# fastlane
fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output
fastlane/readme.md
or create a .gitignore file in your root folder of project
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 am currently working on a Android Studio Project that I am sharing with other team mates. In order to do this we are using GitHub to share the Project.
I tried using the option "Check out project from Version Control". However one I successfully download and open the Project I get "Error Loading Project: Cannot load 2 modules", being two .iml files, one which is the app.iml. This prevents me from accessing the app folder from the project, hence I cannot work with it in Android Studio.
I have tried downloading it from our GitHub repository directly and opening it with Android Studio, however I get the same error.
Can anyone help me figure out how to successfully run a GitHub shared Android Studio project?
I am running this on Windows 10.
.iml files are the local configuration of the IDE, you and other team members should add it to .gitignore.
Also you can deleted them any time you want , and select Build Project from the Run menu. They will be generared again.
That's because .iml files are specific for local configurations. You have to remove them manually from the repository and not push them. I recommend to you to use a .gitignore file that can be either global or a project file with some classic Android excludes:
#built application files
*.apk
*.ap_
# files for the dex VM
*.dex
# Java class files
*.class
# generated files
bin/
gen/
# Local configuration file (sdk path, etc)
local.properties
# Windows thumbnail db
Thumbs.db
# OSX files
.DS_Store
# Eclipse project files
.classpath
.project
# Android Studio
*.iml
.idea
#.idea/workspace.xml - remove # and delete .idea if it better suit your needs.
.gradle
build/
#NDK
obj/
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.