gitignoring Android Studio app - android

In the file structure, you have
Project Name
.idea
app
build
libs
src
app.iml
build.gradle
build
gradle
...
I have .gitignored the build in the Project Name directory, but is it safe and should I also .gitignore build in the app directory?

Yes, it is safe. Files in build folder can be regenerated when you re-import the project next time.

Related

gradle directory is not included in default `.gitignore`

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.

Gradle file push to github repository

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.

Android Studio project with Github

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/

Which files to ignore using to commit to SVN in Android Studio

Which files do i have to put on ignore in SVN when im using Android Studio?
Currently i have ignored this files:
*.idea
gradle
*.iml
build
local.properties
.DS_Store
When you create an Android Studio project, .gitignore files will be also generated.
Based on that, in the parent folder we exclude:
-.gradle
-/local.properties
-/.idea/workspace.xml
-.DS_Store
And in the modules directory:
-/build
Personally when I'm working on Android project I ignore the folder bin , project.property, classpath, settins/org.eclipse.jdt.core.pref , proguard-project.txt , local.properties .
I don't use Ant or Maven so maybe there are others files to ignore.

Which files should I add to SVN ignore for an Android Studio project?

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

Categories

Resources