如何将 SDK 示例项目复制到工作区?

How to duplicate an SDK-sample project into workspace?(如何将 SDK 示例项目复制到工作区?)

本文介绍了如何将 SDK 示例项目复制到工作区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是复制 NotePad 示例项目,这样如果我修改源文件以便通过实验学习,原始示例文件将不会受到影响.这篇文章来自@Neutrino.

My goal is to duplicate the NotePad sample project such that if I tinker with the source files in order to learn through experimentation, the original sample files will not be affected. The rational behind this goal is explained very well in bullets 1-2-3 in this post by @Neutrino.

根据@Neutrino 的帖子,我执行了以下步骤:

Based on @Neutrino's post, I performed the following steps:

第 1 步:将示例代码复制到临时位置(工作区目录之外):

Step 1: Copy sample code to a temporary location (outside of the workspace directory):

 1. Close Eclipse.
 2. Copy the entire sample folder
    **NotePad** from C:android-sdk-windowssamplesandroid-7
    to C:UsersandroideveDocumentsNotePad

步骤 2. 从副本导入工作区:

Step 2. Import from copy to workspace:

   1. Start Eclipse
   2. File > New > Project > Android Project [Next]
      > Create project from existing **source**: C:UsersandroideveDocumentsNotePad
   3. Delete project from Package Explorer (without deleting its files from disk!)
   4. File > Import... 
      > General > Existing Projects into Workspace [Next]
        > Browse: C:UsersandroideveDocumentsNotePad
        > Check "Copy projects into workspace" [Finish]
   5. Delete entire folder C:UsersandroideveDocumentsNotePad from disk.

这会导致项目创建,但它带有 21 个错误,但没有任何线索说明它们的原因(请记住,我是 Android 新手,我没有编写记事本程序):

This results in the project creation but it comes with 21 errors without any clue as to what causes them (remember, I am an Android newbie and I didn't write the NotePad program):

Description Resource    Path    Location    Type
Error generating final archive: java.io.FileNotFoundException: C:sbworkspaceNotesListin
esources.ap_ does not exist   NotesList       Unknown Android Packaging Problem
error: Error: String types not allowed (at 'layout_height' with value 'match_parent').  note_editor.xml /NotesList/res/layout   line 17 Android AAPT Problem
error: Error: String types not allowed (at 'layout_width' with value 'match_parent').   note_editor.xml /NotesList/res/layout   line 17 Android AAPT Problem
error: Error: String types not allowed (at 'layout_width' with value 'match_parent').   noteslist_item.xml  /NotesList/res/layout   line 17 Android AAPT Problem
R cannot be resolved to a variable  NoteEditor.java /NotesList/src/com/example/android/notepad  line 148    Java Problem
R cannot be resolved to a variable  NoteEditor.java /NotesList/src/com/example/android/notepad  line 151    Java Problem
R cannot be resolved to a variable  NoteEditor.java /NotesList/src/com/example/android/notepad  line 175    Java Problem
R cannot be resolved to a variable  NoteEditor.java /NotesList/src/com/example/android/notepad  line 177    Java Problem
R cannot be resolved to a variable  NoteEditor.java /NotesList/src/com/example/android/notepad  line 194    Java Problem
R cannot be resolved to a variable  NoteEditor.java /NotesList/src/com/example/android/notepad  line 195    Java Problem
R cannot be resolved to a variable  NoteEditor.java /NotesList/src/com/example/android/notepad  line 265    Java Problem
R cannot be resolved to a variable  NoteEditor.java /NotesList/src/com/example/android/notepad  line 269    Java Problem
R cannot be resolved to a variable  NoteEditor.java /NotesList/src/com/example/android/notepad  line 276    Java Problem
R cannot be resolved to a variable  NotesList.java  /NotesList/src/com/example/android/notepad  line 83 Java Problem
R cannot be resolved to a variable  NotesList.java  /NotesList/src/com/example/android/notepad  line 94 Java Problem
R cannot be resolved to a variable  NotesList.java  /NotesList/src/com/example/android/notepad  line 177    Java Problem
R cannot be resolved to a variable  NotesLiveFolder.java    /NotesList/src/com/example/android/notepad  line 48 Java Problem
R cannot be resolved to a variable  NotesLiveFolder.java    /NotesList/src/com/example/android/notepad  line 51 Java Problem
R cannot be resolved to a variable  TitleEditor.java    /NotesList/src/com/example/android/notepad  line 71 Java Problem
R cannot be resolved to a variable  TitleEditor.java    /NotesList/src/com/example/android/notepad  line 80 Java Problem
R cannot be resolved to a variable  TitleEditor.java    /NotesList/src/com/example/android/notepad  line 83 Java Problem

我做错了什么?我需要做什么才能构建并运行此记事本示例的副本?

What did I do wrong and what do I need to make the copy of this NotePad sample build and run?

推荐答案

好的,我想我到了(注意原始步骤和以下步骤之间的细微差别):

OK, I think I am getting there (note the subtle differences between the original steps and the following ones):

第 1 步:将示例代码复制到临时位置(工作区目录之外):

Step 1: Copy sample code to a temporary location (outside of the workspace directory):

 1. Close Eclipse.
 2. Copy the entire sample folder
    **NotePad** from C:android-sdk-windowssamplesandroid-8
    to C:UsersandroideveDocumentsNotePad

步骤 2. 从副本导入工作区:

Step 2. Import from copy to workspace:

   1. Start Eclipse
   2. File > New > Project > Android Project [Next]
      > Create project from existing **source**: C:UsersandroideveDocumentsNotePad
      > Build Target: **Uncheck** Android 1.5. **Check** Android 2.2. [Finish]
   3. Delete project from Package Explorer (without deleting its files from disk!)
   4. File > Import... 
      > General > Existing Projects into Workspace [Next]
        > Browse: C:UsersandroideveDocumentsNotePad
        > Check "Copy projects into workspace" [Finish]
   5. Delete entire folder C:UsersandroideveDocumentsNotePad from disk.

现在,项目像以前一样创建,但我只有 1 个警告,而不是 21 个错误:

Now, the project is created as before but instead of 21 errors, I have only 1 warning:

Description Resource    Path    Location    Type
Attribute minSdkVersion (3) is lower than the project target API level (8)  AndroidManifest.xml /NotesList  line 1  Android ADT Problem

我在控制台上也有两条红色消息:

I also have two red messages on the Console:

[2011-02-10 12:45:50 - com.android.ide.eclipse.adt.internal.project.AndroidManifestHelper] Unable to read C:android-sdk-windowsAndroidManifest.xml: java.io.FileNotFoundException: C:android-sdk-windowsAndroidManifest.xml (The system cannot find the file specified)
[2011-02-10 12:45:50 - com.android.ide.eclipse.adt.internal.project.AndroidManifestHelper] Unable to read C:android-sdk-windowsAndroidManifest.xml: java.io.FileNotFoundException: C:android-sdk-windowsAndroidManifest.xml (The system cannot find the file specified)

确实:C:android-sdk-windows 下没有AndroidManifest.xml,但是NoteList 目录下有一个.为什么抱怨这个?为什么它在 C:android-sdk-windows 中查找?

It's true: There is no AndroidManifest.xml in C:android-sdk-windows, but there is one in the NoteList directory. Why is it complaining about this? Why is it looking in C:android-sdk-windows?

无论如何,在创建启动配置后,复制的逐字示例项目继续在模拟器上运行,没有任何问题(现在我终于可以继续学习它的编程方面了).

Anyway, after creating a launch configuration, the copied-verbatim sample project proceeded to run on the emulator without any problems (now I can finally proceed to learning the programming side of it).

总之,问题的根源在于我使用的是 Android 7 示例(而不是 Android 8)并且我继续使用构建目标 1.5(而不是 2.2).

In summary, the source of the problem was that I was using the Android 7 sample (instead of Android 8) and that I proceeded with build target 1.5 (instead of 2.2).

现在一切都很好.:)

这篇关于如何将 SDK 示例项目复制到工作区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何将 SDK 示例项目复制到工作区?

基础教程推荐