Android系统常用Makefile技巧

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/tankai19880619/article/details/41981719

一、重用Android.mk写法

1.源码编译一个so库libChannelSwitchDetector.so

LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)

LOCAL_C_INCLUDES += $(LOCAL_PATH)/../tinyalsa-mstar/include/

LOCAL_SRC_FILES:= AudioDetector.c ChannelSwitchDetector_mstar.c

LOCAL_SHARED_LIBRARIES:= libtinyalsa libcutils

LOCAL_LDLIBS:=-llog

LOCAL_MODULE := libChannelSwitchDetector

LOCAL_MODULE_TAGS := optional

include $(BUILD_SHARED_LIBRARY)

include $(call all-makefiles-under,$(LOCAL_PATH))

2.源码编译一个可执行文件testinput

LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)

LOCAL_SRC_FILES:= \
        testinput.c

LOCAL_SHARED_LIBRARIES := \
        libutils

LOCAL_MODULE:= testinput

LOCAL_MODULE_TAGS := optional

include $(BUILD_EXECUTABLE)

3.源码编译一个apk,Demo.apk

LOCAL_PATH:= $(call my-dir)

LOCAL_STATIC_JAVA_LIBRARIES := \
                android-support-v4 \
                gson-2.2.4 \
                jiepingmu \
                sqlitecommon 

LOCAL_JAVA_LIBRARIES := com.***.tvmanager

LOCAL_SRC_FILES := $(call all-java-files-under, src) \
                   src/com/***/fingerprint/lib/IChannelSwitchListener.aidl 

#LOCAL_JNI_SHARED_LIBRARIES 将so打包进apk

LOCAL_PACKAGE_NAME := Demo

#LOCAL_PROGUARD_FLAG_FILES := proguard.flags

LOCAL_PROGUARD_ENABLED := disabled

LOCAL_MODULE_TAGS := optional

LOCAL_CERTIFICATE := platform

LOCAL_DEX_PREOPT := false

include $(BUILD_PACKAGE)

include $(call all-makefiles-under,$(LOCAL_PATH))

4.直接将编译ok文件拷贝到out目录

LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := libopencv_java.so

LOCAL_MODULE_CLASS := ETC

LOCAL_MODULE_PATH := $(TARGET_OUT)/lib

LOCAL_SRC_FILES := libs/armeabi-v7a/$(LOCAL_MODULE)

include $(BUILD_PREBUILT)

include $(call all-makefiles-under,$(LOCAL_PATH))

5.三方库放置编译环境,而不生成到out目录

include $(CLEAR_VARS)

LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := \
                android-support-v4:libs/android-support-v4.jar \
                gson-2.2.4:libs/gson-2.2.4.jar \
                jiepingmu:libs/jiepingmu.jar \
                sqlitecommon:libs/sqlitecommon.jar

LOCAL_PREBUILT_LIBS := jni/libs/armeabi-v7a/libopencv_java.so

include $(BUILD_MULTI_PREBUILT)

二、注意

1.LOCAL_PROGUARD_ENABLED := disabled

在编译APK,且该APK中需要JNI调用时;需要该参数阻止PROGRARD对源码的优化编译。

2.LOCAL_MODULE_TAGS := optional

加上该参数指不敢在eng、user或userdebug环境下,该模块都会被编译。

3.LOCAL_CERTIFICATE := platform

apk获取系统签名。

4.LOCAL_CFLAGS += -Wno-error=return-type -Wno-error=non-virtual-dtor -Wno-error=address -Wno-error=sequence-point

gcc编译器忽略警告。相似的还有LOCAL_CPPFLAGS、LOCAL_LDFLAGS。

LOCAL_LDLIBS





阅读更多
博主设置当前文章不允许评论。

博主推荐

换一批

没有更多推荐了,返回首页