3

I am working on an Android Studio project where my team members use Windows and I use OSX.

The problem is that when I pull new code from git and then open the project, I get all sorts of changes based on the Mac's SDK location:

First a notice when opening the project: enter image description here

git diff logs a bunch of changes similar to this one:

enter image description here

How do we configure the Android Studio project so that these automatic code changes do not have to occur, or maybe there is a way to minimize the number of files changed?

Update:

I updated the .gitignore and pushed it to the remote repo.

When my team updated more code and I pulled it, I still got the same issues.

Here is a snippet of my git status after pulling (I used "..." to denote multiple files from that folder):

modified:   .idea/gradle.xml
modified:   .idea/misc.xml
modified:   .idea/modules.xml
modified:   .idea/vcs.xml
modified:   app/app.iml
modified:   app/build/intermediates/incremental/mergeAssets/androidTest/debug/merger.xml
…
    modified:   app/build/intermediates/incremental/mergeResources/debug/merger.xml
    modified:   app/build/intermediates/res/debug/anim/abc_fade_in.xml
...
    modified:   app/build/intermediates/res/debug/anim/abc_slide_out_top.xml
    modified:   app/build/intermediates/res/debug/color-v11/abc_background_cache_hint_selector_material_dark.xml
    modified:   app/build/intermediates/res/debug/color-v11/abc_background_cache_hint_selector_material_light.xml
    modified:   app/build/intermediates/res/debug/color/abc_background_cache_hint_selector_material_dark.xml
...
    modified:   app/build/intermediates/res/debug/color/wallet_secondary_text_holo_dark.xml
    modified:   app/build/intermediates/res/debug/drawable/abc_btn_borderless_material.xml
...
    modified:   app/build/intermediates/res/debug/drawable/timeline_button_hover.xml
    modified:   app/build/intermediates/res/debug/layout/abc_action_bar_title_item.xml
...
    modified:   app/build/intermediates/res/debug/layout/support_simple_spinner_dropdown_item.xml
    modified:   app/build/intermediates/res/debug/menu/menu_all_locations.xml
    modified:   app/build/intermediates/res/debug/menu/menu_main.xml
    modified:   app/build/intermediates/res/debug/values-af/values-af.xml
...
    modified:   app/build/intermediates/res/debug/values/values.xml
    modified:   app/build/intermediates/resources/resources-debug-androidTest.ap_
    modified:   app/build/intermediates/resources/resources-debug.ap_
    modified:   build/intermediates/gradle_project_sync_data.bin
    modified:   local.properties

Here is my .gitignore, as suggested by @Gabriele Mariotti:

#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
*.iws
*.iml
.idea
.gradle
build/
*/build/

Do I need additional .gitignore configurations? If I'm excluding .idea then why are these files showing up as changed?

kraftydevil
  • 5,144
  • 6
  • 43
  • 65

1 Answers1

5

Inside the project you will find some Android Studio files, for example the .idea and the iml files inside each module.
Check also this answer for more details.

These resources contain local paths and references and you should exclude them (the .idea folder and iml files) from your git repo.

It is an example of .gitignore we are using with Mac, Linux and Windows users.

#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
*.iws
*.iml
.idea
.gradle
build/
*/build/

If these files are in git repo, you should remove them from the remote repo, and then rebuild the local projects.

Community
  • 1
  • 1
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
  • I had to update the question because the issue was not resolved with this .gitignore. – kraftydevil Oct 05 '15 at 21:00
  • 1
    @kraftydevil of course, editing the gitignore after pushing this folder doesn't resolve your issue. You have to remove the folder and the other files (as .iml), commit and push it into git (to remove them), and rebuild the project using gradle. Locally the folder will be recreated but not pushed again. – Gabriele Mariotti Oct 05 '15 at 21:03
  • Of course, indeed! So it's safe to remove each file 'git status' that revealed? – kraftydevil Oct 05 '15 at 21:12
  • Check also this answer. http://stackoverflow.com/questions/32494631/delete-project-and-all-setting-from-android-studio/32494701#32494701 You can delete the Android Studio folder and files, because gradle will rebuild them. You can try it locally in your machine. – Gabriele Mariotti Oct 05 '15 at 21:17
  • any suggestions on how to remove all the correct files without manually executing `git rm` on each one? – kraftydevil Oct 05 '15 at 21:29
  • delete the files locally in 1 pc (windows or mac). Rebuild the project and try if it is ok. At this point commit and push the changes on the remote repo. – Gabriele Mariotti Oct 05 '15 at 21:33
  • I was able to use `git ls-files --modified | xargs git rm -f` to find the right files to remove without having to manually delete – kraftydevil Oct 05 '15 at 21:45
  • @kraftydevil In any case I have updated the answer with more details – Gabriele Mariotti Oct 05 '15 at 22:17
  • I was able to resolve my issue after following your instructions. After deleting and pushing, I opened the project again and got an "Unlinked Gradle Project?". I then followed it's suggestion to "Import Gradle project" and could build it without the extra files showing up in source control. – kraftydevil Oct 05 '15 at 22:31
  • 1
    [this post](https://devnet.jetbrains.com/thread/293573) would suggest that one should *include* `misc.xml` in git – Jon Nov 12 '15 at 21:05