Build System Changes for Writers

Deprecating / obsoleting variables in Makefiles

It is not required to source before running a build. Many scripts, including a majority of our automated build systems, do not do so. Make will transparently make every environment variable available as a make variable. This means that relying on environment variables only set up in will produce different output for local users and scripted users.

Many of these variables also include absolute path names, which we‘d like to keep out of the generated files, so that you don’t need to do a full rebuild if you move the source tree.

To fix this, we‘re marking the variables that are set in as deprecated in the makefiles. This will trigger a warning every time one is read (or written) inside Kati. Once all the warnings have been removed for a particular variable, we’ll switch it to obsolete, and any references will become errors. variables with make equivalents

instead ofuse

All of the make variables may be relative paths from the current directory, or absolute paths if the output directory was specified as an absolute path. If you need an absolute variable, convert it to absolute during a rule, so that it's not expanded into the generated ninja file:

$(PRODUCT_OUT)/gen.img: my/src/path/
	export PRODUCT_OUT=$$(cd $(PRODUCT_OUT); pwd); cd my/src/path; ./ -o $${PRODUCT_OUT}/gen.img


In files, you can always assume that the current directory is the root of the source tree, so this can just be replaced with ‘.’ (which is what $TOP is hardcoded to), or removed entirely. If you need an absolute path, see the instructions above.

Stop using PATH directly

This isn‘t only set by, but it is modified by it. Due to that it’s rather easy for this to change between different shells, and it's not ideal to reread the makefiles every time this changes.

In most cases, you shouldn‘t need to touch PATH at all. When you need to have a rule reference a particular binary that’s part of the source tree or outputs, it's preferrable to just use the path to the file itself (since you should already be adding that as a dependency).

Depending on the rule, passing the file path itself may not be feasible due to layers of unchangable scripts/binaries. In that case, be sure to add the dependency, but modify the PATH within the rule itself:

$(TARGET): myscript my/path/binary
	PATH=my/path:$$PATH myscript -o $@

Stop using PYTHONPATH directly

Like PATH, this isn‘t only set by, but it is modified by it. Due to that it’s rather easy for this to change between different shells, and it's not ideal to reread the makefiles every time.

The best solution here is to start switching to Soong's python building support, which packages the python interpreter, libraries, and script all into one file that no longer needs PYTHONPATH. See fontchain_lint for examples of this:

If you still need to use PYTHONPATH, do so within the rule itself, just like path:

$(TARGET): $(sort $(shell find my/python/lib -name '*.py'))
	PYTHONPATH=my/python/lib:$$PYTHONPATH -o $@


Specify Framework Compatibility Matrix Version in device manifest by adding a target-level attribute to the root element <manifest>. If PRODUCT_COMPATIBILITY_MATRIX_LEVEL_OVERRIDE is 26 or 27, you can add "target-level"="1" to your device manifest instead.


Clang is the default and only supported Android compiler, so there is no reason for this option to exist.

Other variables {#other_envsetup_variables}


These are all exported from, but don‘t have clear equivalents within the makefile system. If you need one of them, you’ll have to set up your own version.