Android studio imports Android source code (AOSP Android 14)

1. Completely compile the AOSP source code

Some java files are dynamically generated during the compilation process, and they need to be compiled completely to complete the source code dependencies.

$ source build/envsetup.sh
$ make -j20

2. Generate project files imported by IDE

$ source build/envsetup.sh
$ make idegen
# 或者 mmm development/tools/idegen/
$ development/tools/idegen/idegen.sh

After the execution is complete, a file is generated under the AOSP root directory:

android.iml # 导入前需先编辑这个文件
android.ipr # 在Android studio中打开这个文件,导入源码工程

3. Before importing, edit the project file

(This step is very important, it affects the loading speed and jump of the code)
To edit the android.iml file, you need to modify 2 parts:
1) Add the excludeFolder list to exclude unnecessary source code paths, which can speed up the import and creation of file indexes . There are missing excludeFolder items in the .iml file, which can be added later according to your needs. For example:

<excludeFolder url="file://$MODULE_DIR$/abi"/>
<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$/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$/libcore"/> -->
<excludeFolder url="file://$MODULE_DIR$/libnativehelper"/>
<excludeFolder url="file://$MODULE_DIR$/ndk"/>
<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$/sdk"/>
<!-- <excludeFolder url="file://$MODULE_DIR$/system"/> -->
<excludeFolder url="file://$MODULE_DIR$/tools"/>
<!-- <excludeFolder url="file://$MODULE_DIR$/vendor"/> -->
<excludeFolder url="file://$MODULE_DIR$/toolchain"/>
<excludeFolder url="file://$MODULE_DIR$/compatibility"/>
<excludeFolder url="file://$MODULE_DIR$/compatibility"/>
<excludeFolder url="file://$MODULE_DIR$/test"/>

Note: You can also add excluded paths by modifying the development/tools/idegen/excluded-paths file.

2) Delete all <orderEntry type="module-library">...</orderEntry>items. These items are jar packages compiled from the referenced source code. If you keep them, you will jump to these files instead of the source code files during the jarbrowsing classprocess java. After deletion, you can jump directly to the source code file.
Note: These settings can also be modified in Android studio: project structure - project settings - modules - dependencies, the speed is relatively slow, it is not as convenient as directly editing the .iml file.
For example:

<orderEntry type="module-library">
  <library>
    <CLASSES>
      <root url="jar://$MODULE_DIR$/./AMSS/lagvm/LINUX/android/out/target/product/prodname/system/framework/locksettings.jar!/" />
    </CLASSES>
    <JAVADOC />
    <SOURCES />
  </library>
</orderEntry>
<orderEntry type="module-library">
  <library>
    <CLASSES>
      <root url="jar://$MODULE_DIR$/./AMSS/lagvm/LINUX/android/out/target/product/prodname/system/framework/framework.jar!/" />
    </CLASSES>
    <JAVADOC />
    <SOURCES />
  </library>

4. Import the project into Android Studio

Open the android.ipr file generated above in Android Studio. If the above edits are done and only the required source directories are kept, the loading time will be shorter.
After the loading is complete, you can browse and edit the code completely.
When the AS is closed, the current configuration and index will be saved to the file android.iws. It will be very fast to open the project again in the future.

Modify Android Studio configuration parameters:
1) Help - Edit custom Properties:
(corresponding configuration file: ~/.config/Google/AndroidStudio version / idea . properties ) ' idea . max . intellisense . filesize = 100000 ' 2 ) H elp − E ditcustom VM options: (corresponding configuration file: / . config / G oogle / A ndroid S studio version/idea.properties) `idea.max.intellisense.filesize=100000` 2) Help - Edit custom VM options: (corresponding configuration file : ~/.config/Google/AndroidStudioversion/idea.propertiesidea.max.intellisense.filesize=100000‘2HelpE d i t c u s t o mV M o pt i o n s : (corresponding configuration file: /. co n f i g / G oo g l e / A n d ro i d St u d i o  version/ studio64.vmoptions)
-Xms1g
-Xmx5g

If the modified parameters are incorrect and the studio cannot be started normally, you can manually edit the corresponding configuration file to delete or adjust the relevant parameters.

Guess you like

Origin blog.csdn.net/yinminsumeng/article/details/131144369