編輯:關於Android編程
上路了,准備開始重操那兩年的舊業,後悔之前在上家公司做Amlogic和Realtak方案盒子時沒有養成寫博客的習慣,這算是開篇之作吧,順帶也算是給一個網友的答疑吧。不多說,該篇只是工具講解而已。
關於Android Studio對於應用層App開發的技巧和配置前面我寫過文章分析的,這裡不再解釋說明,具體查看我的這一片博文《Android Studio入門到精通 》。這裡我們主要說明的是用它來看源碼的相關配置(該實例依據官方源碼android-5.1.1_r14進行配置說明)。
以前在上家公司查看修改源碼時還是使用的Eclipse導入部分代碼的方式,而現在在android源碼中發現有一個development/tools/idegen目錄,查了一下發現是生成IDE的project文件(主要是intellij的project文件,其實也就是Android Studio的),所以說福利工具就這麼來了,欲知詳情,請看下文。
首先你得安裝配置了Android Studio,具體不明白的參考《Android Studio入門到精通 》。
接著你得下載好了源碼Code,至於如何下載這裡不再說明,比較簡單,上官網查看就行了。
其次你需要保證源碼已經被編譯生成了out相關目錄文件。
好了,如上就是一些基本准備工作,針對定制源碼或者原生源碼來說,這些准備步驟都是必須的,沒必要再強調了。
在開始編譯idegen模塊前,你一定知道需要先全局編譯出out目錄及相關文件吧,這個不再過多說了,我們通過如下命令編譯idegen模塊:
mmm development/tools/idegen/
這行命令的意思是編譯idegen這個模塊項目,然後生成idegen.jar文件(不信你自己去查看這個模塊的Android.mk的目標吧,不多解釋)。運行完以後如果看到如下信息則說明編譯OK:
......
#### make completed successfully (7 seconds) ####
接著執行如下腳本:
development/tools/idegen/idegen.sh
這行命令的意思是在根目錄生成對應的android.ipr、android.iml IEDA工程配置文件。等待片刻得到類似如下信息說明OK:
Read excludes: 21ms
Traversed tree: 194799ms
通過如上操作我們就完成了基本的源碼配置工作。
大家都知道使用Eclipse倒入源碼很慢,Android Studio導入源碼時也慢,所以建議修改android.iml文件(將自己不用的代碼去掉),然後再導入Studio。
就像下面摘取的android.iml文件1887行開始的這些一樣:
我們可以仿照上面這段代碼的
寫法一樣過濾掉不需要的內容,這樣在導入時就會快很多。
也可以通過Android Studio的Project Stucture 打開左側Modules,然後將右側Sources中一些目錄Excluded掉。
有了如上的這些操作以後,我們打開Android Studio,然後選擇打開一個現有的Android Studio項目,然後選擇打開源碼根目錄下的android.ipr文件,然後出現如圖一樣的索引即可等待導入就行:tu
vcS/x7DOqta5ztLDx77Nv8nS1Le9seO1xMq508NBbmRyb2lkIFN0dWRpb7Lpv7TUtMLrwLKho8jnz8LNvMv5yr6jujwvcD4NCjxwPjxpbWcgYWx0PQ=="這裡寫圖片描述" src="/uploadfile/Collfiles/20151009/20151009084739140.png" title="\" />
吊不屌!!!
上圖我們看見了,可以通過Android Studio搜索整套源碼的代碼了。但是這時候如果你打開一個Service.java類,然後把鼠標放在其中任意方法的Intent參數上按住CTRL+鼠標左鍵跳轉到Intent類你會發現跳轉過去的是一個Intent.class文件,為啥呢?因為他跳轉的是你的默認SDK中的jar內部的class文件。既然要修改查看整套源碼,這麼跳轉得多蛋疼啊,所以我們需要配置讓其能跳轉到Intent.java文件,具體做法如下:
首先刪掉依賴中的所有依賴,只保留下圖中沒被選中的那兩個(當然你可以選擇保留一些你用到的其他jar),如下:
接著點擊加號的JARs or directories將你源碼的frameworks及external和你用到的其他跳轉目錄添加到依賴中,然後apply即可。
這時候我們在像上面一樣打開Service.java跳轉Intent,你會發現像下圖一樣直接跳轉到你源碼路徑下的Intent.java文件了,如下:
到此對於平時只是查看源碼的人來說已經夠用了。
俗話說工欲善其事必先利其器,你會發現使用Android Studio比Eclipse和Source Insight都好很多(當然了,SubText還是很強大的),無論是代碼提示還是跳轉、還是Python Shell等插件支持等都很強大,慢慢體驗吧。
順帶說一句,Google的野心真的很大,看來Android Studio即將要被他們打造為全能IDE了。
附上原版的英文README文檔,英語高手直接看這裡就行:
IDEGen automatically generates Android IDE configurations for IntelliJ IDEA
and Eclipse. Your IDE should be able to compile everything in a reasonable
amount of time with no errors.
If you’re using IntelliJ…
If this is your first time using IDEGen...
IDEA needs a lot of memory. Add -Xms748m -Xmx748m to your VM options
in IDEA_HOME/bin/idea.vmoptions on Linux or
IntelliJ IDEA.app/Contents/Info.plist on OS X.
Create a JDK configuration named 1.6 (No Libraries) by adding a new
JDK like you normally would and then removing all of the jar entries
under the Classpath tab. This will ensure that you only get access to
Android's core libraries and not those from your desktop VM.
From the project's root directory...
Repeat these steps after each sync...
1) make (to produce generated .java source)
2) development/tools/idegen/idegen.sh
3) Open android.ipr in IntelliJ. If you already have the project open,
hit the sync button in IntelliJ, and it will automatically detect the
updated configuration.
If you get unexpected compilation errors from IntelliJ, try running
Build -> Rebuild Project. Sometimes IntelliJ gets confused after the
project changes significantly.
If you’re using Eclipse…
If this is your first time using IDEGen...
Edit eclipse.ini (Eclipse.app/Contents/MacOS/eclipse.ini on OS X) and
add -Xms748m -Xmx748m to your VM options.
Configure a JRE named 1.5 (No Libraries) under Preferences -> Java ->
Installed JREs. Remove all of the jar entries underneath JRE system
libraries. Eclipse will not let you save your configuration unless at
least one jar is present, so include a random jar that won't get in the
way.
From the project's root directory...
Repeat these steps after each sync...
1) make (to produce generated .java source)
2) development/tools/idegen/idegen.sh
3) Import the project root directory into your Eclipse workspace. If you
already have the project open, simply refresh it (F5).
Excluding source roots and jars
IDEGen keeps an exclusion list in the excluded-paths file. This file
has one regular expression per line that matches paths (relative to the
project root) that should be excluded from the IDE configuration. We
use Java's regular expression parser (see java.util.regex.Parser).
You can create your own additional exclusion list by creating an
excluded-paths file in the project's root directory. For example, you
might exclude all apps except the Browser in your IDE configuration with
this regular expression: ^packages/apps/(?!Browser).
Controlling source root ordering (Eclipse)
You may want some source roots to come before others in Eclipse. Simply
create a file named path-precedence in your project's root directory.
Each line in the file is a regular expression that matches a source root
path (relative to the project's root directory). If a given source root's
path matches a regular expression that comes earlier in the file, that
source root will come earlier in the generated configuration. If a source
root doesn't match any of the expressions in the file, it will come last,
so you effectively have an implicit .* rule at the end of the file.
For example, if you want your applications's source root to come first,
you might add an expression like ^packages/apps/MyApp/src$ to the top
of the path-precedence file. To make source roots under ./out come last,
add ^(?!out/) (which matches all paths that don't start with out/).
本次分析的是github上一個用於下拉刷新上拉加載的控件XListView,這個開源的ListView相信大家在開發的過程中會經常用到。https://github.co
簽名工具的使用Android源碼編譯出來的signapk.jar既可給apk簽名,也可給rom簽名的。使用格式:java –jar signapk.jar [-w] pu
Activities提供了一種方便管理的創建、保存、回復的對話框機制,例如 onCreateDialog(int), onPrepareDialog(int, Dialo
除非迫不得已,要不然不要在你的APP裡面使用數據庫,記不得是哪個書的話了!現在Android平台下的ORM框架very多,比如GreenDao,曾經寫過一篇關於Green