导入源码至Android Studio
参考:
- Android源码环境搭建(aosp Ubuntu 16.04)
使用如下的步骤:
1.. build/envsetup.sh
(source
可以用 .
代替,即". build/envsetup.sh"
)
2.lunch
,并选择要编译的项目
3.make idegen -j4
(这里的 -j4
表示用 4线程来编译,可以不加)
4.development/tools/idegen/idegen.sh
执行脚本,生成.iml
.ipr
文件
报错find: ‘out/target/product/generic_x86_64/root/d’: Permission denied
不影响
有了ipr
和iml
,删减一部分android.iml
的内容,主要原因源码太多,要排除部分没用项目,还有就是依赖部分只留下自己moudle就可以
再参考如下的文章:
- aosp11/12/13 framework源码开发IDE工具之idegen/aidegen/AIDEGen详细使用
把android.iml
中的excludeFolder
标签都删除用以下标签
<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$/compatibility" />
<excludeFolder url="file://$MODULE_DIR$/cts" />
<excludeFolder url="file://$MODULE_DIR$/dalvik" />
<excludeFolder url="file://$MODULE_DIR$/developers" />
<excludeFolder url="file://$MODULE_DIR$/developers/samples" />
<excludeFolder url="file://$MODULE_DIR$/development" />
<excludeFolder url="file://$MODULE_DIR$/device" />
<excludeFolder url="file://$MODULE_DIR$/device/google" />
<excludeFolder url="file://$MODULE_DIR$/device/sample" />
<excludeFolder url="file://$MODULE_DIR$/docs" />
<excludeFolder url="file://$MODULE_DIR$/external" />
<excludeFolder url="file://$MODULE_DIR$/flashing-files" />
<excludeFolder url="file://$MODULE_DIR$/frameworks/base/docs" />
<excludeFolder url="file://$MODULE_DIR$/hardware" />
<excludeFolder url="file://$MODULE_DIR$/kernel" />
<excludeFolder url="file://$MODULE_DIR$/libcore" />
<excludeFolder url="file://$MODULE_DIR$/libnativehelper" />
<excludeFolder url="file://$MODULE_DIR$/out" />
<excludeFolder url="file://$MODULE_DIR$/out/soong/.intermediates" />
<excludeFolder url="file://$MODULE_DIR$/pdk" />
<excludeFolder url="file://$MODULE_DIR$/platform_testing" />
<excludeFolder url="file://$MODULE_DIR$/prebuilt" />
<excludeFolder url="file://$MODULE_DIR$/prebuilts" />
<excludeFolder url="file://$MODULE_DIR$/sdk" />
<excludeFolder url="file://$MODULE_DIR$/shortcut-fe" />
<excludeFolder url="file://$MODULE_DIR$/system" />
<excludeFolder url="file://$MODULE_DIR$/test" />
<excludeFolder url="file://$MODULE_DIR$/toolchain" />
<excludeFolder url="file://$MODULE_DIR$/tools" />
之后,选择Android Studio的import project
,选择android.ipr
文件即可
由于本人的误操作,导致导入时提示Cannot import project The project file specified already exists
1.移除.idea
文件夾,该文件夾时隐藏的,使用ls -a
移除
2.或者open existing android project, 而不是import project
跳转时发现还是跳转android.jar
的源码,不是我们本地的源码,可参考如下的链接解决:
1.AndroidStudio - File - Project Structure - Project Settings - Modules - Dependencies - Module Source
,将Module Source
移到最顶 第一行。操作为:选中 Module source
,一直按 ALT + ↑
(ALT + 向上箭头),将其移动到第一行
2.参考:
- Android Studio 源码阅读时代码跳转
排除不常用的代码
其它
参考:
- Android Studio导入系统源码