开发者

How to properly clone an Android project using Eclipse and Mercurial

I'm trying to clone an Android project using Eclipse, the Android SDK, and the Mercurial plug-in. I can successfully clone it by doing this: File -> New -> Project -> Clone Existing Mercurial Repository

But the problems start when Eclipse does not seem to recognize that it is an Android project. I can then right-click on the project and: Android Tools -> Convert to Android Project but I don't get to select any build preferences and the source folder icon doesn't get identified as a package. I try to add a new package but Eclipse says the folder is not a Java source folder.

I fee开发者_如何学编程l like there is either something wrong with the repository, the way I am cloning it, or that Eclipse/Mercurial/Android SDK don't work well together.

Obviously, I'm a complete greenhorn at this and any help/patience is appreciated. Links to useful tutorials are welcome since none that I've found deal with this particular set of tools.


Here's what I do:

  1. Use command line to clone the repository in a separate folder outside of the Eclipse workspace folder hierarchy.

    hg clone https://existing/repository/path

  2. In Eclipse, create a new Android project using the "Create project from existing source" option selecting the cloned folder.

How to properly clone an Android project using Eclipse and Mercurial

The new project is now both an Android project with the Mercurial Team options.


Cloning an Android Project in Eclipse

    Assume you have a WorkSpace at "D:\workspace" and want to clone an existing Android project named "B".
  1. Windows: go to the WorkSpace
  2. Windows: make a copy of the complete project directory named "B" (Windows makes a "B - Copy")
  3. Windows: rename the copied directory "B - copy" into the clones name, in this case: "B_00"
  4. Windows: Go into directory "B_00" and edit file ".project".
    Change the line with "<name>B</name>" into "<name>B_00</name>"
    Windows: save the file
  5. Start Eclipse and open it in your WorkSpace. "B_00" is not visible.
  6. Eclipse: Menu File -> Import
    Eclipse Import dialog Select: select General -> Existing Projects into Workspace
    Eclipse Import dialog Select: push button "Next"
    Eclipse Import dialog Import Projects: select "select root directory" and then "Browse..." to "B_00"
    Eclipse Import dialog Import Projects: push button Finish.
  7. Eclipse: package explorer: select "B_00"
    Eclipse: Menu Project -> Clean...
  8. Done.


I've stumbled upon a solution and believe these were all of the steps needed.

First I created a new project by cloning an existing mercurial project and clicked Properties -> Android Tools -> Convert to an Android Project

Added a PROJECT_DIR/.classpath file:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
        <classpathentry kind="src" path="src"/>
        <classpathentry kind="src" path="gen"/>
        <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
        <classpathentry kind="output" path="bin"/>
</classpath>

Added the buildCommand/javabuilder and natures/javanature lines to PROJECT_DIR/.project:

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
        <name>SuperBetterThanEverythingElseApp</name>
        <comment></comment>
        <projects>
        </projects>
        <buildSpec>
                <buildCommand>
                        <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
                        <arguments>
                        </arguments>
                </buildCommand>
                <buildCommand>
                        <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
                        <arguments>
                        </arguments>
                </buildCommand>
                <buildCommand>
                        <name>com.android.ide.eclipse.adt.ApkBuilder</name>
                        <arguments>
                        </arguments>
                </buildCommand>
                <buildCommand>
                        <name>org.eclipse.jdt.core.javabuilder</name>
                        <arguments>
                        </arguments>
                </buildCommand>
        </buildSpec>
        <natures>
                <nature>com.android.ide.eclipse.adt.AndroidNature</nature>
                <nature>org.eclipse.jdt.core.javanature</nature>
        </natures>
</projectDescription>

Then I closed the project in Eclipse, reopened it, added a missing external jar, did a Project -> Clean, and it worked.


I just did this for a feature branch. All I did was create a clone of the existing project in another directory in the Eclipse workspace, then opened the cloned project in Eclipse.

I did not use the MercurialEclipse plugin to create the clone, I used the File->Clone Repository menu item in the TortoiseHg Workbench. I then called the File->Import->Projects from Local Mercurial Repository menu item from Eclipse to add the new project to the workspace. You should also be able to create the clone from the command line by calling hg.exe (hg help clone will give you the command line options to use).

You don't mention the software versions you are using. I'm using TortoiseHG 2.0.2, Eclipse Helios Service Release 2, and MercurialEclipse 1.8.0 on Windows 7.


Never used the plugin but have been using mercurial externally and uniformly for all my projects (also non-android). Why not try setting up the repository externally. http://redline6561.livejournal.com/362393.html


I didn't see the option to convert to an Android project when following the most popular answer, so here's what I did instead:

  1. Clone the remote repository using the "Mercurial Repositories" view without creating a project.
  2. Make a new Android project using the existing source you've checked out.
  3. If you still don't see the right team options, make mercurial for Eclipse aware that the project is associated with a repository by right-clicking the project itself and selecting "Team" > "Share", then "Mercurial". The local clone of the repository should appear, just select that and save your changes. I only had to do that once, most times the first two steps are enough.

I ended up with a working Android project and am now able to interact with the repository using the normal "Team" menu commands.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