If you are annoyed that "Sources for Android 26" are not yet available via SDK manager, this might be for you:
- Collect source files
mkdir android-sdk-source-build
cd android-sdk-source-build
mkdir -p frameworks/base
# Fetch repositories that contain the sources we're interested in
git clone --depth 1 https://android.googlesource.com/platform/frameworks/base -b android-8.0.0_r4 frameworks/base
git clone --depth 1 https://android.googlesource.com/platform/libcore -b android-8.0.0_r4
git clone --depth 1 https://android.googlesource.com/platform/development -b android-8.0.0_r4
# Create a basic source.properties file
echo -e "Pkg.UserSrc=false\nPkg.Revision=1\nAndroidVersion.ApiLevel=26" > source.properties
# Modify the script to create a sources ZIP to use "android-26" as top-level directory
cat development/build/tools/mk_sources_zip.py | sed -e 's/TOP_FOLDER = .*/TOP_FOLDER = "android-26"/' > my_mk_sources_zip.py
# Run the script to create android-26-sources.zip
python my_mk_sources_zip.py -z source.properties android-26-sources.zip .
- Extract into Android SDK source directory
unzip android-26-sources.zip -d ${ANDROID_HOME}/sources
- Restart Android Studio and SDK sources should show up.
Updated for API 27: https://gist.github.com/cketti/c0d1886627ce31fbf9aa8d7dc8a12424