Build Environment
Macbook with 2.2G core i7 + 8G RAM
- OS X 10.9.5
- GNU Make 3.81
- Python 2.7.5
- Java 1.7.0_71
- git 1.9.3 ( Apple git-50 )
- gcc 4.2.1
Problem
With all Android source in /Volumes/Opensource/android/aosp, trying to make -j4, get error message
Troubleshooting process
This is just the way of thinking, not a step by step guide.
First, where is target out/target/common/docs/api-stubs-timestamp defined.Apparently frameworks/base//Volumes/Opensource/android/aosp/frameworks/base is an incorrectly constructed path, so the first step is to look up where api-stubs-timestamp is defined.
find . -name "*.mk" | xargs egrep -n "api-stubs-timestamp"
Got all files containing api-stubs-timestamp, but no one directly defines the target. One of hints is the target might be dynamically generated and related rule droiddoc. check the file dorddoc.mk, and found
full_target:=$(call doc-timestamp-for,$(LOCAL_MODULE))
Check doc-timestamp-for in definitions.mk,
define doc-timestamp-for
$(OUT_DOCS)/$(strip $(1))-timestamp
endef
Now, we know where is the target come from: when we specify LOCAL_MODULE as api-stubs, and include $(BUILD_DRODDOC), we make target ..../api-stubs-timestamp.
Search all .mk file for api-stubs MODULE, or check frameworks/base/Android.mk first as the error message shows the target is related to frameworks/base.
Search all .mk file for api-stubs MODULE, or check frameworks/base/Android.mk first as the error message shows the target is related to frameworks/base.
Yes, api-stubs MODULE is defined in frameworks/base/Android.mk,
Second, how the wrong path frameworks/base//Volumes/Opensource/android/aosp/ frameworks/base is constructed.
Add $(info, LOCAL_SRC_FILES=$(LOCAL_SRC_FILES) ) before $(BUILD_DROIDDOC), in frameworks/base/Android.mk, then build again, the wrong path shows up.
Create a simple Android.mk and track variable LOCAL_SRC_FILES. It leads to find-subdir-files expendable variable in definitions.mk
Redirecting the output of cd command to /dev/null can be a workaround for this issue. But it's absolutely not the root reason, because the build script without any modification works anywhere else.
Finally, The root reason
Check cd command in shell: open another terminal window on Mac, and cd to a subdirectory of current location. It has an output.
Compare with Linux, cd command has no output in my Linux box, so the difference comes from the bash installed in my Mac.
Check bash version, the one running on the Mac is 3.2.53; it's 4.2.24 on the Linux box. Is it possible that Mac bash doesn't support Android build? Ask Google, no one mentioned the Android build needs a specific bash version.
Check bash environment variable which could be specific in my environment, especially the ones which could be related to cd commands, then it comes CDPATH.
Remove CDPATH, and check cd in terminal window on the Mac. There is NO output anymore.
Build Android again. It works!!
Create a simple Android.mk and track variable LOCAL_SRC_FILES. It leads to find-subdir-files expendable variable in definitions.mk
define find-subdir-files
$(patsubst ./%,%,$(shell cd $(LOCAL_PATH) ; find -L $(1)))
endef
find-subdir-files is supposed to expand as the the result of find command, which are all .java files in this case, but it also includes the LOCAL_PATH, the result of cd command, in my build.$(patsubst ./%,%,$(shell cd $(LOCAL_PATH) ; find -L $(1)))
endef
Redirecting the output of cd command to /dev/null can be a workaround for this issue. But it's absolutely not the root reason, because the build script without any modification works anywhere else.
Finally, The root reason
Check cd command in shell: open another terminal window on Mac, and cd to a subdirectory of current location. It has an output.
Compare with Linux, cd command has no output in my Linux box, so the difference comes from the bash installed in my Mac.
Check bash version, the one running on the Mac is 3.2.53; it's 4.2.24 on the Linux box. Is it possible that Mac bash doesn't support Android build? Ask Google, no one mentioned the Android build needs a specific bash version.
Check bash environment variable which could be specific in my environment, especially the ones which could be related to cd commands, then it comes CDPATH.
Remove CDPATH, and check cd in terminal window on the Mac. There is NO output anymore.
Build Android again. It works!!