Android常见的预编译(prebuilt)

作者: 风暴小狼 | 来源:发表于2019-11-11 14:32 被阅读0次

android常用的预编译方法(prebuilt)

1.framework引入静态jar包

include $(CLEAR_VARS)
LOCAL_MODULE = xxx
LOCAL_MODULE_CLASS = JAVA_LIBRARIES
LOCAL_MODULE_SUFFIX = .jar
LOCAL_UNINSTALLABLE_MODULE = true
LOCAL_SRC_FILES = lib/xxx.jar
include $(BUILD_PREBUILT)

在需要引入的地方,比如framework.jar
在其对应的Android.mk中添加:
LOCAL_STATIC_JAVA_LIBRARIES += xxx

2.编译共享jar包

include $(CLEAR_VARS)
LOCAL_MODULE := xxx
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := \
    $(call all-java-files-under,$(ANDROID_API_SUBDIRS)) \
    $(call all-Iaidl-files-under,$(ANDROID_API_SUBDIRS))
LOCAL_PROGUARD_ENABLED := disabled
LOCAL_REQUIRED_MODULES := \
    xxx.xml 
LOCAL_AIDL_INCLUDES := $(ANDROID_JAVA_API_DIRS)
include $(BUILD_JAVA_LIBRARY)

####instlal permission####
include $(CLEAR_VARS)
LOCAL_MODULE := xxx.xml
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := ETC
LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)/permissions
LOCAL_SRC_FILES := $(LOCAL_MODULE)
include $(BUILD_PREBUILT)

xxx.xml :
<?xml version="1.0" encoding="utf-8"?>
<permissions>
    <library name="xxx"
        file="/system/framework/xxx.jar"/>
</permissions>

3.编译so库
方法1 : 单独编译

include $(CLEAR_VARS)
LOCAL_MODULE        := mylib
LOCAL_MODULE_CLASS  := SHARED_LIBRARIES
LOCAL_MODULE_SUFFIX := .so
LOCAL_MODULE_TAGS   := optional
LOCAL_MULTILIB      := both
LOCAL_SRC_FILES_32  := mylib_32.so
LOCAL_SRC_FILES_64  := mylib_64.so
LOCAL_MODULE_PATH   :=$(TARGET_OUT)/lib
include $(BUILD_PREBUILT)

方法2 : 轮询编译

LOCAL_PATH := $(call my-dir)

define XIAOMOR_PREBUILT_LIB_template
  include $(CLEAR_VARS)
  LOCAL_MODULE        := $(1)
  LOCAL_MODULE_CLASS  := SHARED_LIBRARIES
  LOCAL_MODULE_TAGS   := optional
  LOCAL_STRIP_MODULE  := false
  LOCAL_SRC_FILES_32  := $(2)
  LOCAL_SRC_FILES_64  := $(3)
  LOCAL_MULTILIB      := both
  include $(BUILD_PREBUILT)
endef

my_libs := \
    libaa \
    libbb \
    libcc \
    libdd \

$(foreach lib,$(my_libs), \
    $(eval $(call XIAOMOR_PREBUILT_LIB_template, $(lib).so ,$(lib)_32.so, $(lib)_64.so )))

4.预编译apk
预置apk至系统,如果apk含有so库的话,也需要提前编译到系统中,解压apk文件,将so提取出来放置某一文件夹中,通过LOCAL_PREBUILT_JNI_LIBS将so编译至system/app/package/lib/arm目录

include $(CLEAR_VARS)
LOCAL_MODULE        := xxx
LOCAL_MODULE_CLASS  := APPS
LOCAL_MODULE_SUFFIX := .apk
LOCAL_MODULE_TAGS   := optional
LOCAL_SRC_FILES     := xxxx.apk
LOCAL_CERTIFICATE   := platform
LOCAL_MULTILIB      := 32
LOCAL_DEX_PREOPT    := false
LOCAL_MODULE_PATH   :=$(TARGET_OUT)/app
LOCAL_PREBUILT_JNI_LIBS:= \
    Hhappy_libs/libffmpeg.so \
    Hhappy_libs/libhpplayvideo.so \
    Hhappy_libs/libhpplayvideo19.so \
    Hhappy_libs/liblbffmpeg.so \
    Hhappy_libs/libusbserver.so
include $(BUILD_PREBUILT)

相关文章

网友评论

    本文标题:Android常见的预编译(prebuilt)

    本文链接:https://www.haomeiwen.com/subject/vqstictx.html