1. Android.mk编译apk
LOCAL_PATH := $(call my-dir) //当前目录
src_dir = app/src/main/java
res_dir = app/src/main/res
aidl_dir = app/src/main/aidl
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_PACKAGE_NAME := AppName //生成AppName.apk
LOCAL_SRC_FILES := $(call all-java-files-under, $(src_dir)) \
$(call all-Iaidl-files-under, $(aidl_dir))
LOCAL_AIDL_INCLUDES := \
$(call all-Iaidl-files-under, $(aidl_dir)) \
$(LOCAL_PATH)/$(aidl_dir)
LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/$(res_dir)
LOCAL_MANIFEST_FILE := src/main/AndroidManifest.xml
LOCAL_PRIVATE_PLATFORM_APIS := true //可以使用私有平台API
LOCAL_SYSTEM_EXT_MODULE := true //系统扩展模块
LOCAL_CERTIFICATE := platform //使用平台证书签名APK
LOCAL_STATIC_JAVA_LIBRARIES := \
androidx.appcompat_appcompat \
androidx.annotation_annotation \
include $(BUILD_PACKAGE)
2. Android.bp 编译apk
android_app {
name: "AppName", //生成AppName.apk
srcs: [
" app/src/main/java/**/*.java",
" app/src/main/aidl/**/*.aidl",
],
resource_dirs: [
"app/src/main/res",
],
manifest: "app/src/main/AndroidManifest.xml",
platform_apis: true,
certificate: "platform",
static_libs: [
"androidx-constraintlayout_constraintlayout",
"androidx.appcompat_appcompat",
"androidx.recyclerview_recyclerview",
],
}
3. Android.mk集成现成apk到系统
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := AppName
LOCAL_SRC_FILES := $(LOCAL_MODULE).apk //集成当前目录下AppName.apk
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_CERTIFICATE := platform
LOCAL_SYSTEM_EXT_MODULE := true
LOCAL_PREBUILT_JNI_LIBS:= \
lib/arm64-v8a/libxxx.so //引用so
include $(BUILD_PREBUILT)
4. Android.mk编译jar
LOCAL_PATH := $(call my-dir)
src_dir = app/src/main/java
include $(CLEAR_VARS)
LOCAL_MODULE := mylibrary
LOCAL_SRC_FILES := $(wildcard $(src_dir)/*.java)
LOCAL_JAVA_FILES := $(LOCAL_SRC_FILES)
LOCAL_JAVA_FLAGS := -source 1.8 -target 1.8 //使用java1.8编译
LOCAL_MODULE_CLASS := classes
include $(BUILD_JAVA_LIBRARY)
5. Android.bp编译jar
java_library {
name: "com.android.xxx.api", // jar名:com.android.xxx.api.jar
installable: true,
platform_apis: true,
srcs: [
"java/**/*.java",
],
static_libs: ["other_jar_name"],
}
6. Android.bp将java源文件编译进framework
filegroup {
name: "vendor-framework-sources",
srcs: [
"java/**/*.java",
],
visibility: [
"//frameworks/base",
],
}
filegroup {
name: vendor-framework-sources-aidl",
srcs: [
"aidl/**/*.aidl", // **/*为包名加aidl文件名
],
visibility: [
"//frameworks/base",
],
path: "aidl", // path取包名的父目录
}
添加filegroup到framework/base/Android.bp中的srcs中
filegroup {
name: "framework-non-updatable-sources",
srcs: [
// Java/AIDL sources under frameworks/base
":framework-annotations",
":framework-blobstore-sources",
":framework-core-sources",
......
// vendor
":vendor-framework-sources",
":vendor-framework-sources-aidl",
],
}
编译命令:
source build/envsetup.sh
lunch aosp_arm64-eng
make framework-minus-apex
make services
7. Android.bp引用jar包
java_import {
name: "my_java_jar",
jars: ["libs/my_java.jar"],
}
static_libs: [
"androidx-constraintlayout_constraintlayout",
"my_java_jar",
]
8. Android.mk编译so
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := mysoname
LOCAL_SRC_FILES += aaa.cpp \
bbb.cpp
LOCAL_SHARED_LIBRARIES += libutils libcutils liblog
LOCAL_C_INCLUDES += $(LOCAL_PATH)/include
LOCAL_VENDOR_MODULE := true
include $(BUILD_SHARED_LIBRARY)
9.Android.bp编译so
cc_library_shared {
name: "xxx.so.name@1.0-impl",
defaults: [
"xxx.so.name.xxx_defaults", // 包含其他模块
],
relative_install_path: "hw",
vendor: true,
srcs: [
"aaa.cpp",
"bbb.cpp",
],
shared_libs: [
"libcutils",
"liblog",
],
}
cc_defaults {
name: "xxx.so.name.xxx_defaults",
srcs: [
"ccc.cpp",
],
shared_libs: [
"liblog",
],
}
10.android.mk编译现成so到系统
include $(CLEAR_VARS)
LOCAL_MODULE := libxxx //生成的so名 libxxx.so
LOCAL_MODULE_TAGS := optional
LOCAL_MULTILIB := both
LOCAL_PROPRIETARY_MODULE := true
LOCAL_MODULE_RELATIVE_PATH := hw //生成目录 vendor/lib64/hw
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_SHARED_LIBRARIES := libutils liblog
LOCAL_MODULE_SUFFIX := .so
//当前文件下so所在目录
LOCAL_SRC_FILES_32 := src_so/armeabi-v7a/libxxx.so
LOCAL_SRC_FILES_64 := src_so/arm64-v8a/libxxx.so
include $(BUILD_PREBUILT_SHARED_LIBRARY)