[Android] 如何將SDK-sample項目複製到工作區?


Answers

嘗試確保您的進口聲明是正確的:

R無法解決 - Android錯誤

另外,你為什麼認為它正在看C:\sb\workspace\NotesList\bin\resources.ap_ ? 這不是你的項目存儲的地方,是嗎?

我可能會建議嘗試這樣做:

  1. 從工作區中刪除項目,也從磁盤中刪除項目(或者,如果要保留項目,請將其重命名,以免與您要導入的項目發生衝突)
  2. 在Eclipse中,選擇File > Import並選擇Existing Projects into Workspace選項
  3. 選擇Select root directory並瀏覽到Samples文件夾,直到找到NodePad根目錄
  4. 點擊Open或任何相關的“確定”選項
  5. 選中Copy projects into workspace
  6. 點擊Finish

這應該為您的修補程序導入一個很好的API演示的副本,使目錄樹中的原始源碼免於修改

Question

我的目標是複制NotePad示例項目,如果我修改源文件以便通過實驗學習,原始示例文件將不會受到影響。 這個目標背後的理性在@Neutrino的這篇文章中 1-2-3的子彈中有很好的解釋。

基於@ Neutrino的文章,我執行了以下步驟:

步驟1:將示例代碼複製到臨時位置(工作空間目錄之外):

 1. Close Eclipse.
 2. Copy the entire sample folder
    **NotePad** from C:\android-sdk-windows\samples\android-7
    to C:\Users\androideve\Documents\NotePad

第2步。從副本導入到工作區:

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

這導致了項目的創建,但它帶有21個錯誤,不知道是什麼導致它們(請記住,我是一個Android新手,我沒有寫的NotePad程序):

Description Resource    Path    Location    Type
Error generating final archive: java.io.FileNotFoundException: C:\sb\workspace\NotesList\bin\resources.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

我做錯了什麼,我需要什麼來使這個記事本樣本的副本生成和運行?




更簡單的解決方案

  1. “新”;
  2. “Android項目”
  3. 插入臨時項目名稱(不是你想要的最終);
  4. 選擇一個你已經下載了例子的“Build Target”
  5. 選擇“從現有示例創建項目”並選擇您想要的代碼示例;
  6. 點擊“完成”;
  7. 右鍵點擊項目並選擇“複製”;
  8. 右鍵單擊Project Explorer中的空白區域並選擇“粘貼”;
  9. 插入您為項目選擇的最終名稱;
  10. 如果您希望項目在工作區內的正常路徑中,請選擇“使用默認位置”。

就是這樣,項目和代碼現在已經被複製並在工作區中工作。