通常情况下,对于整个AOSP源码,我们一般只关心Framework和某些App,至于其他模块可能关心的比较少,因此没有必要全部作为源码导入。
修改移除不需要关心的模块
在AOSP源码目录,修改下面文件:
development/tools/idegen/excluded-paths
在最后面添加:
ps:我现在是去除了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
模块,因此可以根据自己的需求多去掉一些模块。
比如把下面这些加到上面那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代码,查看集成关系或者调用关系的时候,还是会跳转到.class文件中,而不是相应的Java类,比如PhoneWindow.java
继承了Window.java
,但是我们跳转的时候却跳到了Window.class
:
配置JDK和SDK解决跳转不到源码的问题
File - Project Structure - SDKs
-
删除多余的JDK和SDK:
-
添加JDK,并删除Classpath和Sourcepath下面的所有内容
-
配置Project的SDK
-
配置Modules
把framework添加到Dependencies中:
最后看一下,可以正确跳转了: