通常情況下缤骨,對于整個AOSP源碼爱咬,我們一般只關心Framework和某些App,至于其他模塊可能關心的比較少绊起,因此沒有必要全部作為源碼導入精拟。
修改移除不需要關心的模塊
在AOSP源碼目錄,修改下面文件:
development/tools/idegen/excluded-paths
在最后面添加:
ps:我現(xiàn)在是去除了framework和libcore之外的所有模塊虱歪,如果想留下某些模塊蜂绎,可以自己適當修改。
# remove projects except framework
#^out
^disregard
^kernel
^bootstrap.bash -> build/soong/bootstrap.bash
^Android.bp -> build/soong/root.bp
^build
^vendor
^tools
^toolchain
^test
^system
^shortcut-fe
^sdk
^prebuilts
^platform_testing
^pdk
^packages
^oem-release
^libnativehelper
#^libcore
^libcore/.*/test$
^libcore/.*/test-rules$
^libcore/test-rules$
^libcore/metrictests$
^hardware
#^frameworks
^frameworks/support/samples$
^frameworks/.*/.*tests$
^frameworks/.*/test$
^frameworks/.*/test-base$
^frameworks/.*/core-testing$
^frameworks/.*/testing$
^frameworks/.*/testutils$
^frameworks/.*/loadtest$
^frameworks/.*/testtensorflow$
^frameworks/.*/testrunner-src$
^frameworks/.*/androidTest$
^flashing-files
^external
^device
^build.sh
^development
^developers
^dalvik
^cts
^compatibility
^Makefile
^bootable
^bionic
^art
編譯 idegen 模塊
在AOSP源碼根目錄:
source build/envsetup.sh
including device/generic/car/vendorsetup.sh
including device/generic/mini-emulator-arm64/vendorsetup.sh
including device/generic/mini-emulator-armv7-a-neon/vendorsetup.sh
including device/generic/mini-emulator-x86_64/vendorsetup.sh
including device/generic/mini-emulator-x86/vendorsetup.sh
including device/generic/uml/vendorsetup.sh
including device/google/muskie/vendorsetup.sh
Created 12 symlinks out of 12 mapped links..
including sdk/bash_completion/adb.bash
- 編譯生成
idegen.jar
:
make idegen
或者:
mmm development/tools/idegen/
// 編譯完成
[100% 3/3] out/soong/.bootstrap/bin/soong_build out/soong/build.ninja
[ 50% 1/2] glob art
[100% 4/4] Install: out/host/linux-x86/framework/idegen.jar
#### build completed successfully (01:26 (mm:ss)) ####
- 生成 android.ipr 和 android.iml
$ development/tools/idegen/idegen.sh
Read excludes: 10ms
Traversed tree: 14696ms
運行完畢上面的命令之后笋鄙,就在根目錄生成了2個文件:
android.ipr 和 android.iml
開始導入源碼
- 排除不必要的模塊师枣,提高加載速度
打開android.iml
, 找到excludeFolder
屬性,我們可以看到默認有14個模塊是被排除了局装,不會被導入的坛吁。
<excludeFolder url="file://$MODULE_DIR$/./external/emma"/>
<excludeFolder url="file://$MODULE_DIR$/./external/jdiff"/>
<excludeFolder url="file://$MODULE_DIR$/out/eclipse"/>
<excludeFolder url="file://$MODULE_DIR$/.repo"/>
<excludeFolder url="file://$MODULE_DIR$/external/bluetooth"/>
<excludeFolder url="file://$MODULE_DIR$/external/chromium"/>
<excludeFolder url="file://$MODULE_DIR$/external/icu4c"/>
<excludeFolder url="file://$MODULE_DIR$/external/webkit"/>
<excludeFolder url="file://$MODULE_DIR$/frameworks/base/docs"/>
<excludeFolder url="file://$MODULE_DIR$/out/host"/>
<excludeFolder url="file://$MODULE_DIR$/out/target/common/docs"/>
<excludeFolder url="file://$MODULE_DIR$/out/target/common/obj/JAVA_LIBRARIES/android_stubs_current_intermediates"/>
<excludeFolder url="file://$MODULE_DIR$/out/target/product"/>
<excludeFolder url="file://$MODULE_DIR$/prebuilt"/>
但實際上劳殖,整個AOSP代碼中铐尚,一般情況下,我們只是關心framework
模塊哆姻,因此可以根據(jù)自己的需求多去掉一些模塊宣增。
比如把下面這些加到上面那14行之下:
<excludeFolder url="file://$MODULE_DIR$/abi"/>
<excludeFolder url="file://$MODULE_DIR$/art"/>
<excludeFolder url="file://$MODULE_DIR$/bionic"/>
<excludeFolder url="file://$MODULE_DIR$/bootable"/>
<excludeFolder url="file://$MODULE_DIR$/build"/>
<excludeFolder url="file://$MODULE_DIR$/cts"/>
<excludeFolder url="file://$MODULE_DIR$/dalvik"/>
<excludeFolder url="file://$MODULE_DIR$/developers"/>
<excludeFolder url="file://$MODULE_DIR$/development"/>
<excludeFolder url="file://$MODULE_DIR$/device"/>
<excludeFolder url="file://$MODULE_DIR$/docs"/>
<excludeFolder url="file://$MODULE_DIR$/external"/>
<excludeFolder url="file://$MODULE_DIR$/hardware"/>
<excludeFolder url="file://$MODULE_DIR$/libcore"/>
<excludeFolder url="file://$MODULE_DIR$/libnativehelper"/>
<excludeFolder url="file://$MODULE_DIR$/ndk"/>
<excludeFolder url="file://$MODULE_DIR$/out"/>
<excludeFolder url="file://$MODULE_DIR$/pdk"/>
<excludeFolder url="file://$MODULE_DIR$/prebuilts"/>
<excludeFolder url="file://$MODULE_DIR$/sdk"/>
<excludeFolder url="file://$MODULE_DIR$/system"/>
<excludeFolder url="file://$MODULE_DIR$/tools"/>
<excludeFolder url="file://$MODULE_DIR$/kernel"/>
這樣修改之后,打開速度會快很多矛缨。
- 使用Android Studio直接打開
android.ipr
文件爹脾。
File - Open...,找到adnroid.ipr即可
導入完成之后箕昭,就能看到整個AOSP源碼了:
橘紅色的
就上咱們在上一步exclude的模塊灵妨。
到目前為止,我們就可以正常的搜索代碼落竹,然后打開看了:
但是有個問題泌霍,打開的Java代碼,查看集成關系或者調(diào)用關系的時候述召,還是會跳轉(zhuǎn)到.class文件中朱转,而不是相應的Java類蟹地,比如PhoneWindow.java
繼承了Window.java
,但是我們跳轉(zhuǎn)的時候卻跳到了Window.class
:
配置JDK和SDK解決跳轉(zhuǎn)不到源碼的問題
File - Project Structure - SDKs
-
刪除多余的JDK和SDK:
-
添加JDK,并刪除Classpath和Sourcepath下面的所有內(nèi)容
-
配置Project的SDK
-
配置Modules
把framework添加到Dependencies中:
最后看一下藤为,可以正確跳轉(zhuǎn)了: