標籤:android style blog http io color ar os java
版本:1.0日期:2014.8.26 2014.8.27 2014.11.10著作權:© 2014 kince 轉載註明出處 好久沒有寫部落格,也是因為工作比較忙的關係。當然這不是理由,主要是很多bug要改,而自己的效率又不是很高,所以把很多時間都浪費在修複bug上面了。閑話不多說,切入正題。 Launcher3是最新的google官方Launcher,相比Launcher2,它具有更加小巧、流暢、清新等特點,所以選擇它作為研究的對象。第一步當然是去下載其源碼,git網址是:https://android.googlesource.com/platform/packages/apps/Launcher3/。如果沒有git工具,可以點擊master。
剛好最近lollipop的Launcher源碼也更新了。和之前的Launcher3會有一些區別,不過不大,倒入過程大同小異。
git下載:
壓縮包下載:
下載完後解壓,目錄如下:
接著匯入eclipse,因為Launcher3的某些新特性,需要將build target設定為API level 19(不是必須,為了方便研究起見,Launcher3的源碼最低可以相容大API16)。然後匯入項目所依賴的類庫,這個地方分為三種情況,一是匯入v4包,手動添加一個libs目錄,將v4包加進去;二是需要protocol buffers,到https://android.googlesource.com/platform/external/protobuf.git下載,最好打成jar包,然後放在libs目錄下。三是添加BackupProtos.java這個類。可以從上一步中擷取。英文好的朋友可以看一下下面的步驟:Do it yourself
- Use Git to pull down the latest Launcher 3 source:
git clone https://android.googlesource.com/platform/packages/apps/Launcher3
- Import existing code into Eclipse (Android Project from Existing Code)
- Change the project build target to API level 19
- Add Android support libraries
- Build protocol buffers JAR from AOSP source. You will actually need to build the protoc binary as well. You need to know how to use ‘make’ have gcc available for the protoc binary, and Maven for the JAR: https://android.googlesource.com/pla…l/protobuf.git
- Use protoc binary built from step above to generate the BackupProtos.java file:
protoc –javanano_out=src/ -I protos protos/backup.proto
- Rename the Android package (Android Tools->Rename Application Package) to one of your choice
- Add min SDK in a new ‘uses-sdk’ element in AndroidManifest.xml (works down to API level 17 without too many complaints in Lint, obviously stick to 19 to play it safe).
- Clean and run. BIND APP WIDGETS error can be ignored
Fabio Lo Brutto:
https://plus.google.com/+FabioLoBrutto/posts/KJeyKMBHVT7
導完後的目錄結構如下: 如果想做一個自己的Launcher,那麼需要把包名改一下,研究的話就沒有必要了。最後運行,如下:
關於Launcher最複雜的東西不在於如何顯示應用程式、Widget、檔案夾等功能,而是自訂View方面,因為基本上Launcher的View都是自訂的,而且代碼都很多,理解起來不是那麼簡單。所以說,如果把Launcher裡面的自訂的View掌握了,那麼對Launcher也就基本掌握了。因此,學習重點應該集中在自訂View上。 今後會持續更新關於Launcher3開發方面的文章,在做Launcher開發的朋友可以一起交流。
Android launcher3 開發環境搭建