赞
踩
目录
最终都是生成Ninja格式文件进行编译。
相关概念:
Android.bp的出现就是为了替换Android.mk文件。bp跟mk文件不同,它是纯粹的配置,没有分支、循环等流程控制,不能做算数逻辑运算。如果需要控制逻辑,那么只能通过Go语言编写。旧的mk可以转换为bp,Soong会编译生成一个androidmk命令,用于将Android.mk文件转换为Android.bp文件。只针对简单的mk文件转换,涉及分支,循环等控制转换并不准确。即:
Android.mk --> Soong中androidmk --> Android.bp
直接在"build/soong/androidmk/androidmk/android.go"文件中找:
-
- var moduleTypes = map[string]string{
- "BUILD_SHARED_LIBRARY": "cc_library_shared",
- "BUILD_STATIC_LIBRARY": "cc_library_static",
- "BUILD_HOST_SHARED_LIBRARY": "cc_library_host_shared",
- "BUILD_HOST_STATIC_LIBRARY": "cc_library_host_static",
- "BUILD_HEADER_LIBRARY": "cc_library_headers",
- "BUILD_EXECUTABLE": "cc_binary",
- "BUILD_HOST_EXECUTABLE": "cc_binary_host",
- "BUILD_NATIVE_TEST": "cc_test",
- "BUILD_HOST_NATIVE_TEST": "cc_test_host",
- "BUILD_NATIVE_BENCHMARK": "cc_benchmark",
- "BUILD_HOST_NATIVE_BENCHMARK": "cc_benchmark_host",
-
- "BUILD_JAVA_LIBRARY": "java_library_installable", // will be rewritten to java_library by bpfix
- "BUILD_STATIC_JAVA_LIBRARY": "java_library",
- "BUILD_HOST_JAVA_LIBRARY": "java_library_host",
- "BUILD_HOST_DALVIK_JAVA_LIBRARY": "java_library_host_dalvik",
- "BUILD_PACKAGE": "android_app",
- "BUILD_RRO_PACKAGE": "runtime_resource_overlay",
-
- "BUILD_CTS_EXECUTABLE": "cc_binary", // will be further massaged by bpfix depending on the output path
- "BUILD_CTS_SUPPORT_PACKAGE": "cts_support_package", // will be rewritten to android_test by bpfix
- "BUILD_CTS_PACKAGE": "cts_package", // will be rewritten to android_test by bpfix
- "BUILD_CTS_TARGET_JAVA_LIBRARY": "cts_target_java_library", // will be rewritten to java_library by bpfix
- "BUILD_CTS_HOST_JAVA_LIBRARY": "cts_host_java_library", // will be rewritten to java_library_host by bpfix
- }
-
- var prebuiltTypes = map[string]string{
- "SHARED_LIBRARIES": "cc_prebuilt_library_shared",
- "STATIC_LIBRARIES": "cc_prebuilt_library_static",
- "EXECUTABLES": "cc_prebuilt_binary",
- "JAVA_LIBRARIES": "java_import",
- "APPS": "android_app_import",
- "ETC": "prebuilt_etc",
- }
-
-
- var rewriteProperties = map[string](func(variableAssignmentContext) error){
- // custom functions
- "LOCAL_32_BIT_ONLY": local32BitOnly,
- "LOCAL_AIDL_INCLUDES": localAidlIncludes,
- "LOCAL_ASSET_DIR": localizePathList("asset_dirs"),
- "LOCAL_C_INCLUDES": localIncludeDirs,
- "LOCAL_EXPORT_C_INCLUDE_DIRS": exportIncludeDirs,
- "LOCAL_JARJAR_RULES": localizePath("jarjar_rules"),
- "LOCAL_LDFLAGS": ldflags,
- "LOCAL_MODULE_CLASS": prebuiltClass,
- "LOCAL_MODULE_STEM": stem,
- "LOCAL_MODULE_HOST_OS": hostOs,
- "LOCAL_RESOURCE_DIR": localizePathList("resource_dirs"),
- "LOCAL_SANITIZE": sanitize(""),
- "LOCAL_SANITIZE_DIAG": sanitize("diag."),
- "LOCAL_STRIP_MODULE": strip(),
- "LOCAL_CFLAGS": cflags,
- "LOCAL_UNINSTALLABLE_MODULE": invert("installable"),
- "LOCAL_PROGUARD_ENABLED": proguardEnabled,
- "LOCAL_MODULE_PATH": prebuiltModulePath,
- "LOCAL_REPLACE_PREBUILT_APK_INSTALLED": prebuiltPreprocessed,
-
- // composite functions
- "LOCAL_MODULE_TAGS": includeVariableIf(bpVariable{"tags", bpparser.ListType}, not(valueDumpEquals("optional"))),
-
- // skip functions
- "LOCAL_ADDITIONAL_DEPENDENCIES": skip, // TODO: check for only .mk files?
- "LOCAL_CPP_EXTENSION": skip,
- "LOCAL_MODULE_SUFFIX": skip, // TODO
- "LOCAL_PATH": skip, // Nothing to do, except maybe avoid the "./" in paths?
- "LOCAL_PRELINK_MODULE": skip, // Already phased out
- "LOCAL_BUILT_MODULE_STEM": skip,
- "LOCAL_USE_AAPT2": skip, // Always enabled in Soong
- "LOCAL_JAR_EXCLUDE_FILES": skip, // Soong never excludes files from jars
-
- "LOCAL_ANNOTATION_PROCESSOR_CLASSES": skip, // Soong gets the processor classes from the plugin
- "LOCAL_CTS_TEST_PACKAGE": skip, // Obsolete
- "LOCAL_JACK_ENABLED": skip, // Obselete
- "LOCAL_JACK_FLAGS": skip, // Obselete
- }
-
- func init() {
- addStandardProperties(bpparser.StringType,
- map[string]string{
- "LOCAL_MODULE": "name",
- "LOCAL_CXX_STL": "stl",
- "LOCAL_MULTILIB": "compile_multilib",
- "LOCAL_ARM_MODE_HACK": "instruction_set",
- "LOCAL_SDK_VERSION": "sdk_version",
- "LOCAL_MIN_SDK_VERSION": "min_sdk_version",
- "LOCAL_NDK_STL_VARIANT": "stl",
- "LOCAL_JAR_MANIFEST": "manifest",
- "LOCAL_CERTIFICATE": "certificate",
- "LOCAL_PACKAGE_NAME": "name",
- "LOCAL_MODULE_RELATIVE_PATH": "relative_install_path",
- "LOCAL_PROTOC_OPTIMIZE_TYPE": "proto.type",
- "LOCAL_MODULE_OWNER": "owner",
- "LOCAL_RENDERSCRIPT_TARGET_API": "renderscript.target_api",
- "LOCAL_NOTICE_FILE": "notice",
- "LOCAL_JAVA_LANGUAGE_VERSION": "java_version",
- "LOCAL_INSTRUMENTATION_FOR": "instrumentation_for",
- "LOCAL_MANIFEST_FILE": "manifest",
-
- "LOCAL_DEX_PREOPT_PROFILE_CLASS_LISTING": "dex_preopt.profile",
- "LOCAL_TEST_CONFIG": "test_config",
- "LOCAL_RRO_THEME": "theme",
- })
- addStandardProperties(bpparser.ListType,
- map[string]string{
- "LOCAL_SRC_FILES": "srcs",
- "LOCAL_SRC_FILES_EXCLUDE": "exclude_srcs",
- "LOCAL_HEADER_LIBRARIES": "header_libs",
- "LOCAL_SHARED_LIBRARIES": "shared_libs",
- "LOCAL_STATIC_LIBRARIES": "static_libs",
- "LOCAL_WHOLE_STATIC_LIBRARIES": "whole_static_libs",
- "LOCAL_SYSTEM_SHARED_LIBRARIES": "system_shared_libs",
- "LOCAL_ASFLAGS": "asflags",
- "LOCAL_CLANG_ASFLAGS": "clang_asflags",
- "LOCAL_COMPATIBILITY_SUPPORT_FILES": "data",
- "LOCAL_CONLYFLAGS": "conlyflags",
- "LOCAL_CPPFLAGS": "cppflags",
- "LOCAL_REQUIRED_MODULES": "required",
- "LOCAL_HOST_REQUIRED_MODULES": "host_required",
- "LOCAL_TARGET_REQUIRED_MODULES": "target_required",
- "LOCAL_OVERRIDES_MODULES": "overrides",
- "LOCAL_LDLIBS": "host_ldlibs",
- "LOCAL_CLANG_CFLAGS": "clang_cflags",
- "LOCAL_YACCFLAGS": "yacc.flags",
- "LOCAL_SANITIZE_RECOVER": "sanitize.recover",
- "LOCAL_LOGTAGS_FILES": "logtags",
- "LOCAL_EXPORT_HEADER_LIBRARY_HEADERS": "export_header_lib_headers",
- "LOCAL_EXPORT_SHARED_LIBRARY_HEADERS": "export_shared_lib_headers",
- "LOCAL_EXPORT_STATIC_LIBRARY_HEADERS": "export_static_lib_headers",
- "LOCAL_INIT_RC": "init_rc",
- "LOCAL_VINTF_FRAGMENTS": "vintf_fragments",
- "LOCAL_TIDY_FLAGS": "tidy_flags",
- // TODO: This is comma-separated, not space-separated
- "LOCAL_TIDY_CHECKS": "tidy_checks",
- "LOCAL_RENDERSCRIPT_INCLUDES": "renderscript.include_dirs",
- "LOCAL_RENDERSCRIPT_FLAGS": "renderscript.flags",
-
- "LOCAL_JAVA_RESOURCE_DIRS": "java_resource_dirs",
- "LOCAL_JAVA_RESOURCE_FILES": "java_resources",
- "LOCAL_JAVACFLAGS": "javacflags",
- "LOCAL_ERROR_PRONE_FLAGS": "errorprone.javacflags",
- "LOCAL_DX_FLAGS": "dxflags",
- "LOCAL_JAVA_LIBRARIES": "libs",
- "LOCAL_STATIC_JAVA_LIBRARIES": "static_libs",
- "LOCAL_JNI_SHARED_LIBRARIES": "jni_libs",
- "LOCAL_AAPT_FLAGS": "aaptflags",
- "LOCAL_PACKAGE_SPLITS": "package_splits",
- "LOCAL_COMPATIBILITY_SUITE": "test_suites",
- "LOCAL_OVERRIDES_PACKAGES": "overrides",
-
- "LOCAL_ANNOTATION_PROCESSORS": "plugins",
-
- "LOCAL_PROGUARD_FLAGS": "optimize.proguard_flags",
- "LOCAL_PROGUARD_FLAG_FILES": "optimize.proguard_flags_files",
-
- // These will be rewritten to libs/static_libs by bpfix, after their presence is used to convert
- // java_library_static to android_library.
- "LOCAL_SHARED_ANDROID_LIBRARIES": "android_libs",
- "LOCAL_STATIC_ANDROID_LIBRARIES": "android_static_libs",
- "LOCAL_ADDITIONAL_CERTIFICATES": "additional_certificates",
-
- // Jacoco filters:
- "LOCAL_JACK_COVERAGE_INCLUDE_FILTER": "jacoco.include_filter",
- "LOCAL_JACK_COVERAGE_EXCLUDE_FILTER": "jacoco.exclude_filter",
-
- "LOCAL_FULL_LIBS_MANIFEST_FILES": "additional_manifests",
- })
-
- addStandardProperties(bpparser.BoolType,
- map[string]string{
- // Bool properties
- "LOCAL_IS_HOST_MODULE": "host",
- "LOCAL_CLANG": "clang",
- "LOCAL_FORCE_STATIC_EXECUTABLE": "static_executable",
- "LOCAL_NATIVE_COVERAGE": "native_coverage",
- "LOCAL_NO_CRT": "nocrt",
- "LOCAL_ALLOW_UNDEFINED_SYMBOLS": "allow_undefined_symbols",
- "LOCAL_RTTI_FLAG": "rtti",
- "LOCAL_PACK_MODULE_RELOCATIONS": "pack_relocations",
- "LOCAL_TIDY": "tidy",
- "LOCAL_USE_CLANG_LLD": "use_clang_lld",
- "LOCAL_PROPRIETARY_MODULE": "proprietary",
- "LOCAL_VENDOR_MODULE": "vendor",
- "LOCAL_ODM_MODULE": "device_specific",
- "LOCAL_PRODUCT_MODULE": "product_specific",
- "LOCAL_SYSTEM_EXT_MODULE": "system_ext_specific",
- "LOCAL_EXPORT_PACKAGE_RESOURCES": "export_package_resources",
- "LOCAL_PRIVILEGED_MODULE": "privileged",
- "LOCAL_AAPT_INCLUDE_ALL_RESOURCES": "aapt_include_all_resources",
- "LOCAL_DONT_MERGE_MANIFESTS": "dont_merge_manifests",
- "LOCAL_USE_EMBEDDED_NATIVE_LIBS": "use_embedded_native_libs",
- "LOCAL_USE_EMBEDDED_DEX": "use_embedded_dex",
-
- "LOCAL_DEX_PREOPT": "dex_preopt.enabled",
- "LOCAL_DEX_PREOPT_APP_IMAGE": "dex_preopt.app_image",
- "LOCAL_DEX_PREOPT_GENERATE_PROFILE": "dex_preopt.profile_guided",
-
- "LOCAL_PRIVATE_PLATFORM_APIS": "platform_apis",
- "LOCAL_JETIFIER_ENABLED": "jetifier",
-
- "LOCAL_IS_UNIT_TEST": "unit_test",
-
- "LOCAL_ENFORCE_USES_LIBRARIES": "enforce_uses_libs",
- })
- }
不断更新...记录常用但不好理解的
LOCAL_SHARED_LIBRARIES、LOCAL_LDLIBS、LOCAL_LDFLAGS的区别:
LOCAL_SHARED_LIBRARIES 会生成依赖关系,当库不存在时会去编译这个库。
LOCAL_LDLIBS :链接的库不产生依赖关系,一般用于不需要重新编译的库,如库不存在,则会报错找不到。且貌似只能链接那些存在于系统目录下本模块需要连接的库。如果某一个库既有动态库又有静态库,那么在默认情况下是链接的动态库而非静态库。
如:LOCAL_LDLIBS += -lm –lz –lc -lcutils –lutils –llog …
如果你的Android.mk文件中只有这么一行,那么将会采用动态链接。
LOCAL_LDFLAGS:这个编译变量传递给链接器一个一些额外的参数,比如想传递额外的库和库路径给ld,或者传递给ld linker的一些链接参数,-On,-EL{B}(大小端字节序),那么就要加到这个上面,如:
LOCAL_LDFLAGS += -L$(LOCAL_PATH)/lib/ -lHWrecog –EB{EL} –O{n} …
或者直接加上绝对路径库的全名:
LOCAL_LDFLAGS += $(LOCAL_PATH)/lib/libHWrecog.a –EB{EL} –O{n}
如果是非系统的第三方库,貌似只能用LOCAL_LDFLAGS方式,LOCAL_LDLIBS方式不行。
部分参考优秀博客:
Android.mk常用宏定义 - 简书 (jianshu.com)
---------------------
作者:alibli
来源:CSDN
原文:https://blog.csdn.net/weixin_36389889/article/details/128469488
版权声明:本文为作者原创文章,转载请附上博文链接!
内容解析By:CSDN,CNBLOG博客文章一键转载插件
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。