将现有的Android项目导入到Eclipse中

8

在将现有的Android项目导入Eclipse时,project.properties文件的更新不正确。该文件存在于源代码控制中:

# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system use,
# "ant.properties", and override values to adapt the script to your
# project structure.

# Project target.
target=Google Inc.:Google APIs:14

导入项目后(不进行任何其他操作),文件看起来像这样:

# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system use,
# "ant.properties", and override values to adapt the script to your
# project structure.

# Project target.
target=android-8

清单包含以下内容:
<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="14"/>

这意味着每次有人导入项目时,我们都需要在项目-属性-Android菜单中重置构建目标。我已安装最新的ADT工具,并且所有SDK都已下载并可用。
我尝试过以下方法:
1. 删除整个项目,包括磁盘上的内容,在导入之前克隆并删除project.properties文件。结果相同。 2. 删除整个项目,包括磁盘上的内容,在导入之前克隆并删除.settings文件夹。结果相同。 3. 删除整个项目,包括磁盘上的内容,仅为了好玩而克隆和导入。结果相同。 4. 仔细查看.project文件。没有有趣的东西。 5. 双重检查ant.properties、build.xml以及其他可读的纯文本文件以寻找线索。没有有趣的东西。 6. 搜索问题并双重检查Eclipse和ADT错误网站以查找已知问题。没有发现。 7. 在文件系统上验证文件确实在克隆后具有正确的设置,并且导入是罪魁祸首。 8. 删除整个项目,包括磁盘上的内容,在导入之前克隆,手动编辑project.properties文件到android-14,然后导入。这导致project.properties文件未更改,但由于我正在使用Google APIs进行映射,因此无法接受。
我刚刚验证了一下,我可以在导入后“修复”项目。从Eclipse中删除项目但将内容保留在磁盘上。错误的导入过程再次编辑project.properties。导入过程无法识别project.properties中的Google APIs条目。
这是我将项目从文件系统导入到Eclipse中的方式:
思路是什么?

我在stackoverflow上浏览了一下,发现有两种导入现有项目的方法。也许如果您尝试通过import>General>Existing Project into Workspace进行导入,它就不会出现这种奇怪的变化。只是一个想法。 - JochemQuery
1
失去了Android包结构。我提交了一个错误报告:https://code.google.com/p/android/issues/detail?id=54828 - Bill Mote
嗨,比尔。我也遇到了相同的问题。你找到解决方法了吗? - Rajat Anantharam
@RajatAnantharam 我没有。 - Bill Mote
2个回答

2
现在,为了避免项目属性文件被错误地自动生成,请使用“General”->“Existing Projects into Workspace”而不是“Android”->“Existing Android Code into Workspace”。
如果您的Android项目没有.classpath文件,则Android包结构会丢失。但是,如果您的Android项目已经是一个Eclipse项目,那么它应该可以正常导入。
这是Eclipse中的一个bug。http://code.google.com/p/android/issues/detail?id=40161 这段摘录解释了问题。
"If you want to import an Eclipse project with a .classpath file, you can use the general Eclipse project import feature. It can be found under Import > General > Existing Projects Into Workspace. We added the Import > Android > Existing Android Code Into Workspace option because many people had non-Eclipse projects that were not well-supported. You had to create a new project and then select "existing code" using a checkbox, but the location of the project and existing sources was unclear. We made the Existing Android Code import option work for Eclipse projects too so that it would be easier to import source code. However, this is new code and not the general Eclipse built-in import code, which is why it does not pick up the project name as it used to. The related code that handled adding new projects from source also acted in the same quirky way, picking a project name from the manifest. However, it should be possible to make it look up the project name from the .project file as a better default if present, so I will try to add that as well."

很好的数据,但并不完全是同样的问题,目前也没有解决方案。顺便提一下,我已经提交了一个错误报告。尽管没有解决,但还是要给你点赞 :) - Bill Mote
你的回答帮了我很多。 - Thirumalvalavan

-1

按照您正在进行的方式将项目导入工作区,即将现有的Android代码导入工作区。

现在删除project.properties文件。清理并构建项目。

方法2:

如果现有项目具有build.xml文件,请使用此ant构建文件导入选项导入项目

新建-->其他-->从现有Ant文件导入Java项目-->

按照进一步的选项操作,完成后就可以了

方法3:

右键单击您的项目--->项目属性 转到Android 选择适当的API级别。 清理和构建您的项目.... 完成了


不行。请仔细阅读上面的内容。这两个答案都不起作用,因为它们都会导致创建错误的project.properties文件。关键在于导入失败,并且必须在事后手动设置API级别。 - Bill Mote
1
是的,没错 Bill ,感谢您的澄清。 - Java Crazy

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接