Android 编译重要参数 LOCAL_MODULE_TAGS

本文详细解析了在移植TSlib库至Android系统时遇到的问题,特别是库和测试工具输出路径未按预期进入指定目录的情况。通过调整Android.mk文件中的LOCAL_MODULE_TAGS变量,解决了输出路径问题。此外,文章还讨论了LOCAL_MODULE_TAGS变量与TARGET_BUILD_VARIANT变量的关系,以及不同设置对模块输出位置的影响。
最近移植tslib库到android系统,发现编译好的库和测试工具竟然没有输入到out/target/product/Ok6410/system/lib 和 out/target/product/Ok6410/system/bin下面,感觉很奇怪,于是下定决心看一下,到底输入到了哪里。

过程如下:

   tslib的源代码放到了android2.3 源代码下 vendor 目录 (android2.3中自己添加,如何设置自己的vendor 我的博客中有说明)forlinx/OK6410/的下面. tslib目录下面的 Android.mk写好以后,重新make clean 整个android源码,再次make 编译通过,奇怪的是输出目录 out/target/product/Ok6410/system/bin 下面竟然没有tslib相关的工具,而是放在了out/target/product/OK6410/symbols/system/bin 下面,在做打包文件时,由于没有把symbols文件夹放到文件系统里面,所以校准功能不能实现。(事实上提取文件系统过程中也不应该把symbols文件夹考虑在内)。

 

 最后查找原因 ,是因为tslib文件下的Android.mk文件里面,LOCAL_MODULE_TAGS变量设置的有问题。

LOCAL_MODULE_TAGS :=optional

把这项改为

LOCAL_MODULE_TAGS :=eng即可

 

原因是LOCAL_MODULE_TAGS 变量跟TARGET_BUILD_VARIANT 变量息息相关。 android系统编译时如果不指定

TARGET_BUILD_VARIANT 变量的值,默认 TARGET_BUILD_VARIANT=eng ,这一项指定 编译android时形成的版本风格,一般发布时使用这个值,当然还有user,debuguser等风格值,具体看一下这个链接http://android.git.kernel.org/?p=platform/build.git;a=blob_plain;f=core/build-system.html;h=43bae03b6b7b9cba678b86d2faf424fa565497bf;hb=HEAD,如果打不开,翻个墙就可以。

这样设置好以后,重新编译,输出目录out/target/product/Ok6410/system/bin ,out/target/product/Ok6410/system/lib里面就有tslib 相关的库和测试程序了。

  所以,如果自己需要加额外的模块,或者应用程序,一定要注意Android.mk里面的这个变量,当然了,如果你指定了LOCAL_MODULE_TAGS :=optional,也能编译出来,但是存放的输入路径就不是一般的

out/target/product/Ok6410/system/目录了,而是out/target/product/OK6410/symbols/system/目录。

后来自己在android源代码的 external目录下面放了一个模块,指定该模块的编译风格为LOCAL_MODULE_TAGS :=optional,重新编译,通过以后,竟然直接输出到了out/target/product/Ok6410/system/ 目录,很是惊讶,个人认为还跟模块存放的目录有关.所以无论模块在哪个文件夹下面,最好指定的值跟TARGET_BUILD_VARIANT 相关,如果没指定TARGET_BUILD_VARIANT ,系统会默认设置TARGET_BUILD_VARIANT =eng,你也就指定LOCAL_MODULE_TAGS :=eng 

目前自己遇到的 vendor目录,hardware目录下面的模块输出路径跟LOCAL_MODULE_TAGS 有很大的关系

LOCAL_MODULE_TAGS :=optional >> out/target/product/OK6410/symbols/system/

LOCAL_MODULE_TAGS :=eng    >> out/target/product/Ok6410/system/

 

当然前提是TARGET_BUILD_VARIANT=eng .

 

下面是网友遇到的类似问题:

"Set LOCAL_MODULE_TAGS to any number of whitespace-separated tags.

This variable controls what build flavors the package gets included
in. For example:

    * user: include this in user/userdebug builds
    * eng: include this in eng builds
    * tests: the target is a testing target and makes it available for tests
    * optional: don't include this"

Are these the same as "variants" and if so, which name would affect
the build and how? I've noticed that everything mentioned in a
product's makefile will always get built. But what gets in the final
system.img not always the same as what gets built.
http://groups.google.com.tw/group/android-platform/browse_thread/thread/a4f70254a2ceb622 
http://android.git.kernel.org/?p=platform/build.git;a=blob_plain;f=core/build-system.html;h=43bae03b6b7b9cba678b86d2faf424fa565497bf;hb=HEAD

 

 以上是自己在移植android2.3过程中发现的一个问题,如果您也遇到了,并且认为我的解释存在问题,请指出,以免给大家带来误解。

 

 

 原文地址 http://blog.youkuaiyun.com/yimiyangguang1314/article/details/6312215

LOCAL_MODULE_TAGS :=optional 的模块会被编译,但不会安装到image里面,要想让是optional的模块安装的话,需要将模块名加入到相关product的PRODUCT_PACKAGES里面。

 

