利用Android.bp來編譯so庫
在SimpleHook模塊中钾腺,我們使用了以下構建腳本來建議Android.bp
cc_library {
name:"libsecAI",
host_supported: true,
shared_libs:[
"libnativehelper",
"libart",
"liblog",
],
local_include_dirs:[
"include",
],
arch:{
arm: {
srcs: [
"AIHook.cpp",
"HookPage.cpp",
],
},
arm64:{
srcs: [
"AIHook.cpp",
"HookPage.cpp",
],
},
},
cppflags:[
"-DART_STACK_OVERFLOW_GAP_arm=8912",
"-DART_STACK_OVERFLOW_GAP_arm64=8912",
"-DART_STACK_OVERFLOW_GAP_mips=16384",
"-DART_STACK_OVERFLOW_GAP_mips64=16384",
"-DART_STACK_OVERFLOW_GAP_x86=16384",
"-DART_STACK_OVERFLOW_GAP_x86_64=20480",
"-DIMT_SIZE=43",
],
cpp_std:"c++17",
}
可以看出,Android.bp文件的語法與json文件的形式很類似讥裤。這里cc_library是用來生成native庫的(so包)放棒,常用的屬性:
- name: 指定了生成的lib包的名字
- host_supported:當該模塊依賴的某個模塊中存在該屬性,則依賴它的模塊都需要配置該屬性
- local_include_dirs:項目內的頭文件目錄依賴己英,這里是相對路徑
- cppflag:編譯的flag選項间螟,示例中定義了一些工程依賴的宏的定義
- cpp_std: 指定了編譯器依賴的語言編譯標準
- arch: 用來指定需要的目標編譯平臺,諸如arm损肛, arm64厢破,x86等,在srcs中指定需要依賴的源碼文件(以相對文件的形式給出)
- srcs:常見的還可以直接在最外層用
srcs
屬性配置工程源碼文件 - include_dirs: 指定依賴的頭文件治拿,這里的頭文件可以為模塊外的頭文件摩泪,以相對整個Android工程路徑給出。
- export_include_dirs: 是否將頭文件導出忍啤;這使得依賴該模塊的模塊無需再引用依賴模塊的頭文件目錄加勤。
利用Android.bp來編譯Java庫
來看下framework模塊的bp文件
java_library {
name: "framework",
srcs: [
// From build/make/core/pathmap.mk FRAMEWORK_BASE_SUBDIRS
"core/java/**/*.java",
"graphics/java/**/*.java",
"location/java/**/*.java",
"lowpan/java/**/*.java",
.....
":framework-javastream-protos",
"core/java/android/accessibilityservice/IAccessibilityServiceConnection.aidl",
"core/java/android/accessibilityservice/IAccessibilityServiceClient.aidl",
"media/java/android/media/session/ISessionControllerCallback.aidl",
......
":framework-statslog-gen",
],
aidl: {
export_include_dirs: [
// From build/make/core/pathmap.mk FRAMEWORK_BASE_SUBDIRS
"core/java",
"graphics/java",
"location/java",
"lowpan/java",
"media/java",
"media/mca/effect/java",
"media/mca/filterfw/java",
"media/mca/filterpacks/java",
"drm/java",
"opengl/java",
"sax/java",
"telecomm/java",
"telephony/java",
"wifi/java",
"keystore/java",
"rs/java",
],
include_dirs: [
"system/update_engine/binder_bindings",
"system/bt/binder",
"system/security/keystore/binder",
],
},
exclude_srcs: [
// See comment on framework-atb-backward-compatibility module below
"core/java/android/content/pm/AndroidTestBaseUpdater.java",
// See comment on framework-oahl-backward-compatibility module below
"core/java/android/content/pm/OrgApacheHttpLegacyUpdater.java",
],
no_framework_libs: true,
libs: [
"conscrypt",
"okhttp",
"bouncycastle",
"ext",
],
static_libs: [
"framework-protos",
"android.hidl.base-V1.0-java",
"android.hardware.cas-V1.0-java",
],
// Loaded with System.loadLibrary by android.view.textclassifier
required: [
"libtextclassifier",
"libmedia2_jni",
],
javac_shard_size: 150,
dxflags: [
"--core-library",
"--multi-dex",
],
}
首先java_library
說明了編譯的是java庫仙辟,另外還可能有java_library_static
,file_group
等屬性,這里面有好多屬性鳄梅,我們重點關注幾個選項叠国。
- name:指定了模塊名
- static_libs:指定了依賴的靜態(tài)庫(將被打入到jar中)
- libs: 共享庫
- srcs:指定模塊中含有的java代碼,這里也可以指定aidl文件戴尸。這里通過
"core/java/**/*.java"
,這種寫法來覆蓋某個路徑下的所有java文件 - aidl: 一般我們會在這里面指定aidl文件相對路徑