从 Android Git 创建 Eclipse 项目
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2211689/
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
Create Eclipse Project from Android Git
提问by Kleptine
I've downloaded one of the open source Android Applications (the music application) from the Android git, and I'm trying to create a new project from the source. Creating a new project using that existing source doesn't work giving me an "invalid description error". Any help?
我已经从 Android git 下载了一个开源 Android 应用程序(音乐应用程序),我正在尝试从源代码创建一个新项目。使用该现有源创建一个新项目不起作用,给我一个“无效的描述错误”。有什么帮助吗?
回答by VonC
You must be referring to the error message "invalid project description
".
您一定是指错误消息“ invalid project description
”。
See this thread(relevant extracts below, with emphasis mine):
请参阅此线程(以下相关摘录,重点是我的):
If you see a .project in the application you downloaded, you can try a "File" + "Import" + "Existing Projects into Workspace"
and select the directory of the music sample.
如果您在下载的应用程序中看到一个 .project,您可以尝试 a"File" + "Import" + "Existing Projects into Workspace"
并选择音乐样本的目录。
But if not, using New> Android Project> Create project from existing source
is the
right way to do it.
Make sure to select which Android target you want (1.1 or 1.5 or 2.0):
the "new project" wizard will automatically select the right sample directory for you.
Then select "Browse" and the Music directory. It should then fill the properties at the bottom of the new android project wizard.
但如果没有,使用New> Android Project> Create project from existing source
是正确的方法。
确保选择您想要的 Android 目标(1.1 或 1.5 或 2.0):
“新项目”向导将自动为您选择正确的示例目录。
然后选择“浏览”和音乐目录。然后它应该填充新 android 项目向导底部的属性。
However you should not put your workspace in
%ANDROID_HOME%\samples
.
Leave it somewhere else (My Documents, whatever).
I suspect you get a conflict because Eclipse tries to create a project and there's already a directory of the same name.
In either case, can you look atyour_workspace_dir/.metadata/.log
for a more verbose error and post it?
但是,您不应将工作区放在
%ANDROID_HOME%\samples
.
把它放在其他地方(我的文档,不管怎样)。
我怀疑您会遇到冲突,因为 Eclipse 尝试创建一个项目并且已经有一个同名目录。
在这两种情况下,您能否查看your_workspace_dir/.metadata/.log
更详细的错误并将其发布?
In short:
简而言之:
- Change the workspace other than android SDK.
- Then dont put project name first.
- Browse the project of
\samples\Music
in create project from the source.- The other fields will fill automaticaly.
- Then execute....
- 更改 android SDK 以外的工作区。
- 然后不要把项目名称放在第一位。
\samples\Music
从源浏览创建项目中的项目。- 其他字段将自动填充。
- 然后执行....
See also this tutorial(for the Snake sample)
另请参阅本教程(对于 Snake 示例)
I wanted to open up the Snake sample provided in the SDK samples.
For this, choose ‘Create project from existing source
' in theNew Android Project
window and select theSnake
directory fromSamples
.
This will set the package name, activity name, and application name for you.
我想打开 SDK 示例中提供的 Snake 示例。
为此,请Create project from existing source
在New Android Project
窗口中选择“ ”并Snake
从 中选择目录Samples
。
这将为您设置包名称、活动名称和应用程序名称。
That being said, if after importing the project, you end up (like the OP) with tons of errors.
See question R cannot be resolved - android error:
话虽如此,如果在导入项目后,您最终(如 OP)会出现大量错误。
请参阅问题R 无法解决 - android 错误:
- make sure the tools in the SDK directory have the permission to be executed
- go to
Project > Build all
(and selecting "Build Automatically
"
- 确保SDK目录下的tools有执行权限
- 转到
Project > Build all
(并选择“Build Automatically
”
R is an automatically generated class that holds the constants used to identify your resources.
R 是一个自动生成的类,其中包含用于标识您的资源的常量。
Other cause for massive compilation errors all over the Eclipse Android project, as reported by the OP himself (GuyNtheitroad):
OP 本人 ( GuyNtheitroad)报告了 Eclipse Android 项目中大量编译错误的其他原因:
The code I downloaded from git was the newest version, and probably for Android 2.1, where the SDK I'm was creating it under was Android 1.5.
So I'll need to download older code or install the latest SDK.
我从 git 下载的代码是最新版本,可能适用于 Android 2.1,我在其中创建它的 SDK 是 Android 1.5。
所以我需要下载旧代码或安装最新的 SDK。
回答by dB Wood
I was still getting the "invalid project description" error with the Android 2.3 SDK examples (Eclipse Helios 20100917-0705, Ubuntu 10.10). It won't import the existing projects.
对于 Android 2.3 SDK 示例(Eclipse Helios 20100917-0705,Ubuntu 10.10),我仍然收到“无效的项目描述”错误。它不会导入现有项目。
WORKAROUND:
解决方法:
- Place the project in a owned directory (I copied them from my SDK install at /opt/anrdroid-sdk-linux_86) to my ~/workspace directory.
- Using the Java Package Explorer view /New/JavaProject, enter the project directory name (you should see the existing files on the 2nd wizard page)
- In Package Manager, select the new project: Android Tools/Convert to Android Project
- Create the /gen project directory if it doesn't exist (fails without it)
- Android Tools/Fix Project Properties
- Main Menu/Project/Build Project
- 将项目放在一个拥有的目录中(我从 /opt/anrdroid-sdk-linux_86 的 SDK 安装中复制它们)到我的 ~/workspace 目录。
- 使用 Java Package Explorer 视图 /New/JavaProject,输入项目目录名称(您应该会在第二个向导页面上看到现有文件)
- 在包管理器中,选择新项目:Android Tools/Convert to Android Project
- 如果 /gen 项目目录不存在,则创建它(没有它会失败)
- Android 工具/修复项目属性
- 主菜单/项目/构建项目
I've had good luck getting the example Apps to compile and run this way
我很幸运让示例应用程序以这种方式编译和运行
回答by Fred Grott
Resources should realign with what you imported it often takes the ADT eclipse plugin some time ro recognize sometimes depending upon size of the project
资源应该与您导入的内容重新对齐 通常需要 ADT eclipse 插件一段时间才能识别有时取决于项目的大小