此参数会影响到库生成后的存放位置,影响生成位置的应该是相关平台下的变量PRODUCT_PACKAGES

 

http://blog.youkuaiyun.com/evilcode/article/details/6459299

LOCAL_MODULE_TAGS :=user eng tests optional

user: 指该模块只在user版本下才编译

eng: 指该模块只在eng版本下才编译

tests: 指该模块只在tests版本下才编译

optional:指该模块在所有版本下都编译

 

eng This is the default flavor. A plain "make" is the same as "make eng". droid is an alias for eng. 
  * Installs modules tagged with: eng, debug, user, and/or development. 
  * Installs non-APK modules that have no tags specified. 
  * Installs APKs according to the product definition files, in addition to tagged APKs. 
  * ro.secure=0 
  * ro.debuggable=1 
  * ro.kernel.android.checkjni=1 
  * adb is enabled by default.   

user "make user"     This is the flavor intended to be the final release bits. 
  * Installs modules tagged with user. 
  * Installs non-APK modules that have no tags specified. 
  * Installs APKs according to the product definition files; tags are ignored for APK modules. 
  * ro.secure=1 
  * ro.debuggable=0 
  * adb is disabled by default.   

userdebug "make userdebug"     The same as user, except: 
  * Also installs modules tagged with debug. 
  * ro.debuggable=1 
  * adb is enabled by default.

 

Build flavors/types

When building for a particular product, it's often useful to have minor variations on what is ultimately the final release build. These are the currently-defined "flavors" or "types" (we need to settle on a real name for these).

engThis is the default flavor. A plain "make " is the same as "make eng ". droid is an alias for eng .
  • Installs modules tagged with: eng , debug , user , and/or development .
  • Installs non-APK modules that have no tags specified.
  • Installs APKs according to the product definition files, in addition to tagged APKs.
  • ro.secure=0
  • ro.debuggable=1
  • ro.kernel.android.checkjni=1
  • adb is enabled by default.
user"make user "

This is the flavor intended to be the final release bits.

  • Installs modules tagged with user .
  • Installs non-APK modules that have no tags specified.
  • Installs APKs according to the product definition files; tags are ignored for APK modules.
  • ro.secure=1
  • ro.debuggable=0
  • adb is disabled by default.
userdebug"make userdebug "

The same as user , except:

  • Also installs modules tagged with debug .
  • ro.debuggable=1
  • adb is enabled by default.

If you build one flavor and then want to build another, you should run "make installclean " between the two makes to guarantee that you don't pick up files installed by the previous flavor. "make clean " will also suffice, but it takes a lot longer.

 

 

### 关于 `LOCAL_MODULE_TAGS` 的宏定义 在 Android.mk 文件中,`LOCAL_MODULE_TAGS` 是一个常用的变量,用于指定模块的标签。这些标签决定了该模块是否会被包含到特定类型的构建中(例如用户版本、调试版本等)。具体来说: - **`LOCAL_MODULE_TAGS` 的作用** 这个变量通常用来标记模块属于哪个类别,常见的取值包括 `eng`、`debug` 和 `user` 等[^1]。不同的标签会影响模块最终被安装到哪种类型的镜像中。 - **宏定义的位置** 在 Android 构建系统中,`LOCAL_MODULE_TAGS` 并不是一个严格意义上的 C/C++ 宏定义,而是 Makefile 中的一个变量。它的默认行为由构建系统的核心脚本决定,具体的实现可以在以下路径找到: - `$ANDROID_BUILD_TOP/build/core/base_rules.mk` 此文件是 Android 构建系统的一部分,其中包含了关于如何处理 `LOCAL_MODULE_TAGS` 的逻辑[^4]。 以下是部分代码片段展示其核心逻辑: ```makefile ifeq (,$(strip $(LOCAL_MODULE_TAGS))) # 如果未设置 LOCAL_MODULE_TAGS,则使用默认值 eng LOCAL_MODULE_TAGS := eng endif ``` 这段代码表明,如果没有显式设置 `LOCAL_MODULE_TAGS`,它会自动被赋予默认值 `eng`。 - **常见用法示例** 假设我们需要创建一个库并将其标记为仅适用于开发环境(即 `eng` 或 `debug`),可以这样写: ```makefile include $(CLEAR_VARS) LOCAL_MODULE := my_module LOCAL_SRC_FILES := my_source.cpp LOCAL_MODULE_TAGS := debug include $(BUILD_SHARED_LIBRARY) ``` 通过上述配置,只有当构建类型为 `eng` 或 `debug` 时,这个模块才会被编译和打包[^5]。 --- ### 总结 `LOCAL_MODULE_TAGS` 不是一个传统意义的宏定义,而是在 Android.mk 文件中使用的变量,默认行为由 `$ANDROID_BUILD_TOP/build/core/base_rules.mk` 控制。开发者可以通过设置此变量来控制模块的适用范围。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值