Created
August 6, 2018 18:03
-
-
Save nasahapps/07fa38dc5f63aaed72f9bd0ca7a30758 to your computer and use it in GitHub Desktop.
Downloads and packages Android sources to your local SDK directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env sh | |
set -euo pipefail | |
########## | |
# Config # | |
########## | |
readonly GIT_BRANCH='android-p-preview-2' | |
readonly API_LEVEL='28' | |
########### | |
# Helpers # | |
########### | |
readonly CUR_DIR=$( pwd ) | |
readonly WORKING_DIR=$( mktemp -d ) | |
setup() { | |
pushd ${WORKING_DIR} | |
mkdir -p frameworks/base | |
} | |
teardown() { | |
popd | |
rm -rf "${WORKING_DIR}" | |
} | |
fetch_sources() { | |
local -r target_branch="${1}" | |
# Fetch repositories that contain the sources we're interested in | |
git clone --depth 1 https://android.googlesource.com/platform/frameworks/base -b "${target_branch}" frameworks/base | |
git clone --depth 1 https://android.googlesource.com/platform/libcore -b "${target_branch}" | |
git clone --depth 1 https://android.googlesource.com/platform/development -b "${target_branch}" | |
} | |
package_sources() { | |
local -r zip_name="${1}" | |
# Create a basic source.properties file | |
echo -e "Pkg.UserSrc=false\nPkg.Revision=1\nAndroidVersion.ApiLevel=${API_LEVEL}" > 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-${API_LEVEL}\"/" > my_mk_sources_zip.py | |
# Run the script to create android-26-sources.zip | |
python my_mk_sources_zip.py -z source.properties "${zip_name}" . | |
} | |
maybe_install_sources() { | |
local -r zip_name="${1}" | |
local -r sources_dir="${ANDROID_HOME}/sources" | |
local -r target_path="${sources_dir}/android-${API_LEVEL}" | |
if [ -d "${target_path}" ]; then | |
echo "" | |
echo "WARN: directory exists [${target_path}] copying instead..." | |
local -r zip_path="${CUR_DIR}/${zip_name}" | |
if [ -f "${zip_path}" ]; then | |
echo "WARN: nevermind, file exists [${zip_path}] skipping..." | |
else | |
cp "${zip_name}" "${CUR_DIR}/" | |
fi | |
else | |
unzip "${zip_name}" -d "${sources_dir}" | |
fi | |
} | |
############### | |
# DO WORK SON # | |
############### | |
main() { | |
local -r zip_name="android-${API_LEVEL}-sources.zip" | |
setup | |
fetch_sources "${GIT_BRANCH}" | |
package_sources "${zip_name}" | |
maybe_install_sources "${zip_name}" | |
teardown | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment