1#!/bin/bash 2# 3# This script sync and builds the AOSP source for a specified platform version. 4# 5# Usage: 6# sync-android.sh <src root> <android version> 7# 8# This will create a <src root>/aosp-<android version>, sync the source for that version, and 9# attempt to build. 10# 11# You may need to customize the JAVA_6 or JAVA_7 install locations environment variables, or ensure 12# the right version of java is in your PATH when versions earlier than nougat. See 13# https://source.android.com/source/requirements#jdk for more details. 14# 15# See README.md for additional instructions 16 17JAVA_6=/usr/lib/jvm/jdk1.6.0_45/bin 18JAVA_7=/usr/lib/jvm/java-7-openjdk-amd64/bin 19 20function usage() { 21 echo "Usage: ${0} <android root path> <android-version> <parallel jobs>" 22} 23 24if [[ $# -ne 3 ]]; then 25 usage 26 exit 1 27fi 28 29set -ex 30 31ANDROID_VERSION=$2 32SRC_ROOT=$1/aosp-$ANDROID_VERSION 33J=$3 34 35sync_source() { 36 repo init -q --depth=1 -uhttps://android.googlesource.com/platform/manifest -b android-$ANDROID_VERSION 37 repo sync -cq -j$J 38} 39 40build_source() { 41 source build/envsetup.sh 42 43 if [[ "${ANDROID_VERSION}" == "4.1.2_r1" ]]; then 44 lunch generic_x86-eng 45 export PATH=$JAVA_6:$PATH 46 make -j$J 47 elif [[ "${ANDROID_VERSION}" == "4.2.2_r1.2" ]]; then 48 lunch generic_x86-eng 49 export PATH=$JAVA_6:$PATH 50 make -j$J 51 elif [[ "${ANDROID_VERSION}" == "4.3_r2" ]]; then 52 lunch aosp_x86-eng 53 export PATH=$JAVA_6:$PATH 54 make -j$J 55 elif [[ "${ANDROID_VERSION}" == "4.4_r1" ]]; then 56 lunch aosp_x86-eng 57 export PATH=$JAVA_6:$PATH 58 make -j$J 59 elif [[ "${ANDROID_VERSION}" == "5.0.2_r3" ]]; then 60 lunch aosp_x86-eng 61 tapas core-libart services services.accessibility telephony-common framework ext framework-res 62 export PATH=$JAVA_7:$PATH 63 ANDROID_COMPILE_WITH_JACK=false make -j$J 64 elif [[ "${ANDROID_VERSION}" == "5.1.1_r9" ]]; then 65 tapas core-libart services services.accessibility telephony-common framework ext framework-res 66 export PATH=$JAVA_7:$PATH 67 ANDROID_COMPILE_WITH_JACK=false make -j$J 68 elif [[ "${ANDROID_VERSION}" == "6.0.1_r3" ]]; then 69 tapas core-libart services services.accessibility telephony-common framework ext icu4j-icudata-jarjar framework-res 70 export PATH=$JAVA_7:$PATH 71 ANDROID_COMPILE_WITH_JACK=false make -j$J 72 elif [[ "${ANDROID_VERSION}" == "7.0.0_r1" ]]; then 73 cd ../.. 74 lunch aosp_x86-eng 75 make -j$J 76 make -j$J out/target/common/obj/JAVA_LIBRARIES/services_intermediates/classes.jar out/host/linux-x86/framework/icu4j-icudata-host-jarjar.jar out/host/linux-x86/framework/icu4j-icutzdata-host-jarjar.jar 77 elif [[ "${ANDROID_VERSION}" == "7.1.0_r7" ]]; then 78 cd frameworks/base && git fetch https://android.googlesource.com/platform/frameworks/base refs/changes/75/310575/1 && git cherry-pick FETCH_HEAD && git commit -a -m "patch shortcut service" 79 cd ../.. 80 lunch aosp_x86-eng 81 make -j$J 82 make -j$J out/target/common/obj/JAVA_LIBRARIES/services_intermediates/classes.jar out/host/linux-x86/framework/icu4j-icudata-host-jarjar.jar out/host/linux-x86/framework/icu4j-icutzdata-host-jarjar.jar 83 elif [[ "${ANDROID_VERSION}" == "8.0.0_r4" ]]; then 84 cd external/robolectric && git fetch https://android.googlesource.com/platform/external/robolectric refs/changes/22/463722/1 && git cherry-pick FETCH_HEAD 85 cd ../.. 86 lunch aosp_x86-eng 87 make -j$J robolectric_android-all 88 else 89 echo "Robolectric: No match for version: ${ANDROID_VERSION}" 90 exit 1 91 fi 92} 93 94mkdir -p $SRC_ROOT 95cd $SRC_ROOT 96 97sync_source 98build_source 99 100echo "Done building $SRC_ROOT!!" 101 102