Home » Android » How to create new android project in eclipse and share in local git repository?

How to create new android project in eclipse and share in local git repository?

Posted by: admin May 14, 2020 Leave a comment


I use the wizard to create a new Android project in Eclipse Juno with Android SDK Tools revision 20.0.3 at build SDK 15 and minimum required SDK 15. The files are generated with sample code for activity, manifest, etc. I have tried different templates (like MasterDetail or BlankActivity with Tabs) in this process and there are sometimes issues such as AndroidManifest.xml or activity_main.xml with repeated XML elements. So I fix these issues manually (which I think is a bug with the wizard).

Now, I want to “team share” the project via EGIT. So I right-click the project and “Team->Share Project->git”. At this point, it wants me to choose a repository. I have created a new one outside Eclipse workspace (and re-used it once created). (I also tried creating one in the parent directory (i.e. in workspace despite an Eclipse warning not to do so).

Either way, when the share operation completes, the buildpath for Libraries “Android Dependencies” does not have the “android-support-v4.jar” in the location specified which was in the workspace. It seems that after the egit operation, the project directory appears to have been moved to the repository, but the .classpath file has not changed.

Is this how egit should work (move project workspace inside git repo and tell Eclipse that the project directory is in a new location)? Is the only workaround to fix the buildpath manually?

Is there a different approach to create new android project in Eclipse and then put the relevant files (i.e. exclude generated java files) into a local git repository such that Eclipse EGIT works?

How to&Answers:

I am answering my own question after some trial and error.

Here are the steps.

  1. Create the android project via the wizard.
  2. Fix any XML errors (as necessary) to get a buildable project.
  3. Right-click project and Team->Share Project->Git
  4. Select the Git Repository (and create if necessary).

At this point, the Android Dependencies (a dynamic classpath container) in the Java Build Path will be wrong because Git has moved the files to the repository.

  1. Close the project (Project->Close Project)
  2. Re-open project (Project->Open Project)
    Now, the Android Dependencies are correct because it is dynamic. I don’t know the exact mechanism used by Eclipse for dynamic classpath container, but if you read the Android Tools website it will explain the rules used to to populate this container.
  3. Clean the project. (Project->Clean…)

The important thing is not to try to fix these Android Dependencies yourself (like deleting it), because then your Android project may have issues when you start to build the APK.