关闭

Android makefile语法

标签: androidmakefile语法
214人阅读 评论(0) 收藏 举报
分类:

Android makefile语法

(1)android.mk文件首先需要制定LOCAL_PATH变量,用于查找源文件。由于一般情况下它和需要编译的源文件在同一目录下,宏函数“my-dir”右编译系统提供的,用于返回当前路径。其形式如:LOCAL_PATH:=$(call my-dri)

该语句de意思是将LOCAL_PATH变量定义成本文件所在的目录路径。

(2)android.mk中可以定义多个编译模块,每个编译模块都是以include$(CLEAR_VARS)开始以include$(BUILD_XXX)结束。CLEAR_VARS由编译系统提供,制定让GNU MAKEFILE为你清除除LOCAL_PATH以外的所有LOCAL_XXX变量,如LOCAL_MODULE,LOCAL_SRC_FILES,LOCAL_SHARED_LIBRARIES等。

Include$(BUILD_STATIC_LIBRARY)表示编译成静态库

Include$(BUILD_SHARED_LIBRARY)表示编译成动态库

Include$(BUILD_EXECUTALBE_LIBRARY)表示编译成可执行库

(3)LOCAL_MODULE_TAGS:=optional

(4)LOCAL_MODULE_TAGS:=user eng tests optional

(5)User:指该模块只在user版本下才编译

(6)Eng :指该模块只在eng版本下才编译

(7)Tests :指该模块只在tests版本下才编译

(8)Optional:指该模块只在optional版本下才编译

(9)LOCAL_MODULE:=hellowork  该语句的变量必须定义,以标识你在android.mk文件中描述的每个模块。名称必须是唯一的,而且不包含任何空格。注意编译系统会自动产生合适的前缀和后缀,换句话说,一个被命名为‘foo’的共享库模块,将会生成‘libfoo.so’文件。

(10)LOCAL_SRC_FILES:=helloworld.c  该语句变量必须包含将要编译打包进模块中的CC++源码文件。

(11)LOCAL_SR_VERSION:=current

(12)LCOAL_PACKAGE_NAME:=APK包的名称

(13)LCOAL_JAVA_LIBRARIES:=platform core ext以来的共享jar

(14)LOCAL_STATIC_JAVA_LIBRARIES:=以来的静态jar包,jar包是有Include$(BUILD_STATIC_JAVA_LIBRARY生成的)

(15)LOCAL_CERTIFICATE:签名认证

(18)  编译一个应用程序(APK)
  LOCAL_PATH := $(call my-dir)
  include $(CLEAR_VARS)
   
  # Build all java files in the java subdirectory
  LOCAL_SRC_FILES := $(call all-subdir-java-files)
   
  # Name of the APK to build
  LOCAL_PACKAGE_NAME := LocalPackage
   
  # Tell it to build an APK
  include $(BUILD_PACKAGE)

(19)  编译静态库

#清除java环境变量

include$(CLEAR_VARS)

LOCAL_MODULE_TAGS:= user

#添加aidl文件

LOCAL_SRC_FILES+= src/net/sunniwell/download/aidl/IDownload.aidl

# SDK 版本                

LOCAL_SDK_VERSION:= current

#jar包的名字

LOCAL_MODULE:=DownLoadServerapi               

#编译 DownLoadServerapi  jar包

include $(BUILD_STATIC_JAVA_LIBRARY)

(20) 编译一个依赖于静态Java(static.jar)的应用程序
  LOCAL_PATH := $(call my-dir)
  include $(CLEAR_VARS)
   
  # List of static libraries to include in the package
  LOCAL_STATIC_JAVA_LIBRARIES := DownLoadServerapi 第三方jar包
   
  # Build all java files in the java subdirectory
  LOCAL_SRC_FILES := $(call all-subdir-java-files)
   
  # Name of the APK to build
  LOCAL_PACKAGE_NAME := LocalPackage
   
  # Tell it to build an APK
  include $(BUILD_PACKAGE)

(21) 编译一个需要用平台的key签名的应用程序
  LOCAL_PATH := $(call my-dir)
  include $(CLEAR_VARS)
   
  # Build all java files in the java subdirectory
  LOCAL_SRC_FILES := $(call all-subdir-java-files)
   
  # Name of the APK to build
  LOCAL_PACKAGE_NAME := LocalPackage
   
  LOCAL_CERTIFICATE := platform
   
  # Tell it to build an APK
  include $(BUILD_PACKAGE)

(22) 添加一个静态JAVA
  LOCAL_PATH := $(call my-dir)
  include $(CLEAR_VARS)
   
  # Build all java files in the java subdirectory
  LOCAL_SRC_FILES := $(call all-subdir-java-files)
   
  # Any libraries that this library depends on
  LOCAL_JAVA_LIBRARIES := android.test.runner
   
  # The name of the jar file to create
  LOCAL_MODULE := sample
   
  # Build a static jar file.
  include $(BUILD_STATIC_JAVA_LIBRARY)

(23) 引用第三方JAR包方式

#引入第三方包

include $(CLEAR_VARS) 

 

表示在当前目录下的lib/iptv.jar进行预处理到android jar包的目录中去

 

#LOCAL_PREBUILT_JAVA_LIBRARIES := libiptv:lib/iptv.jar

LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := \

libiptv:lib/iptv.jar 

 

include $(BUILD_MULTI_PREBUILT)

 

需要在编译apk 中进行、并添加

LOCAL_STATIC_JAVA_LIBRARIES := libiptv

(16)

 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:22808次
    • 积分:529
    • 等级:
    • 排名:千里之外
    • 原创:17篇
    • 转载:76篇
    • 译文:3篇
    • 评论:1条
    最新评论