第一步:
下载源码,可以有很多种方法下载,这里主要用repo下载。
- 安装repo
ubuntu安装: sudo apt-get update sudo apt-get install repo mac安装:注意mac需要建一个大小写敏感的磁盘存储源码 brew install repo
- 配置git:
mkdir WORKING_DIRECTORY cd WORKING_DIRECTORY git config --global user.name Your Name git config --global user.email you@example.com
- 下载源码
repo init -u https://android.googlesource.com/platform/manifest #国内源 repo init -u git://mirrors.ustc.edu.cn/aosp/platform/manifest #如果需要下载某个分支 repo init -u https://android.googlesource.com/platform/manifest -b master repo sync -c -j8
第二步:生成项目文件,参考
生成iml和ipr文件
source build/envsetup.sh
lunch aosp_x86-eng # 或者直接lunch 然后选择对应的架构
#此时不需要make命令编译整个项目
make idegen #等同于 mmm development/tools/idegen/
development/tools/idegen/idegen.sh
#上述命令会在根目录产生两个文件
android.iml/android.ipr 用android stduio打开android.ipr就可以了
第三步:导入android studio
点击File -> Open,选中前面生成的android.ipr文件即可,该过程比较耗时。
其他as配置:
1. 导入整个项目,索引会很慢,可以添加排除文件夹,在android.iml中搜索excludeFolder,在下面加入这些配置。
<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$/kernel" />
<excludeFolder url="file://$MODULE_DIR$/out" />
<excludeFolder url="file://$MODULE_DIR$/pdk" />
<excludeFolder url="file://$MODULE_DIR$/platform_testing" />
<excludeFolder url="file://$MODULE_DIR$/prebuilts" />
<excludeFolder url="file://$MODULE_DIR$/system" />
<excludeFolder url="file://$MODULE_DIR$/test" />
<excludeFolder url="file://$MODULE_DIR$/toolchain" />
<excludeFolder url="file://$MODULE_DIR$/tools" />
2. 如果点击类跳转到了jar包反编译的代码,而不是导入的源码,配置:
File->Project Structure->Project Settings->Moudules->Dependencies
, 将 Module source移到最顶端
3. 如果想打开超过10个文件,配置:File->Settings->Editor->General->Editor Tabs,选中Mark modified防止误修改,和Tab limit、多行标签等。
4. 如果想要断点调试:
File->Project Structure->Project Settings->Project->Project SDK
, 选择Android API .. Platform
- Run->Edit Configurations->Add New Configuration->Android App