|
| 1 | +#Android Tutorial 從Eclipse ADT轉移到Android Studio |
| 2 | +CodeDate的Android Studio系列專欄,在連載的中途發表Android 5 Lollipop,還有全新的開發工具Android Studio。因為版本與開發工具的變化非常大,因此決定把系列專欄昇級為Android 5與Android Studio,專欄與範例程式專案在2015/03/02同步更新。 |
| 3 | + |
| 4 | +因為之前的範例程式專案採用Eclipse ADT,如果你已經依照之前的專欄撰寫應用程式,可以考慮將它轉移到Android Studio,再繼續依照後續的專欄學習全新的Android Studio。 |
| 5 | + |
| 6 | +依照下列的步驟執行轉移的工作: |
| 7 | + |
| 8 | +1. 依照<http://www.codedata.com.tw/mobile/android-tutorial-the-1st-class-2-android-sdk/>的說明,安裝好Android Studio開發環境。 |
| 9 | +2. 啟動Android Studio,選擇「Import project(Eclipse ADT, Gradle, etc.)」: |
| 10 | + |
| 11 | +  |
| 12 | + |
| 13 | +3. 選擇使用Eclipse ADT開發的Android應用程式專案: |
| 14 | + |
| 15 | +  |
| 16 | + |
| 17 | +4. 選擇轉移後的專案儲存位置,選擇「Next」: |
| 18 | + |
| 19 | +  |
| 20 | + |
| 21 | +5. 選擇「Finish」: |
| 22 | + |
| 23 | +  |
| 24 | + |
| 25 | +6. 等候Android Studio完成轉換工作並開啟專案後,你會發現專案有一些錯誤。開啟「MyAndroidTutorial -> app -> build.gradle」,參考下面的內容,修改並儲存這個檔案(注意applicationId的設定,必須參考你實際的專案修正): |
| 26 | + |
| 27 | + apply plugin: 'com.android.application' |
| 28 | + |
| 29 | + android { |
| 30 | + compileSdkVersion 21 |
| 31 | + buildToolsVersion "21.1.2" |
| 32 | + |
| 33 | + defaultConfig { |
| 34 | + applicationId "net.macdidi.myandroidtutorial" |
| 35 | + minSdkVersion 15 |
| 36 | + targetSdkVersion 21 |
| 37 | + versionCode 1 |
| 38 | + versionName "1.0" |
| 39 | + } |
| 40 | + buildTypes { |
| 41 | + release { |
| 42 | + minifyEnabled false |
| 43 | + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' |
| 44 | + } |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + dependencies { |
| 49 | + compile fileTree(dir: 'libs', include: ['*.jar']) |
| 50 | + compile 'com.android.support:appcompat-v7:21.0.3' |
| 51 | + } |
| 52 | + |
| 53 | +7. 開啟「MyAndroidTutorial -> app -> src -> main -> AndroidManifest.xml」,參考下面的內容,修改並儲存這個檔案(移除SDK與版本設定): |
| 54 | + |
| 55 | + <?xml version="1.0" encoding="utf-8"?> |
| 56 | + <manifest xmlns:android="http://schemas.android.com/apk/res/android" |
| 57 | + package="net.macdidi.myandroidtutorial"> |
| 58 | + |
| 59 | + <!-- 省略 --> |
| 60 | + |
| 61 | + <application |
| 62 | + android:allowBackup="true" |
| 63 | + android:icon="@drawable/ic_launcher" |
| 64 | + android:label="@string/app_name" |
| 65 | + android:theme="@style/AppTheme" > |
| 66 | + |
| 67 | + <!-- 省略 --> |
| 68 | + |
| 69 | + </application> |
| 70 | + |
| 71 | + </manifest> |
| 72 | + |
| 73 | +8. 選擇「Try Again」: |
| 74 | + |
| 75 | +  |
| 76 | + |
| 77 | +9. 選擇「Yes」讓Android Studio關閉與重新啟動專案: |
| 78 | + |
| 79 | +  |
| 80 | + |
| 81 | +10. 接下來就可以依照專欄的內容,使用Android Studio開發工具繼續學習。 |
0 commit comments