导入源码至Android Studio

导入源码至Android Studio

参考:

使用如下的步骤:

1.. build/envsetup.sh (source可以用 .代替,即". build/envsetup.sh")
2.lunch,并选择要编译的项目
3.make idegen -j4 (这里的 -j4表示用 4线程来编译,可以不加)
001

4.development/tools/idegen/idegen.sh
执行脚本,生成.iml .ipr文件
报错find: ‘out/target/product/generic_x86_64/root/d’: Permission denied不影响

002

003
有了ipriml,删减一部分android.iml的内容,主要原因源码太多,要排除部分没用项目,还有就是依赖部分只留下自己moudle就可以
再参考如下的文章:

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文件即可
import project
由于本人的误操作,导致导入时提示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 + 向上箭头),将其移动到第一行

Module source

2.参考:

排除不常用的代码

排除不常用的代码

说明

1.make idegen

IDEGen automatically generates Android IDE configurations for IntelliJ IDEAand Eclipse. Your IDE should be able to compile everything in a reasonable amount of time with no errors.
IDEGen 自动为 IntelliJ IDEA 和 Eclipse 生成 Android IDE 配置。 您的 IDE 应该能够在合理的时间内编译所有内容而不会出现错误。

android.iws 包含工作区的个人设置,比如打开过的文件,版本控制工具的配置,本地修改历史,运行和debug的配置等。
android.ipr 一般保存了工程相关的设置,比如modulesmodules libraries的路径,编译器配置,入口点等。
android.iml 用来描述modules。它包括modules路径、 依赖关系,顺序设置等。一个项目可以包含多个 *.iml 文件。

其它

参考:

猜你喜欢

转载自blog.csdn.net/u014084081/article/details/130789324