These are thevariables that you'll commonly see in Android.mk files, listedalphabetically.
But first, a note onvariable naming:
include$(CLEAR_VARS)
line, so you can rely on thembeing empty after including that file. Most of the variables you'lluse in most modules are LOCAL_ variables.In Android.mk files that include$(BUILD_PACKAGE)
set this to the set offiles you want built into your app. Usually:
LOCAL_ASSET_FILES += $(call find-subdir-assets)
This will probably change when we switch to ant for the apps' buildsystem.
If you want to use a different C compiler for this module, setLOCAL_CC to the path to the compiler. If LOCAL_CC is blank, theappropriate default compiler is used.
If you want to use a different C++ compiler for this module, setLOCAL_CXX to the path to the compiler. If LOCAL_CXX is blank, theappropriate default compiler is used.
If you have additional flags to pass into the C or C++ compiler,add them here. For example:
If you have additional flags to passinto
LOCAL_CPPFLAGS += -ffriend-injection
LOCAL_CPPFLAGS
is guaranteed to beafter LOCAL_CFLAGS
onthe compile line, so you can use it to override flags listedin LOCAL_CFLAGS
.
If your C++ files end in something other than".cpp
", you can specify the customextension here. For example:
LOCAL_CPP_EXTENSION := .cc
Note that all C++ files for a given module must have the sameextension; it is not currently possible to mix differentextensions.
Normally, the compile line for C and C++ files includes globalinclude paths and global cflags.IfLOCAL_NO_DEFAULT_COMPILER_FLAGS
isnon-empty, none of the default includes or flags will be used whencompiling C and C++ files in thismodule. LOCAL_C_INCLUDES
,LOCAL_CFLAGS
,andLOCAL_CPPFLAGS
will still be usedin this case, as willany DEBUG_CFLAGS
thatare defined for the module.
This will be going away.
The set of files to copy to the install include tree. You must alsosupply LOCAL_COPY_HEADERS_TO
.
This is going away because copying headers messes up the errormessages, and may lead to people editing those headers instead ofthe correct ones. It also makes it easier to do bad layering in thesystem, which we want to avoid. We also aren't doing a C/C++ SDK,so there is no ultimate requirement to copy any headers.
This will be going away.
The directory within "include" to copy the headers listedin LOCAL_COPY_HEADERS
to.
This is going away because copying headers messes up the errormessages, and may lead to people editing those headers instead ofthe correct ones. It also makes it easier to do bad layering in thesystem, which we want to avoid. We also aren't doing a C/C++ SDK,so there is no ultimate requirement to copy any headers.
Additional directories to instruct the C/C++ compilers to look forheader files in. These paths are rooted at the top of the tree.Use LOCAL_PATH
ifyou have subdirectories of your own that you want in the includepaths. For example:
LOCAL_C_INCLUDES += extlibs/zlib-1.2.3
LOCAL_C_INCLUDES += $(LOCAL_PATH)/src
You should not add subdirectories of includeto LOCAL_C_INCLUDES
,instead you should reference those files inthe #include
statementwith their subdirectories. For example:
#include
not #include
There are some components that are doing this wrong, and should becleaned up.
Set LOCAL_MODULE_TAGS
toany number of whitespace-separated tags. If the tag list is emptyor contains droid
,the module will get installed as part ofa make droid
.Otherwise, it will only get installed byrunning make
orwith the makeall
pseudotarget.
Set LOCAL_REQUIRED_MODULES
toany number of whitespace-separated module names, like "libblah" or"Email". If this module is installed, all of the modules that itrequires will be installed as well. This can be used to, e.g.,ensure that necessary shared libraries or providers are installedwhen a given app is installed.
If your executable should be linked statically,set LOCAL_FORCE_STATIC_EXECUTABLE:=true
.There is a very short list of libraries that we have in static form(currently only libc). This is really only used for executables in/sbin on the root filesystem.
Files that you addto LOCAL_GENERATED_SOURCES
willbe automatically generated and then linked in when your module isbuilt. See the
When linking Java apps andlibraries, LOCAL_JAVA_LIBRARIES
specifieswhich sets of java classes to include. Currently there are two ofthese: core
and framework
.In most cases, it will look like this:
LOCAL_JAVA_LIBRARIES := core framework
Note thatsetting LOCAL_JAVA_LIBRARIES
isnot necessary (and is not allowed) when building an APK with"include $(BUILD_PACKAGE)
". Theappropriate libraries will be included automatically.
You can pass additional flags to the linker bysetting LOCAL_LDFLAGS
.Keep in mind that the order of parameters is very important to ld,so test whatever you do on all platforms.
LOCAL_LDLIBS
allows you to specifyadditional libraries that are not part of the build for yourexecutable or library. Specify the libraries you want in -lxxxformat; they're passed directly to the link line. However, keep inmind that there will be no dependency generated for theselibraries. It's most useful in simulator builds where you want touse a library preinstalled on the host. The linker (ld) is aparticularly fussy beast, so it's sometimes necessary to pass otherflags here if you're doing something sneaky. Some examples:
LOCAL_LDLIBS += -lcurses -lpthread
LOCAL_LDLIBS += -Wl,-z,origin
If your package doesn't have a manifest (AndroidManifest.xml), thensetLOCAL_NO_MANIFEST:=true
. Thecommon resources package does this.
LOCAL_PACKAGE_NAME
is the name of anapp. For example, Dialer, Contacts, etc. This will probably changeor go away when we switch to an ant-based build system for theapps.
The directory your Android.mk file is in. You can set it by puttingthe following as the first line in your Android.mk:
LOCAL_PATH := $(my-dir)
The my-dir
macrouses the MAKEFILE_LIST
variable,so you must call it before you include any other makefiles. Also,consider that any subdirectories you inlcude might resetLOCAL_PATH, so do your own stuff before you include them. This alsomeans that if you try to writeseveralinclude
lines thatreference LOCAL_PATH
,it won't work, because those included makefiles might resetLOCAL_PATH.
For host executables, you can specify a command to run on themodule after it's been linked. You might have to go through somecontortions to get variables right because of early or latevariable evaluation:
module := $(HOST_OUT_EXECUTABLES)/$(LOCAL_MODULE)
LOCAL_POST_PROCESS_COMMAND := /Developer/Tools/Rez -d __DARWIN__ -t APPL\
-d __WXMAC__ -o $(module) Carbon.r
When including $(BUILD_PREBUILT) or $(BUILD_HOST_PREBUILT), setthese to executables that you want copied. They're locatedautomatically into the right bin directory.
When including $(BUILD_PREBUILT) or $(BUILD_HOST_PREBUILT), setthese to libraries that you want copied. They're locatedautomatically into the right lib directory.
These are the libraries you directly link against. You don't needto pass transitively included libraries. Specify the name withoutthe suffix:
LOCAL_SHARED_LIBRARIES := \
libutils \
libui \
libaudio \
libexpat \
libsgl
The build system looksat LOCAL_SRC_FILES
toknow what source files to compile -- .cpp .c .y .l .java. For lexand yacc files, it knows how to correctly do the intermediate .hand .c/.cpp files automatically. If the files are in a subdirectoryof the one containing the Android.mk, prefix them with thedirectory name:
LOCAL_SRC_FILES := \
file1.cpp \
dir/file2.cpp
These are the static libraries that you want to include in yourmodule. Mostly, we use shared libraries, but there are a couple ofplaces, like executables in sbin and host executables where we usestatic libraries instead.
LOCAL_STATIC_LIBRARIES := \
libutils \
libtinyxml
LOCAL_MODULE
is the name of what'ssupposed to be generated from your Android.mk. For exmample, forlibkjs,the LOCAL_MODULE
is"libkjs" (the build system adds the appropriate suffix -- .so.dylib .dll). For app modules,use LOCAL_PACKAGE_NAME
insteadof LOCAL_MODULE
. We're planning onswitching to ant for the apps, so this might become moot.
Instructs the build system to put the module somewhere other thanwhat's normal for its type. If you override this, make sure youalsoset LOCAL_UNSTRIPPED_PATH
ifit's an executable or a shared library so the unstripped binary hassomewhere to go. An error will occur if you forget to.
See
Instructs the build system to put the unstripped version of themodule somewhere other than what's normal for its type. Usually,you override this because youoverrode LOCAL_MODULE_PATH
for anexecutable or a shared library. If youoverrode LOCAL_MODULE_PATH
,but notLOCAL_UNSTRIPPED_PATH
, anerror will occur.
See
These are the static libraries that you want to include in yourmodule without allowing the linker to remove dead code from them.This is mostly useful if you want to add a static library to ashared library and have the static library's content exposed fromthe shared library.
LOCAL_WHOLE_STATIC_LIBRARIES := \
libsqlite3_android
Any flags to pass to invocations of yacc for your module. A knownlimitation here is that the flags will be the same for allinvocations of YACC for your module. This can be fixed. If you everneed it to be, just ask.
LOCAL_YACCFLAGS := -p kjsyy
You should never have to touch anything in the config directoryunless you're adding a new platform, new tools, or adding newfeatures to the build system. In general, please consult with thebuild system owner(s) (android-build-team
In order to make easier for people when the build system changes,when it is necessary to make changes to buildspec.mk or to rerunthe environment setup scripts, they contain a version number in thevariable BUILD_ENV_SEQUENCE_NUMBER. If this variable does not matchwhat the build system expects, it fails printing an error messageexplaining what happened. If you make a change that requires anupdate, you need to update two places so this message will beprinted.
The scripts automatically get the value from the build system, sothey will trigger the warning as well.
You probably shouldn't use these variables. Pleaseconsult
If your module needs to depend on anything else that isn't actuallybuilt in to it, you can add those make targetsto LOCAL_ADDITIONAL_DEPENDENCIES
.Usually this is a workaround for some other dependency that isn'tcreated automatically.
When a module is built, the module is created in an intermediatedirectory then copied to its final location. LOCAL_BUILT_MODULE isthe full path to the intermediate file. See LOCAL_INSTALLED_MODULEfor the path to the final installed location of the module.
Set by the host_xxx.make includes to tell base_rules.make and theother includes that we're building for the host. Kenneth did thisas part of openbinder, and I would like to clean it up so therules, includes and definitions aren't duplicated for host andtarget.
The fully qualified path name of the final location of the module.See LOCAL_BUILT_MODULE for the location of the intermediate filethat the make rules should actually be constructing.
Used in some stuff remaining from the openbinder for buildingscripts with particular values set,
Used in some stuff remaining from the openbinder build system thatwe might find handy some day.
Which kind of module this is. This variable is used to constructother variable names used to locate the modules. Seebase_rules.make and envsetup.make.
Set to the leaf name of the LOCAL_BUILT_MODULE. I'm not sure, butit looks like it's just used in the WHO_AM_I variable to identifyin the pretty printing what's being built.
The suffix that will be appendedto LOCAL_MODULE
toform LOCAL_MODULE_NAME
.For example, .so, .a, .dylib.
Calculated in base_rules.make to determine if this module shouldactually be stripped or not, based onwhether LOCAL_STRIPPABLE_MODULE
isset, and whether the combo is configured to ever strip modules.With Iliyan's stripping tool, this might change.
Set by the include makefiles if that type of module is strippable.Executables and shared libraries are.
Used while building the base libraries: libc, libm, libdl. Usuallyit should be set to "none," as it is in $(CLEAR_VARS). Whenbuilding these libraries, it's set to the ones they link against.For example, libc, libstdc++ and libdl don't link against anything,and libm links against libc. Normally, when the value is none,these libraries are automatically linked in to executables andlibraries, so you don't need to specify them manually.
联系客服