将现有的 Android 项目导入 Eclipse

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16301759/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 20:26:31  来源:igfitidea点击:

Importing Existing Android Project into Eclipse

androideclipse

提问by Bill Mote

project.properties is being updated incorrectly when importing an Existing Android project into Eclipse. This file exists in source control:

将现有 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

After importing the project (and doing NOTHING else) the file looks like this:

导入项目(并且什么都不做)后,文件如下所示:

# 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

The manifest has the following items:

清单包含以下项目:

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="14"/>

This means that every time someone imports the project we're having to reset the build target in the project->properties->android menu. I have the latest ADT tools installed and all SDKs are downloaded and available.

这意味着每次有人导入项目时,我们都必须在 project->properties->android 菜单中重置构建目标。我安装了最新的 ADT 工具,所有 SDK 都已下载并可用。

Things I've tried:

我尝试过的事情:

  1. Deleting the entire project including contents on disk, cloning and deleting the project.properties file before importing. Same result.
  2. Deleting the entire project including contents on disk, cloning and deleting the .settings folder before importing. Same result.
  3. Deleting the entire project including contents on disk, cloning and importing just for grins. Same result.
  4. Scoured through the .project file. Nothing of interest.
  5. Double checked ant.properties, build.xml and every other plain text readable file for clues. Nothing of interest.
  6. Googled the problem and double checked the Eclipse and ADT bug sites for known issues. Nada.
  7. Verified on the file system that the file does, in fact, have the correct setting after cloning and that the import is the culprit.
  8. Deleting the entire project including contents on disk, cloning, MANUALLY editing the project.properties file to android-14, importing. This resulted in an unchanged project.properties file but since I'm using the Google APIs for mapping this is unacceptable.
  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 API 进行映射,这是不可接受的。

I just verified that I can "fix" the project after it's imported. Delete the project from Eclipse but leaving the contents on disk. Importing the project incorrectly edits project.properties again. The import process does not recognize the Google APIs entries in project.properties.

我刚刚确认我可以在导入后“修复”项目。从 Eclipse 中删除项目,但将内容保留在磁盘上。导入项目错误地再次编辑 project.properties。导入过程无法识别 project.properties 中的 Google API 条目。

This is how I'm getting the project from the file system into Eclipse:

这就是我将项目从文件系统获取到 Eclipse 的方式:

enter image description here

在此处输入图片说明

Thoughts?

想法?

回答by josh527

For now use General -> Existing Projects into Workspace instead of the Android -> Existing Android Code into Workspace to avoid the project.properties file being auto generated improperly.

现在使用 General -> Existing Projects into Workspace 而不是 Android -> Existing Android Code into Workspace 以避免错误地自动生成 project.properties 文件。

You are correct, if your android project does not have a .classpath, the android package structure is lost. But if your android project is already an Eclipse project it should import just fine.

你是对的,如果你的 android 项目没有 .classpath,那么 android 包结构就会丢失。但是如果你的 android 项目已经是一个 Eclipse 项目,它应该导入就好了。

This is a bug in eclipse. http://code.google.com/p/android/issues/detail?id=40161

这是eclipse中的一个错误。http://code.google.com/p/android/issues/detail?id=40161

This excerpt explains the problem.

这段摘录解释了这个问题。

"If you are importing an Eclipse project (which has a .classpath), just use the generic Eclipse project import mechanism; that's still there (Import > General > Existing Projects Into Workspace). We added Import > Android > Existing Android Code Into Workspace because a lot of people had non-Eclipse projects to import, which was not well supported; you had to "Create New" and then use a checkbox to select "existing code" etc, and the location of the project and the location of the existing sources was ambiguous. We made the Existing Android Code import option alsowork for Eclipse projects, such that it would be a single obvious way to pull in source code. But this is new code, not the general Eclipse builtin import code, which is why it doesn't pick up the project name in the way it used to. (The related code which handled adding new project from source did act in the same quirky way the code does now, picking a project name from the manifest). However, making it look up the project name from the .project file as a better default, if present, should be doable so I'll try to add that as well."

“如果您要导入 Eclipse 项目(具有 .classpath),只需使用通用 Eclipse 项目导入机制;那仍然存在(导入 > 常规 > 现有项目到工作区)。我们添加了导入 > Android > 现有 Android 代码到工作区因为很多人有非 Eclipse 项目要导入,这没有得到很好的支持;您必须“新建”,然后使用复选框选择“现有代码”等,以及项目的位置和现有的来源是不明确的。我们作出了将现有Android代码导入选项为 Eclipse 项目工作,这样它就可以成为拉入源代码的一种明显方式。但这是新代码,而不是一般的 Eclipse 内置导入代码,这就是为什么它不像以前那样获取项目名称。(处理从源代码添加新项目的相关代码确实以与现在代码相同的古怪方式行事,从清单中选择项目名称)。但是,让它从 .project 文件中查找项目名称作为更好的默认值(如果存在)应该是可行的,所以我也会尝试添加它。”

回答by Java Crazy

import your project as you are doing ie

在你做的时候导入你的项目,即

Existing Android code into workspace.

将现有的 Android 代码放入工作区。

now delete the project.properties. clean and build project.

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

Approach 2:

方法二:

if existing project has build.xml file import project using this ant build file import option

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

New-->other-->Java Project from existing Ant file-->

新建-->其他-->来自现有Ant文件的Java项目-->

follow further option and you are done

按照进一步的选项,你就完成了

Approach 3

方法三

right click your project ---> project properties go to Android Select appropriate API level. Clean and build your project .... Its done now

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