文件夹列表
CMkDemo/Android.mk
CMkDemo/cpp/SerialPort.c
CMkDemo/cpp/SerialPort.h
Android.mk 内容如下
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
# All of the source files that we will compile.
LOCAL_SRC_FILES:= \
cpp/SerialPort.c
# All of the shared libraries we link against.
LOCAL_SHARED_LIBRARIES := \
libutils liblog
LOCAL_HEADER_LIBRARIES += jni_headers
# No static libraries.
LOCAL_STATIC_LIBRARIES :=
# Also need the JNI headers.
#LOCAL_C_INCLUDES += \
# $(JNI_H_INCLUDE)
# This is the target being built.
LOCAL_MODULE:= lib_cmkdemo
LOCAL_SYSTEM_EXT_MODULE := true
LOCAL_MULTILIB := 64
# No special compiler flags.
LOCAL_CFLAGS +=
include $(BUILD_SHARED_LIBRARY)
最终生成 ./out/target/product/
如果去掉 LOCAL_MULTILIB := 64 ,会生成
./out/target/product/
./out/target/product/
文件夹列表
CBpDemo/Android.bp
CBpDemo/cpp/SerialPort.c
CBpDemo/cpp/SerialPort.h
Android.bp 内容如下
cc_library_shared {
name: "lib_cbpdemo",
system_ext_specific: true,
compile_multilib: "64",
srcs: [
"cpp/*.c",
"cpp/*.cpp",
],
include_dirs: [
],
header_libs: [
"jni_headers",
],
shared_libs: [
"liblog",
]
}
error: missing separator.
;场景: 需要把C文件集成到 Test.apk 的源码里,编译生成的 Test.apk 里有对应的 lib_xx.so ,
Test.apk 的 Android.mk ,
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_PACKAGE_NAME := Test
LOCAL_MODULE_TAGS := optional
LOCAL_CERTIFICATE := platform
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_DEX_PREOPT := false
LOCAL_SYSTEM_EXT_MODULE := true
LOCAL_PROGUARD_FLAG_FILES := proguard.flags
LOCAL_PRIVATE_PLATFORM_APIS := true
LOCAL_PRIVILEGED_MODULE := true
LOCAL_JAVA_LIBRARIES := \
xxx-framework \
LOCAL_STATIC_JAVA_LIBRARIES += \
SettingsLib
include $(BUILD_PACKAGE)
把 C 文件放到 src/com/test/cpp/ 下,添加 patch 如下,
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_PACKAGE_NAME := Test
LOCAL_MODULE_TAGS := optional
LOCAL_CERTIFICATE := platform
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_DEX_PREOPT := false
LOCAL_SYSTEM_EXT_MODULE := true
LOCAL_PROGUARD_FLAG_FILES := proguard.flags
LOCAL_PRIVATE_PLATFORM_APIS := true
LOCAL_PRIVILEGED_MODULE := true
LOCAL_JAVA_LIBRARIES := \
xxx-framework \
LOCAL_STATIC_JAVA_LIBRARIES += \
SettingsLib
############### patch begin ################
LOCAL_JNI_SHARED_LIBRARIES:= lib_cmkdemo
############### patch end ################
include $(BUILD_PACKAGE)
############### patch begin ################
#LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
# This is the target being built.
LOCAL_MODULE:= lib_cmkdemo
LOCAL_SYSTEM_EXT_MODULE := true
# All of the source files that we will compile.
LOCAL_SRC_FILES:= \
src/com/test/cpp/SerialPort.c
# Also need the JNI headers.
LOCAL_C_INCLUDES += \
$(JNI_H_INCLUDE)
# All of the shared libraries we link against.
LOCAL_SHARED_LIBRARIES := \
libutils liblog
# No static libraries.
LOCAL_STATIC_LIBRARIES :=
#LOCAL_MULTILIB := 64
# No special compiler flags.
LOCAL_CFLAGS +=
include $(BUILD_SHARED_LIBRARY)
############### patch end ################
Test.apk 的 Android.bp ,
android_app {
name: "Test",
certificate: "platform",
srcs: ["src/**/*.java"],
dex_preopt: {
enabled: false,
},
system_ext_specific: true,
optimize: {
proguard_flags_files: ["proguard.flags"],
},
platform_apis: true,
privileged: true,
libs: [
"xxx-framework",
],
static_libs: ["SettingsLib"],
}
把 C 文件放到 src/com/test/cpp/ 下,添加 patch 如下,
android_app {
name: "Test",
certificate: "platform",
srcs: ["src/**/*.java"],
dex_preopt: {
enabled: false,
},
system_ext_specific: true,
optimize: {
proguard_flags_files: ["proguard.flags"],
},
platform_apis: true,
privileged: true,
libs: [
"xxx-framework",
],
static_libs: ["SettingsLib"],
//############## patch begin ################
jni_libs: ["lib_cbpdemo"],
//############## patch end ################
}
//############## patch begin ################
//LOCAL_PATH:= $(call my-dir)
cc_library_shared {
// This is the target being built.
name: "lib_cbpdemo",
system_ext_specific: true,
// All of the source files that we will compile.
srcs: ["src/com/test/cpp/SerialPort.c"],
// Also need the JNI headers.
include_dirs: JNI_H_INCLUDE,
// All of the shared libraries we link against.
shared_libs: [
"libutils",
"liblog",
],
// No static libraries.
static_libs: [],
//LOCAL_MULTILIB := 64
// No special compiler flags.
cflags: [],
}
//############## patch end ################