1

I'm asking this question on behalf of my team of two Android devs. I use Windows and my partner uses a Macbook. When sharing a project through Git, the classpaths accidentally got messed up. Here are a few observations:

  • The library projects referenced (working initially) can't be resolved anymore.
  • When adding through the Projects tab in 'Java Build Path', the libraries can be found.
  • But the app crashes (due to NoClassDefFoundError), again pointing towards a messy build path structure.
  • Initially referenced library projects on the Mac used to appear directly in the build path as JARs. Now they do under Android Dependencies, which is weird (the former more).
  • On the Windows, the above JARs have always been under Dependencies and Referenced Libraries.

I'd like to resolve this issue in a way that we can share the project on Git and work seamlessly in the future. :)

SlashG
  • 671
  • 4
  • 17

1 Answers1

1

One option is to:

  • not version .classpath,
  • version a classpath template
  • generate the right classpath depending on the current platform where the code is checked out.

That is called a content filter driver, here a smudge script, which will be called automatically (hence the "seamless" aspect) on git checkout, and will generate the actual .classpath (otherwise not versioned and add in the .gitignore)

http://git-scm.com/book/en/v2/book/08-customizing-git/images/smudge.png

(image shown in "Customizing Git - Git Attributes", from "Pro Git book")

Note that you can easily remove (without deleting it locally) the .classpath from the repo:

git rm --cached -- .classpath
git add -u .
git commit -m "Delete .classpath"
git push
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • The `.classpath` was added to the commits by mistake. Also, I'm pretty new to Git and haven't used a `smudge` script before. I'll surely read more about it and fashion one for my project. Thank you very much! :) – SlashG Jun 03 '15 at 06:46
  • 1
    @SlashG you can easily remove it (without deleting it): `git rm --cached -- .classpath; git add -u . ; git commit -m "Delete .classpath"` – VonC Jun 03 '15 at 06:47
  • @SlashG a smudge script can be written in any script language you want. A bash script will work both on Windows and Linux. – VonC Jun 03 '15 at 06:48
  • Thank you for the remove tip (especially)! I hope it works well. – SlashG Jun 03 '15 at 07:14
  • @SlashG OK. I have included the removal process in the answer for more visibility. – VonC Jun 03 '15 at 07:22