I try to import my Android Studio project on different machines and wondering which project files are realy needed. For example the .idea or .gradle directories. I won't to much trash in my svn repo. Can someone tell my more about required files for Android Studio projects?
You need to keep these files in your root project
app folder (tough ignore the build folder inside it recursively, it's a big waste of space)
gradle
.gitignore if you are using GIT
build.gradle
gradle.properties if you want to have the same configuration on all of your pc's. You need to cinfugure it first tough.
gradlew
gradlew.bat
settings.gradle
Anything else that is not on the list and was not created by you, can be ignored
Make sure you ignore these by file name wildcard. This is the garbage created by macs and windows machines.
.DS_Store
desktop.ini
Thumbs.db
*.iml (garbage created by Android studio)
I truely recomend you to use git in Android Studio, the integration is awesome and it`s so easy to use. It select the files u need for you and have really good tools for merge files.
Related
I'm trying to move my IntelliJ IDEA (2017.3) Android project to another computer just copying the files and it does not work. I am aware of this and this, but in the case of Android project it does not work. All the xml files inside .idea store paths relative to the home ($USER_HOME$) instead of project home ($PROJECT_DIR$). Oddly, Maven projects seem to generate paths relative to the project home and those ones can be copied. But not with gradle projects.
Anyone knows how to solve this ?
EDIT: Bear in mind that I want to copy ALL project settings included running configurations. I want that someone opens the project and find exactly what I have. I know I can reimport the project, but then I'll loose some configuration.
Here's the files and folders that need to be excluded from the copy (assuming that your project has a module called app), preferably if you copy the entire project folder to some where else on the same computer and then deleting the unneeded one by one:
folders .idea, .gradle or any folder who's name starts with a .. They are usually found within the root folder of the project and within the module root folder.
build folder found in the project root folder and in module root folder.
any file who's extension is .iml, found in the project root folder and in module root folder.
local.properties found in project root folder.
The rest of the files and folders need to be kept. With the above excluded, the project can be re-imported in Android Studio properly with the correct configurations relative to your second PC.
On a side note, these are the typical exclusions added in .gitignore of an Android Project Git Repo.
Ok, I found the problem. It is related to how gradle resolve symlinks. This is the issue. Summarizing, if you open your project with a path that contains a symlink, absolute paths will be created in the configuration files and your project won't be portable.
I have reopened the project again using an absolute path and then all the configuration files use PROJECT_DIR instead of USER_HOME
Every project created in Android Studio 1.0.2 contains several files that reference the project's own absolute path. I can't even move my own project directory if I want to, let alone share the project with other developers.
Excluding files in app/build, these are the files containing absolute paths:
.idea/workspace.xml
.idea/modules.xml
.idea/libraries/support_v4_21_0_3.xml
.idea/libraries/appcompat_v7_21_0_3.xml
.idea/gradle.xml
.gradle/2.2.1/taskArtifacts/taskArtifacts.bin
.gradle/2.2.1/taskArtifacts/fileSnapshots.bin
app/app.iml
How do I force Android Studio to use relative paths for everything?
Edit: By experimenting with vanilla IDEA, I've narrowed down the origin of these absolute paths to a specific type of module, which Android Studio apparently always uses without offering you a choice. But I'm still no closer to understanding how to eradicate them.
In IDEA 14.0.2, if you create an empty project or an Android project with an "Application Module", the project does not contain any absolute paths. If you create a project with a "Gradle: Android Module", then it contains absolute paths in the same files as an Android Studio project.
Edit #2: Created IDEA-134587
In general, don't consider any of the .iml files or the contents of the .idea folder to be part of the project, and don't share any of those files, don't check them into source control, and don't move them with the project. Think of them as cache files.
The Gradle files are the source of truth, so if you're having troubles with absolute paths, close the project, delete the non-shareable files, and re-import it from the Gradle build scripts.
I ran into the exact same problem, but the solution suggested above contradicts JetBrains' advice as well as this answer. Also, my co-worker working from the same source code (with unexpanded paths) and Android Studio version wasn't having the problem, so I kept banging my head against the wall.
We eventually solved the problem when we realized that many of the paths I used included symlinks. In my case, I had a symlink set up for ~/work so that it pointed to /some/drive/with/space. Within Android Studio all of my source was referred to from ~/work/source rather than /some/drive/with/space/source. When I changed everything so that Android Studio referred to things with their actual paths, the $PROJECT_DIR$ and $MODULE_DIR$ variables magically started working and my .iml files were no longer getting corrupted. YMMV.
TL;DR: Don't use symlinks in your project paths!
Also, be sure to not keep the files within .gradle as part of your shared project.
Also, one set of files that you might want to share though are your files under .idea/copyright though as that allows you to have shared copyright settings.
So a possible .gitignore file might be:
.gradle
.idea
!.idea/copyright/[YourCopyrightFile].xml
!.idea/copyright/profile_settings.xml
*.iml
build
local.properties
Hmm. I just don't see the same absolute paths in those files, I only see references to MODULE_DIR and PROJECT_DIR, such as:
./app/app.iml: <excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
or:
./.idea/workspace.xml: <entry file="file://$PROJECT_DIR$/.idea/libraries/appcompat_v7_21_0_2.xml">
I wonder if this is Linux issue only, or something in your settings?
Can I just ignore into the gitignore the *.iml and misc.xml files inside and Android Studio project?
Where can I find an official gitignore for Android Studio?
Can I just ignore into the gitignore the *.iml and misc.xml files inside and Android Studio project?
Sure, why not? Android Studio is generally very good at importing Android Gradle projects and recreating the IDEA files, so anyone else working on the project shouldn't have a problem checking out the project and getting it to build.
There isn't an "official" .gitignore. What you choose to ignore is generally left up to you.
Most of Android Studio's configuration files (the .iml files and everything under /.idea) are basic project configuration that you don't need to worry about. If you are making changes such as manually ignoring folders in the IDE or disabling certain IDE code quality checks, you might want to check those respective files in so you have a consistent project setup across your team. For the vast majority of projects, you do not need those files at all.
Some teams also prefer ignoring all IDE-generated files and folders to keep the project IDE-agnostic. Whether you want to do that or you want to enforce a particular IDE on your team is another decision left up to you.
When you create a new Android Studio project, it will automatically generate a .gitignore for you. The default .gitignore as of October 2014 looks like this:
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
.idea/
app/app.iml
*.iml
Android Studio also currently generates a second .gitignore in your Android module's directory containing just /build.
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.
I am using IntelliJ Idea for Android development and IntelliJ uses a folder named out for putting APK file.
I am also using Mercurial as VCS and when I clone the project the out folder is left out from the cloned directory.
Also folder out is also not shown in the project structure and when I go to Open Module Settings -> Modules the folder is excluded as shown in the image below
Why out folder is excluded and how to include it in VCS (Mercurial)?
Why out folder is excluded
Because this folder doesn't contain sources and (I suppose) IntelliJ mirror own settings into .hgignore file of related repository
how to include it in VCS (Mercurial)?
Just
Never do it
because versioning of build artifacts is bad idea, useless, wasted time and space - save only sources, not repeatable results
but, if you want to try all racks on the way - remove the related string from .hgignore.