Android source code compilation method

8bc3cdb013e83efa66931a23abde655d.gif

Learn with you for lifeXi, this is Programmer Android

Recommended classic articles. By reading this article, you will gain the following knowledge points:

1. View the branch where the project is located
2. Switch to the target branch
3. View the current branch
4. Compile Android source code
5. Source Android compilation environment
6. Lunch required compilation projects
7. Single compilation module
8. Push module to verify whether the modification takes effect
9. References

1. Check the branch where the project is located

git branch -a
Representation: View and list all branches of the current project

Examples of Qualcomm projects are as follows:

Test@Test:/Test/Qualcomm_p/E27M_MSM8917_QM215_r26/LA.UM.7.6.2/LINUX/android$ git branch -a
* linux_android_development
  master
  remotes/origin/A/B_update_linux_android_development
  remotes/origin/HEAD -> origin/master
  ... ...
  remotes/origin/secure_linux_android_development
  remotes/origin/streamlined_code_engineering
Test@Test:/Test/Qualcomm_p/E7M_MSM8917_QM215_r26/LA.UM.7.6.2/LINUX/android$

2. Switch to the target branch

git checkout 分支名
Means: Switch to a branch.

Examples of Qualcomm projects are as follows:
git checkout linux_android_development

Test@Test:/Test/Qualcomm_p/E27M_MSM8917_QM215_r26/LA.UM.7.6.2/LINUX/android$ git branch -a
* linux_android_development
  master
  remotes/origin/A/B_update_linux_android_development
  remotes/origin/HEAD -> origin/master
  remotes/origin/cts_development_branch
  ... ...
Test@Test:/Test/Qualcomm_p/E27M_MSM8917_QM215_r26/LA.UM.7.6.2/LINUX/android$ git checkout linux_android_development

3. View the current branch

git branch
Indicates: View the current branch

Examples of Qualcomm projects are as follows:

Test@Test:/Test/Qualcomm_p/E27M_MSM8917_QM215_r26/LA.UM.7.6.2/LINUX/android$ git branch 
* linux_android_development
  master
Test@Test:/Test/Qualcomm_p/E27M_MSM8917_QM215_r26/LA.UM.7.6.2/LINUX/android$

4. Compile Android source code

Android Source code compilation, because each project has different scripts, the compilation commands may sometimes be different.

Google official compilation command is as follows

1.source ./build/envsetup.sh
2.lunch project
3.make -j8

Qualcomm project compilation commands are as follows:

./buildall_userdebug.sh E5527M all

5. source Android compilation environment

First enter Android the source code root directory and execute it source ./build/envsetup.sh.
If not source, you will not be able to compile the module separately later.

Examples of Qualcomm projects are as follows:

Test@Test:/Test/Qualcomm_p/E27M_MSM8917_QM215_r26/LA.UM.7.6.2/LINUX/android$ source ./build/envsetup.sh 
including device/generic/car/vendorsetup.sh
including device/generic/mini-emulator-arm64/vendorsetup.sh
including device/generic/mini-emulator-armv7-a-neon/vendorsetup.sh
including device/generic/mini-emulator-x86_64/vendorsetup.sh
including device/generic/mini-emulator-x86/vendorsetup.sh
including device/generic/uml/vendorsetup.sh
including device/google/muskie/vendorsetup.sh
including device/google/taimen/vendorsetup.sh
including device/qcom/common/vendorsetup.sh
including device/qcom/qssi/vendorsetup.sh
including vendor/partner_gms/products/vendorsetup.sh
including vendor/qcom/opensource/core-utils/vendorsetup.sh
including vendor/qcom/proprietary/common/vendorsetup.sh
including vendor/qcom/proprietary/prebuilt_HY11/vendorsetup.sh
Created 9 symlinks out of 9 mapped links..
including sdk/bash_completion/adb.bash
Test@Test:/Test/Qualcomm_p/E27M_MSM8917_QM215_r26/LA.UM.7.6.2/LINUX/android$

6. Compilation projects required for lunch

Execute  lunch the command to view the list of all compiled projects, and then select the compiled project.
Examples of Qualcomm projects are as follows:

1. lunch, then select the required compilation branch
Test@Test:/Test/Qualcomm_p/E7M_MSM8917_QM215_r26/LA.UM.7.6.2/LINUX/android$ lunch

You're building on Linux

Lunch menu... pick a combo:
     1. aosp_arm-eng
     2. aosp_arm64-eng
     3. aosp_mips-eng
     ... ...
     40. msm8937_64-userdebug
     41. msm8937_64-user
     ... ...
     65. taimenb2-userdebug
// 选择要编译的分支名
Which would you like? [aosp_arm-eng] msm8937_64-userdebug

device/qcom/msm8937_64/msm8937_64.mk:42: warning: "Build with 4.9 kernel"

 ... ...
OUT_DIR=out
============================================
Test@Test:/Test/Qualcomm_p/E27M_MSM8917_QM215_r26/LA.UM.7.6.2/LINUX/android$
2. Directly lunch branch

For example, if we need to compile msm8937_64-userdebuga project, we can actually perform the simplest method and directly luncharrange the position of the project, such aslunch 40

Test@Test:/Test/Qualcomm_p/E7M_MSM8917_QM215_r26/LA.UM.7.6.2/LINUX/android$ lunch 40
device/qcom/msm8937_64/msm8937_64.mk:42: warning: "Build with 4.9 kernel"

============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=9
TARGET_PRODUCT=msm8937_64
... ...

HOST_CROSS_2ND_ARCH=x86_64
HOST_BUILD_TYPE=release
BUILD_ID=PKQ1.190601.001
OUT_DIR=out
============================================
Test@Test:/Test/Qualcomm_p/27M_MSM8917_QM215_r26/LA.UM.7.6.2/LINUX/android$

7. Single module

We often  use mmm and mm compile single modules.
mmm The mm main difference is the directory location you are currently in. Use 
if you are currently at the place where you want to compile the module , otherwise use .(需要有android.mk文件,才可以进行)mmmmm

Examples of Qualcomm projects are as follows:

1. Examples of using mmm (not in the FM directory at this time)

For example, single editing FMis not FMin the directory and needs to be executed.mmm vendor/qcom/opensource/commonsys/fm/fmapp2/

Test@Test:/Test/Qualcomm_p/E27M_MSM8917_QM215_r26/LA.UM.7.6.2/LINUX/android$ mmm vendor/qcom/opensource/commonsys/fm/fmapp2/

/Test/Qualcomm_p/E5527M_MSM8917_QM215_r26/LA.UM.7.6.2/LINUX/android/vendor/qcom/opensource/commonsys/fm/fmapp2/
Restriction Checker not present, skipping..
device/qcom/msm8937_64/msm8937_64.mk:42: warning: "Build with 4.9 kernel"
============================================
... ...
OUT_DIR=out
============================================
QSSI: not enabled for msm8937_64 target as vendor/qcom/proprietary/release/QSSI/QSSI_enforced_targets_list.txt was not found.

... ...
#### build completed successfully (7 seconds) ####

Test@Test:/Test/Qualcomm_p/E27M_MSM8917_QM215_r26/LA.UM.7.6.2/LINUX/android$
2. mm usage examples (in the FM directory)

For example, if you edit a single file FMin FMthe directory, you need to executemm

Test@Test:/Test/Qualcomm_p/E27M_MSM8917_QM215_r26/LA.UM.7.6.2/LINUX/android$ cd  vendor/qcom/opensource/commonsys/fm/fmapp2/
Test@Test:/Test/Qualcomm_p/E27M_MSM8917_QM215_r26/LA.UM.7.6.2/LINUX/android/vendor/qcom/opensource/commonsys/fm/fmapp2$ mm
Restriction Checker not present, skipping..
device/qcom/msm8937_64/msm8937_64.mk:42: warning: "Build with 4.9 kernel"
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=9
... ...
OUT_DIR=out
============================================
QSSI: not enabled for msm8937_64 target as vendor/qcom/proprietary/release/QSSI/QSSI_enforced_targets_list.txt was not found.
ninja: no work to do.
... ...
build/make/core/base_rules.mk:412: warning: ignoring old commands for target `out/target/product/msm8937_64/vendor/lib64/hw/fingerprint.default.so'
ninja: no work to do.

#### build completed successfully (41 seconds) ####

Test@Test:/Test/Qualcomm_p/E7M_MSM8917_QM215_r26/LA.UM.7.6.2/LINUX/android/vendor/qcom/opensource/commonsys/fm/fmapp2$

8. The push module verifies whether the modification is effective

1. Use the debug version and mount the mobile phone

adb shell getprop ro.build.type It is mainly used to check the currently used version. Only debug the version can be used for debugging, and userthe version cannot be debugged.

Examples of Qualcomm projects are as follows:

C:\Users\Administrator>adb shell getprop ro.build.type
userdebug

C:\Users\Administrator>adb root

C:\Users\Administrator>adb remount
remount succeeded

C:\Users\Administrator>
2. Copy the generated single-module compiled apk to the desktop and push it to the mobile phone

adb push 本地文件 手机目录
adb pushIt is mainly used to replace the one in the mobile phone apkand debug to verify whether the single editor is effective.

Qualcomm’s  FM example is as follows:

C:\Users\Administrator>adb push C:\Users\Administrator\Desktop\FM2.apk /system/app/FM2
C:\Users\Administrator\Desktop\FM2.apk: 1 file pushed. 9.7 MB/s (861880 bytes in 0.085s)

C:\Users\Administrator>
3. Clear the storage data of push apk

adb shell pm clear 包名
Used to clear the data of the current package name.
for example:adb shell pm clear com.caf.fmradio

Qualcomm’s  FM apkexample is as follows:

C:\Users\Administrator>adb shell dumpsys activity | findstr Run
    Running activities (most recent first):
        Run #0: ActivityRecord{3bc8d7d u0 com.caf.fmradio/.FMRadio t52}
    Running activities (most recent first):
        Run #0: ActivityRecord{89df584 u0 com.android.launcher3/com.android.searchlauncher.SearchLauncher t51}
C:\Users\Administrator>adb shell pm clear com.caf.fmradio
Success

C:\Users\Administrator>

references:

[Tencent Documentation] Android Framework Knowledge Base
https://docs.qq.com/doc/DSXBmSG9VbEROUXF5

Friendly recommendation:

Collection of useful information on Android development

At this point, this article has ended. The editor thinks the article is reprinted from the Internet and is excellent. You are welcome to click to read the original article and support the original author. If there is any infringement, please contact the editor to delete it. Your suggestions and corrections are welcome. We look forward to your attention and thank you for reading, thank you!

5aef24a2f64d1465cd321ac1c8a2451d.jpeg

Click to read the original article and like the boss!

Guess you like

Origin blog.csdn.net/wjky2014/article/details/131671913