Skip to content

Instantly share code, notes, and snippets.

@cketti
Created September 4, 2019 13:20
Show Gist options
  • Star 24 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cketti/210bb18b6e6112135b7b6468754901bf to your computer and use it in GitHub Desktop.
Save cketti/210bb18b6e6112135b7b6468754901bf to your computer and use it in GitHub Desktop.

Build "Sources for Android 29" so you can comfortably browse the Android API source in Android Studio.

  1. 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-10.0.0_r2 frameworks/base
git clone --depth 1 https://android.googlesource.com/platform/libcore -b android-10.0.0_r2
git clone --depth 1 https://android.googlesource.com/platform/development -b android-10.0.0_r2

# Create a basic source.properties file
echo -e "Pkg.UserSrc=false\nPkg.Revision=0\nAndroidVersion.ApiLevel=29" > source.properties

# Modify the script to create a sources ZIP to use "android-29" as top-level directory
cat development/build/tools/mk_sources_zip.py | sed -e 's/TOP_FOLDER = .*/TOP_FOLDER = "android-29"/' > my_mk_sources_zip.py

# Run the script to create android-29-sources.zip
python my_mk_sources_zip.py -z source.properties android-29-sources.zip .
  1. Extract into Android SDK source directory
unzip android-29-sources.zip -d ${ANDROID_HOME}/sources
  1. Restart Android Studio and SDK sources should show up.
@ni554n
Copy link

ni554n commented Oct 28, 2021

I have automated this script using Github Workflow here: https://github.com/ni554n/sources-for-android-sdk

You can download the package and watch for Releases to get notified of the upcoming API source builds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment