早期的Android系統都是採用Android.mk的配置來編譯源碼,從Android 7.0開始引入Android.bp。很明顯Android.bp的出現就是爲了替換掉Android.mk。html
而後開始介紹如何經過Android.bp來引入一個hello world
模塊。
一、目錄結構android
./device/mi/pure/hello/ ├── Android.bp └── hello.cpp 0 directories, 2 files
2.hello.cpp
文件c++
#include <cstdio> #include <android/log.h> #define LOG_TAG "qiushao" #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG ,__VA_ARGS__) #define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG ,__VA_ARGS__) int main() { printf("hello qiushao\n"); LOGD("hello qiushao"); return 0; }
三、Android.bp
文件git
cc_binary { //模塊類型爲可執行文件 name: "hello", //模塊名hello srcs: ["hello.cpp"], //源文件列表 vendor: true, //編譯出來放在/vendor目錄下(默認是放在/system目錄下) shared_libs: [ //編譯依賴的動態庫 "liblog", ], }
四、編譯hello模塊shell
hinzer@ubuntu:hello$ mma
五、添加product配置ubuntu
hinzer@ubuntu:pure$ pwd /home/hinzer/source/android-10/device/mi/pure hinzer@ubuntu:pure$ echo "PRODUCT_PACKAGES += hello" >> product01.mk
六、整編android系統bash
hinzer@ubuntu:android-10$ source ./build/envsetup.sh hinzer@ubuntu:android-10$ lunch product01-eng hinzer@ubuntu:android-10$ make -j4
這是其中一個常見的模塊實例,須要定義其餘類型的模塊時,能夠參考如下文檔soong。或者參考系統已有的 Android.bp 模塊。框架
hinzer@ubuntu:android-10$ emulator ... hinzer@ubuntu:~$ adb devices List of devices attached emulator-5554 device hinzer@ubuntu:~$ adb shell hello # 運行可執行文件hello hello qiushao
一、模塊編譯輸出分區ide