Android      aosp07-将LineageOS源码导入AndroidStudio   
文章目录  [隐藏]

在 %lineage%/development/tools/idegen/ 下有 idegen.ipr 和 idegen.iml 文件,并且有README文件说明其用法。
本文参考 https://wiki.lineageos.org/how-to/import-to-android-studio

1.准备项目文件

打开 shell 并导航到 Android 源码的根文件夹,例如~/android/lineage. 如果尚未加载环境函数和变量,请键入:


如果您在多个分支上开发或计划这样做(否则跳到下一步),请执行以下操作(lineage用您想要的命名方案替换每个出现的):



2.安装并配置 Android Studio

转到下载页面(https://developer.android.google.cn/studio)并下载适用于您的操作系统的软件包。
将下载的文件解压到您选择的目的地,然后按照Install-Linux-tar.txt解压缩文件夹中的文件中描述的说明进行操作。


配置内存
打开 Android Studio 并点击Configure。
然后单击“编辑自定义虚拟机选项 - Edit Custom VM Options”并包括以下内容:

-Xms748m
-Xmx748m

这会将初始分配的Xms(Xms参数)RAM和最大可用(Xmx参数)RAM 分别设置为 748MB。您也可以使用更高的数字,但不应低于该数字以确保可用性。您可以在官方文档(https://developer.android.google.cn/studio/intro/studio-config.html)中找到这些(https://developer.android.google.cn/studio/intro/studio-config.html#adjusting_heap_size)和其他参数的更多信息


增加文件解析大小限制
再次单击配置Configure,然后单击“编辑自定义属性 - Edit Custom Properties”并添加 idea.max.intellisense.filesize=5000 (kb。如果您愿意,可以将其值更改为高于 5000 的值)
这是必需的,因此 Android Studio 可以解析非常大的文件以正确提供自动完成功能(Android Studio 称之为IntelliSense)。



3.开始使用 Android Studio

重新打开 Android Studio 并点击 “Open an existing project”。
然后定位到您的 Android 源码目录并打开 .ipr 文件。
注意:首次或在全新同步后打开项目可能需要一段时间,要耐心等待。


配置项目
打开项目后,导航到 File -> Project Structure -> SDKs(这可能在索引完成之前被禁用)并设置一个 JDK(LineageOS 14.1 分支须要1.8=+版),并删除其它全部的库(.jar文件)。
然后,在设置面板的左侧,选择 项目设置-Project Settings -> 模块-Modules ,并将文件夹标记 out/target/common/R 为 Sources(您也可以选择它并按 [ALT]+[S])。
按 Apply 并关闭设置界面。


4.开始开发

现在,在完成所有前面的步骤之后,您就可以真正开始开发和探索源代码了。“Find in path”功能(Edit -> Find -> Find in path)可以是一个良好的开端找到您要修改的文件。只需在所有源文件中搜索一个已知字符串,然后深入研究,直到真正找到要修改的函数。


示例

%lineage%$ source build/envsetup.sh
%lineage%$ mmm development/tools/idegen/

14:03:45 ************************************************************
14:03:45 You are building on a machine with 15.5GB of RAM
14:03:45
14:03:45 The minimum required amount of free memory is around 16GB,
14:03:45 and even with that, some configurations may not work.
14:03:45
14:03:45 If you run into segfaults or other errors, try reducing your
14:03:45 -j value.
14:03:45 ************************************************************
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=11
TARGET_PRODUCT=aosp_arm
TARGET_BUILD_VARIANT=eng
TARGET_BUILD_TYPE=release
TARGET_ARCH=arm
TARGET_ARCH_VARIANT=armv7-a-neon
TARGET_CPU_VARIANT=generic
HOST_ARCH=x86_64
HOST_2ND_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-5.11.0-40-generic-x86_64-Ubuntu-20.04.3-LTS
HOST_CROSS_OS=windows
HOST_CROSS_ARCH=x86
HOST_CROSS_2ND_ARCH=x86_64
HOST_BUILD_TYPE=release
BUILD_ID=RQ3A.211001.001
OUT_DIR=out
PRODUCT_SOONG_NAMESPACES=device/generic/goldfish device/generic/goldfish-opengl hardware/google/camera hardware/google/camera/devices/Emul
atedCamera device/generic/goldfish device/generic/goldfish-opengl
============================================
[100% 1/1] out/soong/.bootstrap/bin/soong_build out/soong/build.ninja
FAILED: out/soong/build.ninja
out/soong/.bootstrap/bin/soong_build -t -l out/.module_paths/Android.bp.list -b out/soong -n out -d out/soong/build.ninja.d -globFile out/
soong/.bootstrap/build-globs.ninja -o out/soong/build.ninja Android.bp
error: vendor/lineage/build/soong/Android.bp:24:8: module "generated_kernel_includes": cmd: unknown variable '$(PATH_OVERRIDE_SOONG)'
14:06:49 soong bootstrap failed with: exit status 1
#### failed to build some targets (03:06 (mm:ss)) ####



错误提示缺少一个变量,那么执行下面的lunch操作。
%lineage%$ lunch

You're building on Linux
Lunch menu... pick a combo:
   1. aosp_arm-eng
   2. aosp_arm64-eng
   3. aosp_car_arm-userdebug
   4. aosp_car_arm64-userdebug
   5. aosp_car_x86-userdebug
   6. aosp_car_x86_64-userdebug
   7. aosp_cf_arm64_auto-userdebug
   8. aosp_cf_arm64_phone-userdebug
   9. aosp_cf_x86_64_phone-userdebug
   10. aosp_cf_x86_auto-userdebug
   11. aosp_cf_x86_phone-userdebug
   12. aosp_cf_x86_tv-userdebug
   13. aosp_x86-eng
   14. aosp_x86_64-eng
   15. arm_krait-eng
   16. arm_v7_v8-eng
   17. armv8-eng
   18. armv8_kryo385-eng
   19. car_x86_64-userdebug
   20. lineage_arm-userdebug
   21. lineage_arm64-userdebug
   22. lineage_arm64_ab-userdebug
   23. lineage_arm_ab-userdebug
   24. lineage_car_arm64-userdebug
   25. lineage_car_x86_64-userdebug
   26. lineage_tv_arm-userdebug
   27. lineage_tv_arm64-userdebug
   28. lineage_tv_x86-userdebug
   29. lineage_tv_x86_64-userdebug
   30. lineage_x86-userdebug
   31. lineage_x86_64-userdebug
   32. lineage_x86_64_ab-userdebug
   33. lineage_x86_ab-userdebug
   34. qemu_trusty_arm64-userdebug
   35. silvermont-eng
   36. uml-userdebug



Which would you like? [aosp_arm-eng] lineage_arm64-userdebug 选择一个版本。

Trying dependencies-only mode on a non-existing device tree?
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=11
LINEAGE_VERSION=18.1-20220120-UNOFFICIAL-arm64
TARGET_PRODUCT=lineage_arm64
TARGET_BUILD_VARIANT=userdebug
TARGET_BUILD_TYPE=release
TARGET_ARCH=arm64
TARGET_ARCH_VARIANT=armv8-a
TARGET_CPU_VARIANT=generic
TARGET_2ND_ARCH=arm
TARGET_2ND_ARCH_VARIANT=armv8-a
TARGET_2ND_CPU_VARIANT=generic
HOST_ARCH=x86_64
HOST_2ND_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-5.11.0-40-generic-x86_64-Ubuntu-20.04.3-LTS
HOST_CROSS_OS=windows
HOST_CROSS_ARCH=x86
HOST_CROSS_2ND_ARCH=x86_64
HOST_BUILD_TYPE=release
BUILD_ID=RQ3A.211001.001
OUT_DIR=out
PRODUCT_SOONG_NAMESPACES=device/generic/goldfish device/generic/goldfish-opengl hardware/google/camera hardware/google/camera/devices/EmulatedCamera packages/apps/Bluetooth
============================================



再次编译idegen。
%lineage%$ make idegen 等同于上面的“mmm”指令

14:12:08 ************************************************************
14:12:08 You are building on a machine with 15.5GB of RAM
14:12:08
14:12:08 The minimum required amount of free memory is around 16GB,
14:12:08 and even with that, some configurations may not work.
14:12:08
14:12:08 If you run into segfaults or other errors, try reducing your
14:12:08 -j value.
14:12:08 ************************************************************
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=11
LINEAGE_VERSION=18.1-20220120-UNOFFICIAL-arm64
TARGET_PRODUCT=lineage_arm64
TARGET_BUILD_VARIANT=userdebug
TARGET_BUILD_TYPE=release
TARGET_ARCH=arm64
TARGET_ARCH_VARIANT=armv8-a
TARGET_CPU_VARIANT=generic
TARGET_2ND_ARCH=arm
TARGET_2ND_ARCH_VARIANT=armv8-a
TARGET_2ND_CPU_VARIANT=generic
HOST_ARCH=x86_64
HOST_2ND_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-5.11.0-40-generic-x86_64-Ubuntu-20.04.3-LTS
HOST_CROSS_OS=windows
HOST_CROSS_ARCH=x86
HOST_CROSS_2ND_ARCH=x86_64
HOST_BUILD_TYPE=release
BUILD_ID=RQ3A.211001.001
OUT_DIR=out
PRODUCT_SOONG_NAMESPACES=device/generic/goldfish device/generic/goldfish-opengl hardware/google/camera hardware/google/camera/devices/Emul
atedCamera packages/apps/Bluetooth
============================================
[ 98% 264/268] //development/tools/idegen:idegen javac [linux_glibc common]
警告: [options] 未与 -source 9 一起设置引导类路径
注: 某些输入文件使用或覆盖了已过时的 API。
注: 有关详细信息, 请使用 -Xlint:deprecation 重新编译。
1 个警告
[100% 268/268] Install: out/host/linux-x86/framework/idegen.jar
#### build completed successfully (18:57 (mm:ss)) ####

这时,生成了 idegen.jar 文件。


%lineage%$ ./development/tools/idegen/idegen.sh

find: ‘out/target/product/jason/obj/PACKAGING/target_files_intermediates/lineage_jason-target_files-eng.happy/ROOT/d’: 权限不够
find: ‘out/target/product/jason/obj/PACKAGING/target_files_intermediates/lineage_jason-target_files-eng.happy/RECOVERY/RAMDISK/d’: 权限不够
find: ‘out/target/product/jason/root/d’: 权限不够
find: ‘out/target/product/jason/recovery/root/d’: 权限不够
Read excludes: 51ms
Traversed tree: 271652ms

最终生成 android.ipr 和 android.iml 文件。


打开AndroidStudio,Open,选择ipr文件即可。
为了提高速度,可以关闭不关注的模块。右键项目,“Open Module Settings”,左边选‘Modules’,右边‘android’子面板,右键目标模块‘Excluded’。



- end

承接App定制、企业web站点、办公系统软件 设计开发,外包项目,毕设