一。android大约从7.0开始引入 .bp文件代替以前的.mk文件,用于帮助android项目的编译配置文件。
二。mk文件转化为bp文件,可以使用下面命令转化,注意命令中>,这是写入文件。androidmk是android源码自带的工具,他可以显示mk转换后的bp,后面是写入Android.bp
androidmk Android.mk > Android.bp
三。这两个编译脚本可以对应,所以能够转化,可以在下面的文件中看到对应的规则,事实是,虽然使用了bp,但mk依然可以正常使用,如果有老项目,可以不必转化
/build/soong/androidmk/cmd/androidmk/android.go
1.host_supported: true, 是否支持主机,一般是支持linux系统
2.cc_library ,cc_library_static,cc_library_shared区别,cc_library_static构建静态库,静态库会编译进目标文件,cc_library_shared构建动态共享库,动态库不会编译进目标文件,cc_library可以根据需要设置不同的参数
3aidl_interface专门用于构建aidl,具有一套不同于其他的参数。比如versions_with_info,backend,unstable,owner,stability: "vintf",
4.filegroup
的主要用途包括:
-
文件集合:
filegroup
允许将多个文件组合成一个逻辑上的单元。这些文件可以是源代码文件、资源文件、配置文件或任何其他类型的文件。通过将文件组织在一起,可以方便地对它们进行管理和处理。 -
共享文件:
filegroup
可以用于创建共享文件集合,供其他模块使用。其他模块可以通过依赖filegroup
来访问其中的文件,从而避免了重复的文件复制或定义。 -
文件过滤:
filegroup
允许根据特定的规则或条件对文件进行过滤。这样可以在构建过程中选择性地包含或排除某些文件,以满足特定的需求。 -
文件权限:
filegroup
可以指定文件的权限和属性。这包括文件的所有者、组、访问权限等。通过filegroup
,可以集中管理文件的权限设置,确保文件在构建和部署过程中具有正确的权限。 -
文件打包:
filegroup
可以将文件打包成一个压缩文件(如 ZIP 或 JAR),以方便在构建过程中进行传输、发布或部署。 -
platform_apis: true
:该字段用于指定是否生成平台 API 接口代码。平台 API 是指供 Android 系统内部使用的接口,而不是用于公开给应用程序开发者使用的接口。通过设置platform_apis: true
,您可以生成用于 Android 系统内部使用的接口代码。
四。bp编译脚本常用的模块关键字
1.编译成 Java 库 java_library 2.编译成 Java 静态库 java_library_static 3.编译成 App 应用 Android.bp android_app { ...... }
4编译成 Native 动态库 Android.bp cc_library_shared { ...... } 5 编译成 Native 静态库 Android.bp cc_library_static { ...... } 6 编译成 Native 执行程序 Android.bp cc_binary { ...... } 7 编译成头文件库 Android.bp cc_library_headers { ...... } 8 预加载静态库 cc_prebuilt_library_static 9 预加载动态库 cc_prebuilt_library 五文件路径 1 本地头文件路径 Android.bp local_include_dirs: ["xxx", ...] 2 导出的头文件路径 Android.bp export_include_dirs: ["xxx", ...] 3 资源文件路径 Android.bp resource_dirs: ["xxx", ...] 六 库依赖 1 依赖的静态库 Android.bp static_libs: ["xxx", "xxx", ...] 2 依赖的动态库 Android.bp shared_libs: ["xxx", "xxx", ...] 3 依赖的头文件库 Android.bp header_libs: ["xxx", "xxx", ...] 4 依赖的 Java 库 Android.bp static_libs: ["xxx", "xxx", ...] 七安装到不同分区中 1 安装到vendor中 Android.bp proprietary: true or vendor: true 2 安装到product中 Android.bp product_specific: true 3 安装到odm中 Android.bp device_specific: true 八编译参数 1 C flags Android.bp cflags: ["xxx", "xxx", ...] 2 Cpp flags Android.bp cppflags: ["xxx", "xxx", ...] 3 Java flags Android.bp javacflags: ["xxx", "xxx", ...]
九一个放置第三方open ssl so和a的bp
cc_prebuilt_library_static {
name: "liboopenssl",
//product_available: true,
//vendor_available: true,
//vndk: {
// enabled: true,
//},
srcs: [
"lib/libssl.a",
],
export_include_dirs: ["include"],
//vendor: true
}
cc_prebuilt_library {
name: "libopenssl_shared",
product_available: true,
vendor_available: true,
vndk: {
enabled: true,
},
srcs: [
"lib/libssl.so",
],
shared_libs: [
],
//sanitize: {
// never: true,
//},
static_libs: [
//"liboopenssl",
],
export_include_dirs: ["include"],
//vendor: true
}
cc_prebuilt_library_static {
name: "liboopencrypto",
//product_available: true,
//vendor_available: true,
//vndk: {
// enabled: true,
//},
srcs: [
"lib/libcrypto.a",
],
export_include_dirs: ["include"],
//vendor: true
}
cc_prebuilt_library {
name: "libopencrypto_shared",
product_available: true,
vendor_available: true,
vndk: {
enabled: true,
},
srcs: [
"lib/libcrypto.so",
],
shared_libs: [
],
//sanitize: {
// never: true,
//},
static_libs: [
//"liboopencrypto",
],
export_include_dirs: ["include"],
//vendor: true
}
十。C++ aidl生成
cc_library_static{
name:"libaidltest",
local_include_dirs:[
"include"
],
aidl:{
local_include_dirs:["aidl"],
include_dirs:[
"frameworks/native/aidl/binder"
],
export_aidl_headers:true,
},
srcs:[
"FileInfo.cpp",
":libfile_aidl"
],
shared_libs:[
"libbinder",
"libutils",
],
}
filegroup{
name:"libfile_aidl",
srcs:[
"aidl/com/hht/FileInfo.aidl",
"aidl/com/hht/IFileInfoCallback.aidl",
"aidl/com/hht/IGetFileInfo.aidl"
],
path:"aidl",
}
十二
// 生成一个so库
cc_library_static {
name: "libfileservice_aidl",
srcs: [
":fileservice_aidl",
],
aidl: {
local_include_dirs: ["aidl"],
include_dirs: [
"frameworks/native/aidl/binder"
],
export_aidl_headers: true,
},
shared_libs: [
"libbinder",
"libutils",
"liblog",
],
}
filegroup {
name: "fileservice_aidl",
srcs: [
"aidl/com/filetool/IFileOperation.aidl",
],
path:"aidl",
}
//
// 生成可执行文件
cc_binary {
name: "fileservice",
srcs: [
"main.cpp",
"FileService.cpp",
],
init_rc: ["sota.rc"],
cflags: [
"-Werror",
"-Wno-error=deprecated-declarations",
"-Wall",
"-Wformat-security",
"-Wno-unused-parameter",
],
shared_libs: [
"libbinder",
"libcutils",
"liblog",
"libutils",
"libbase",
],
static_libs:[
"libfileservice_aidl",
]
}
新增如下语句,这里以 lottie.arr 为例 android_library_import { name: "lib-lottie", aars: ["lottie-2.8.0.aar"], sdk_version: "current", }
然后在模块目录下 Android.bp 文件中的 android_app {} 中 static_libs 引入 “lib-lottie”,
android_app { name: "LiveTv", srcs: ["src/**/*.java"], static_libs: [ "lib-lottie", "android-support-annotations", "android-support-compat", "android-support-core-ui", "androidx.tvprovider_tvprovider", "android-support-v4", ....
模块目录下 Android.bp 文件中的 resource_dirs: [] 引入
android_app { name: "LiveTv", srcs: ["src/**/*.java"], resource_dirs: [ "res", "res_ext", "res-lottie", ], static_libs: [ "lib-lottie", "android-support-annotations", "android-support-compat", "android-support-core-ui", "androidx.tvprovider_tvprovider", "android-support-v4", .... ], aaptflags: [ "--extra-packages", "com.airbnb.lottie", ],
在模块源码根文件下新建文件夹 libs,复制要引入的 jar 包至此,新建 Android.bp
新增如下语句,这里以 opencv.jar 为例
java_import { name: "face-opencv-jar", jars: ["opencv.jar"], sdk_version: "current", }
新增如下语句,这里以 libjniopencv_face.so 为例, arm 和 arm64 分别对应32/64的so库,针对源码环境
位数都是确定的,所以我们就写成一样了
cc_prebuilt_library_shared { name: "libjniopencv_face", arch: { arm: { srcs: ["armeabi/libjniopencv_face.so"], }, arm64: { srcs: ["armeabi/libjniopencv_face.so"], }, }, }
然后在模块目录下 Android.bp 文件中的 android_app {} 中 jni_libs 引入 “libjniopencv_face”,
android_app { name: "LiveTv", jni_libs: [ "libjniopencv_face", ] ]
一个完整的包含 aar/jar/so Android.bp
----Android.bp ----lottie-2.8.0.aar ----face-opencv-jar ----armeabi -----libjniopencv_face.so -----libopencv_text.so
android_library_import { name: "lib-lottie", aars: ["lottie-2.8.0.aar"], sdk_version: "current", } java_import { name: "face-opencv-jar", jars: ["opencv.jar"], sdk_version: "current", } cc_prebuilt_library_shared { name: "libjniopencv_face", arch: { arm: { srcs: ["armeabi/libjniopencv_face.so"], }, arm64: { srcs: ["armeabi/libjniopencv_face.so"], }, }, } cc_prebuilt_library_shared { name: "libopencv_text", arch: { arm: { srcs: ["armeabi/libopencv_text.so"], }, arm64: { srcs: ["armeabi/libopencv_text.so"], }, }, }
模块根路径Android.bp
android_app { name: "LiveTv", srcs: ["src/**/*.java"], // TODO(b/122608868) turn proguard back on optimize: { enabled: false, }, // It is required for com.android.providers.tv.permission.ALL_EPG_DATA privileged: true, sdk_version: "system_current", min_sdk_version: "23", // M resource_dirs: [ "res", "material_res", "res-lottie", ], libs: [ "face-opencv-jar", ], static_libs: [ "android-support-compat", "android-support-core-ui", "androidx.tvprovider_tvprovider", "android-support-v4", "android-support-v7-appcompat", "android-support-v7-palette", "android-support-v7-preference", "android-support-v7-recyclerview", "android-support-v14-preference", "android-support-v17-leanback", "android-support-v17-preference-leanback", "lib-lottie", ], jni_libs: [ "libjniopencv_face", "libopencv_text", ] javacflags: [ "-Xlint:deprecation", "-Xlint:unchecked", ], aaptflags: [ "--version-name", version_name, "--version-code", version_code, "--extra-packages", "com.android.tv.tuner", "--extra-packages", "com.airbnb.lottie", ], }
aidl
package {
// See: http://go/android-license-faq
// A large-scale-change added 'default_applicable_licenses' to import
// all of the 'license_kinds' from "hardware_interfaces_license"
// to get the below license kinds:
// SPDX-license-identifier-Apache-2.0
default_applicable_licenses: ["hardware_interfaces_license"],
}
// 这个package也是需要的,用于获取license
aidl_interface {
name: "android.hardware.automotive.mytest",
vendor_available: true,
owner: "android",
srcs: ["android/hardware/automotive/mytest/*.aidl"],
stability: "vintf",
// 指定需要生成的接口,这里制定了java接口和c++的ndk接口,也可以定义aidl的版本,
// 该文件中没有定义默认是v1
backend: {
java: {
enabled: true,
sdk_version: "module_current",
min_sdk_version: "31",
apex_available: [
"//apex_available:platform",
"com.android.car.framework",
],
},
ndk: {
enabled: true,
},
},
}
模块 1
10 filegroup {
//1、定义 filegroup 模块 services.core-sources-am-wm
11 name: "services.core-sources-am-wm",
12 srcs: [
13 "java/com/android/server/am/**/*.java",
15 ],
16 path: "java",
17 visibility: ["//frameworks/base/services"],
18 }
模块 2
20 filegroup {
21 name: "services.core-sources",
22 srcs: ["java/**/*.java"],
23 exclude_srcs: [
//2、引用在 1 中定义的模块 services.core-sources-am-wm
24 ":services.core-sources-am-wm",
25 ],
26 path: "java",
27 visibility: [
28 "//frameworks/base/services",
30 ],
31 }
模块 3
33 genrule {
//3、定义 genrule 模块 services.core.protologsrc
34 name: "services.core.protologsrc",
35 srcs: [
//4、引用在 1 中定义的模块 services.core-sources-am-wm
37 ":services.core-sources-am-wm",
38 ],
39 tools: ["protologtool"],
40 cmd: "$(location protologtool) transform-protolog-calls " +
47 "$(locations :services.core-sources-am-wm)",
48 out: ["services.core.protolog.srcjar"],
49 }
模块 4
91 java_library_static {
92 name: "services.core.unboosted",
93 defaults: ["platform_service_defaults"],
94 srcs: [
//5、引用在 3 中定义的模块 services.core.protologsrc
97 ":services.core.protologsrc",
114 ],
166 }
package {
// See: http://go/android-license-faq
// A large-scale-change added 'default_applicable_licenses' to import
// all of the 'license_kinds' from "hardware_interfaces_license"
// to get the below license kinds:
// SPDX-license-identifier-Apache-2.0
default_applicable_licenses: ["hardware_interfaces_license"],
}
cc_binary {
name: "android.hardware.automotive.mytest.example",
relative_install_path: "hw",
vendor: true,
shared_libs: [
"android.hardware.automotive.mytest-V1-ndk", // 引用的是out目录下的ndk,主要就是这一行代码
"liblog",
"libbase",
"libcutils",
"libutils",
"libbinder_ndk",
],
srcs: [
"main.cpp",
"MyTest.cpp",
],
}
十。错误总结
java.lang.IllegalArgumentException: Not a valid class name
javah com.xx.aaa.java文章来源:https://www.toymoban.com/news/detail-654356.html
Android.bp语法和使用方法讲解 (yii666.com)aidl 实现native service和App通信_aidl native service_东东旭huster的博客-CSDN博客Android.bp 文件中引入aar、jar、so库正确编译方法(值得收藏)-阿里云开发者社区android.bp 使用_android.bp filegroup_会灰的飞猫的博客-CSDN博客Android 13 AIDL服务编写_c-Schutz的博客-CSDN博客文章来源地址https://www.toymoban.com/news/detail-654356.html
到了这里,关于android bp脚本的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!