Mr.Alright---使用AndroidStudio断点调试安卓源码
我为甚要用AS来调试安卓源码呢?来自尼克杨的疑问
当然是因为爽啦!之前都是开发app,后面接触到了修改系统源码,App调试的时候可以断点调试,省去了一部分加log的麻烦,所以希望源码也可以这样,于是有了下面方案。
1.首先你要有系统源码,还要有linux的环境,至于源码的下载,linux的安装配置,大家先问下度娘
2.上面的环境配置好之后,执行
source build/envsetup.sh
初始化了一些函数,接着执行
make idegen -j32
执行完这个,会生成idegen.jar ,接着执行
sh ./development/tools/idegen/idegen.sh
执行完这个就会生成,AS需要的一些文件 android.ipr、android.iml
android.ipr:通常是保存工程编译器配置,入口,相关LIBRARIES等配置
android.iml:主要描述了modules的路径,依赖关系等
3.到这里,双击android.ipr 就可以用AS打开项目了,但是如果真的要直接打开,AS会加载的非常慢,毕竟安卓源码是非常庞大的,所以需要对android.iml处理,只添加我们需要的目录即可,下面简单介绍下android.iml的标签,之后会上传一份模板
关于<sourceFolder>标签:
通需要的文件添加到这里面,其他的删除,如package、framework
<sourceFolder url="file://$MODULE_DIR$/packages" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/frameworks" isTestSource="false" />
关于<excludeFolder>标签:
exclude顾名思义就是不包含的意思,不需要的添加到这里面,如vendor、external
<excludeFolder url="file://$MODULE_DIR$/vendor" />
<excludeFolder url="file://$MODULE_DIR$/external" />
关于<orderEntry>标签:
保留这两个就可以了
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="jdk" jdkName="Android API 24 Platform" jdkType="Android SDK" />
android.iml
<?xml version="1.0" encoding="UTF-8"?>
<module version="4" relativePaths="true" type="JAVA_MODULE">
<component name="FacetManager">
<facet type="android" name="Android">
<configuration />
</facet>
</component>
<component name="ModuleRootManager" />
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/packages/apps/Launcher3" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/packages/wallpapers/LivePicker" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/vendor/mediatek/proprietary/packages/apps/SystemUI" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/frameworks/base/services" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/frameworks/base/core/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/frameworks/base/core/res" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/frameworks/base/packages/SystemUI" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/frameworks/libs/systemui" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/gen" isTestSource="false" generated="true" />
<excludeFolder url="file://$MODULE_DIR$/.repo" />
<excludeFolder url="file://$MODULE_DIR$/FeatrueTableSpec" />
<excludeFolder url="file://$MODULE_DIR$/abi" />
<excludeFolder url="file://$MODULE_DIR$/apps" />
<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$/ccu_tool" />
<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$/development" />
<excludeFolder url="file://$MODULE_DIR$/device" />
<excludeFolder url="file://$MODULE_DIR$/docs" />
<excludeFolder url="file://$MODULE_DIR$/external" />
<excludeFolder url="file://$MODULE_DIR$/frameworks" />
<excludeFolder url="file://$MODULE_DIR$/hardware" />
<excludeFolder url="file://$MODULE_DIR$/kernel" />
<excludeFolder url="file://$MODULE_DIR$/kernel-3.18" />
<excludeFolder url="file://$MODULE_DIR$/kernel-4.4" />
<excludeFolder url="file://$MODULE_DIR$/kernel-4.19" />
<excludeFolder url="file://$MODULE_DIR$/kernel-4.19-lc" />
<excludeFolder url="file://$MODULE_DIR$/kernel-4.14" />
<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$/packages" />
<excludeFolder url="file://$MODULE_DIR$/pdk" />
<excludeFolder url="file://$MODULE_DIR$/phoenix" />
<excludeFolder url="file://$MODULE_DIR$/platform_testing" />
<excludeFolder url="file://$MODULE_DIR$/prebuilt" />
<excludeFolder url="file://$MODULE_DIR$/prebuilts" />
<excludeFolder url="file://$MODULE_DIR$/res" />
<excludeFolder url="file://$MODULE_DIR$/sdk" />
<excludeFolder url="file://$MODULE_DIR$/system" />
<excludeFolder url="file://$MODULE_DIR$/test" />
<excludeFolder url="file://$MODULE_DIR$/toolchain" />
<excludeFolder url="file://$MODULE_DIR$/tools" />
<excludeFolder url="file://$MODULE_DIR$/trusty" />
<excludeFolder url="file://$MODULE_DIR$/vendor" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="jdk" jdkName="Android API 30 Platform" jdkType="Android SDK" />
</component>
</module>
这样AS的只会去索引你添加的sourceFolder ,其他的都不添加,就会快了很多
4.该文件在AS安装目录下面,bin文件夹下
64位的修改studio64.exe.vmoptions、32位的修改studio.exe.vmoptions
-Xms1024m 修改这个,表示的是分配给studio的内存大小
-Xmx1280m
5.打开AS,选择open exist...,选择刚生成的android.ipr
这时候会快很多,因为好多索引我们都去除了,如果需要,再添加回来就是了
等待漫长的indexing...
6.添加一个安卓app,选择要调试的进程即可
8.最终效果如下图,比如我调试的是系统的launcher3
本文地址:https://blog.csdn.net/Keep_Holding_On/article/details/111758987