2014/12/25

Android Studio 筆記

最近Google releases正式版的Android Studio,並宣稱此工具將成為official IDE for Android。那Android未來還會繼續維護與發展ADT嗎?從Android用official IDE這字眼,並在官網上鼓勵大家轉到Android Studio的態度,個人覺得以Eclipse為基礎的ADT可能會走向尾聲了(參考這一篇)。

因為Android Studio的專案結構與觀念與ADT有蠻大的差別,所以一定要來瞭解一下

讀了一些網頁,把一些重要的記錄下來

Android Studio Overview
官方的資料一定是不可或缺的
我覺得這裡的workflow章節很重要,可讓我們可以瞭解一下這工具的使用概念
這裡稍作紀錄一下,Android Studio開啟是以專案(project)為單位(Eclipse則是workspace)
每個project可以包含一至多個modules(至少要有一個application module)。Module是個容器,用來存放與組織所需要的source codes與resources。Module又分為四種:
  • Application Module:可用來產出.apk檔來安裝至Android設備
  • Library Module:如其名稱,用來存放可被其他projects或modules共用的source codes與resources,以達到reuse之目的
  • Test Module:用來包含可對application projects進行測試的codes。其中講到"are built into test applications that run on a device",這等有時間可以來多瞭解一下
  • App Engine Module:可以與Google App Engine(GAE)結合,來整合device與雲端成為一體。這一塊對應該是做IoT的朋友可以多留意的

Android Studio vs. Eclipse: What You Need To Know
如果已經用慣Eclipse的朋友,可以先看看這篇,瞭解這兩者的異同
另外這一篇也可以參考一下

Android Tutorial for Beginners: Part 1
Android Tutorial for Beginners: Part 2
Android Tutorial for Beginners: Part 3
就如標題,這是針對正式版(v.1.0)所修改過的入門文,不是用之前beta版,有正確的畫面截圖,在學習時應該會減少很多混淆與誤解

Gardle
Android Studio並未採用Ant做為其build tool,而是選用了Gardle。因此若想把Android Studio玩好,把Gardle讀通也是必要的。
也可以參考Android官網上的Gradle Plugin User Guide


2014/12/12

GCMRegistrar置換為GoogleCloudMessaging的問題

GCMRegistrar已經宣告為deprecated,官方建議大家應改用GoogleCloudMessaging,並提供範例供大家參考


不過依照這份文件來實作時,當執行到 GooglePlayServicesUtil.isGooglePlayServicesAvailable (context); 時,會遇到  "The Google Play services resources were not found. Check your project configuration to ensure that the resources are included." 的錯誤訊息。

主要的問題在文件中沒有提到要在AndroidManifest.xml的application宣告中,加上
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"></meta-data>
然後在 /res/values/versions.xml 裡,加上
<integer name="google_play_services_version">6111000</integer>
至於這個version number應該填入什麼值?可以從 <sdk>/extras/google/google_play_services/libproject/google-play-services_lib/res/values/version.xml 中獲得。

另外一種說法,不應該把version number寫死,不過這個方法我還沒有試成功 (Eclipse)

參考文件