使用Android.bp在Android源码下编译C++项目
Android.bp用法
-
1.把自己的C++项目放到Android源码目录下,进入项目,执行mm或mma编译项目
-
2.会自动查找此目录下所有的Android.bp,根据bp的规则编译项目
Android.bp函数作用介绍
//为 C/C++ 编译(cc_library、cc_binary等模块)设置一些默认的编译选项和属性,
cc_defaults {
name: "my_defaults",
// cpp_std: "c++14",
//设置编译选项
cflags: [
"-Wall",
"-Werror",
"-Wextra",
"-DLOG_TAG=\"CaEvs\"" //定义宏 LOG_TAG="CaEvs"
]
}
//libtest_headers模块
//用于导出头文件,其它模块引用此模块时,即可直接使用此模块导出的头文件
cc_library_headers {
name: "libtest_headers",
export_include_dirs: [
"include"
]
}
//创建一个名为libtest的模块
//此模块指定生成动态库libtest.so
cc_library_shared {
name: "libtest",
//引用my_defaults中设好的配置
defaults: [
"my_defaults"
],
//指定从哪个路径查找源文件
srcs: [
"src/*.cpp"
],
//指定不包含哪些源文件
exclude_srcs: [
"src/render/window/WaylandWindow.cpp",
"src/render/window/X11Window.cpp",
"src/render/renderer/GlCamera.cpp",
],
//指定需要链接的动态库
shared_libs: [
"libz",
"libtinyxml2",
"libnativewindow",
"libandroid",
],
compile_multilib: "64",
//指定需要链接的静态库
static_libs: [
"libjpeg",
"libpng",
"libavfilter_a",
"libavformat_a",
"libavcodec_a",
"libavutil_a",
"libswresample_a",
"libswscale_a",
"libavdevice_a",
],
//引入libtest_headers模块
header_libs:[
"libtest_headers"
],
//libtest模块导出的头文件。
//可以被其它模块使用
export_include_dirs: ["include"],
//导出本模块引用的libpng,libjpeg模块的头文件
export_static_lib_headers: [
"libpng",
"libjpeg"
],
//导出本模块引用的libtinyxml2模块的头文件
export_shared_lib_headers: [
"libtinyxml2",
],
//导出本模块引用的libtest_headers模块的头文件
export_header_lib_headers: [
"libtest_headers"
],
cflags: [
"-Wno-unused-parameter",
"-Wno-unused-private-field",
"-Wno-unused-variable",
"-DEVS_USE_ANDROID_WINDOW",//定义宏
]
}
//创建一个名为libtest_static的模块
//此模块指定生成静态库libtest_static.a
cc_library_static {
name: "libtest_static",
defaults: [
"caevs_defaults"
],
srcs: [
"src/*.cpp"
],
shared_libs: [
"libbase",
"libbinder",
"libcutils",
"libutils",
"libui",
"libgui",
"libhidlbase",
"libhardware",
"libcamera_metadata",
"android.hardware.camera.device@3.2",
"android.hardware.automotive.evs@1.0",
"android.hardware.automotive.evs@1.1",
"android.hardware.automotive.vehicle@2.0",
"libtinyxml2",
"libz",
"libnativewindow",
"libandroid",
],
compile_multilib: "64",
static_libs: [
"libjpeg",
"libpng",
"libavfilter_a",
"libavformat_a",
"libavcodec_a",
"libavutil_a",
"libswresample_a",
"libswscale_a",
"libavdevice_a",
],
export_include_dirs: ["include"],
cflags: [
"-Wno-unused-parameter",
"-Wno-unused-private-field",
"-Wno-unused-variable"
]
}
//引入预编译库
//创建一个libavfilter_a模块,
//此模块为静态库libavfilter.a,生成一个别名为libavfilter_a.a(可以取一样的名字)的静态库,
//在其它模块中可直接引用此模块
cc_prebuilt_library_static {
name: "libavfilter_a",
check_elf_files:false,
arch: {
arm: {
srcs: [
"lib/android/armv7-a/libavfilter.a",
],
},
arm64: {
srcs: [
"lib/android/aarch64/libavfilter.a",
],
},
},
export_include_dirs: [
"include"
],
strip: {
keep_symbols: true,
}
}
//参考cc_prebuilt_library_static
cc_prebuilt_library_shared {
}
标签:cc,下用,headers,源码,static,模块,Android,libtest
From: https://www.cnblogs.com/linxisuo/p/18429130