Created
April 27, 2015 20:38
-
-
Save optedoblivion/a7977e66b40427d5206a to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
# Supported list | |
SUPPORTED_PLATFORMS="Linux Darwin" | |
# Check platform | |
UNAME=$(uname) | |
VALID_PLATFORM=0 | |
for platform in `echo $SUPPORTED_PLATFORMS`; | |
do | |
if [ "$UNAME" == "$platform" ]; then | |
VALID_PLATFORM=1 | |
break | |
fi | |
done | |
# Validate | |
if [ $VALID_PLATFORM -ne 1 ]; then | |
echo | |
echo "Unsupported platform $UNAME" | |
echo | |
exit 1 | |
fi | |
# We need to have selected a lunch combo | |
if [ -z "$OUT" ]; then | |
echo | |
echo "Please lunch a product before using this command" | |
echo | |
exit 1 | |
else | |
OUTDIR=${OUT%/*/*/*} | |
fi | |
# Ensure we are at croot | |
cd $ANDROID_BUILD_TOP | |
# Source aliases | |
. build/envsetup.sh | |
# Make sure code source is up to date | |
reposync | |
# Build all modules | |
mka | |
# TODO: Need a good way to parse this automagically | |
#PLATFORMS=$(ls prebuilts/devtools/platforms | xargs | awk ' { print $1 }') | |
# TODO: Populate hard coded items once above is figured out | |
SDK_VER="24.1.2" | |
API_VER="22" | |
CUSTOM_NAME="CM" | |
CUSTOM_VER="122" | |
echo | |
echo "===============================" | |
echo | |
echo "SDK Version: $API_VER" | |
echo "Custom Name: $CUSTOM_NAME" | |
echo "Custom Version: $CUSTOM_VER" | |
echo "Out directory: $OUTDIR" | |
echo | |
echo "===============================" | |
echo | |
STUBJAR=${OUTDIR}/target/common/obj/JAVA_LIBRARIES/android_stubs_current_intermediates/classes.jar | |
FRAMEWORKJAR=${OUTDIR}/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes.jar | |
COREJAR=${OUTDIR}/target/common/obj/JAVA_LIBRARIES/core-libart_intermediates/classes.jar | |
FRAMEWORKRESJAR=${OUTDIR}/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes.jar | |
TELEPHONYJAR=${OUTDIR}/target/common/obj/JAVA_LIBRARIES/telephony-common_intermediates/classes.jar | |
if [ ! -f $STUBJAR ]; then | |
echo "Cannot locate $STUBJAR" | |
exit 1 | |
fi | |
if [ ! -f $FRAMEWORKJAR ]; then | |
echo "Cannot locate $FRAMEWORKJAR" | |
exit 1 | |
fi | |
if [ ! -f $COREJAR ]; then | |
echo "Cannot locate $COREJAR" | |
exit 1 | |
fi | |
if [ ! -f $FRAMEWORKRESJAR ]; then | |
echo "Cannot locate $FRAMEWORKRESJAR" | |
exit 1 | |
fi | |
if [ ! -f $TELEPHONYJAR ]; then | |
echo "Cannot locate $TELEPHONYJAR" | |
exit 1 | |
fi | |
TMP_DIR=${OUTDIR}/tmp | |
mkdir -p ${TMP_DIR} | |
echo -n "Extracting data to $TMP_DIR..." | |
$(cd ${TMP_DIR}; jar -xf ${STUBJAR}) | |
$(cd ${TMP_DIR}; jar -xf ${COREJAR}) | |
$(cd ${TMP_DIR}; jar -xf ${FRAMEWORKJAR}) | |
$(cd ${TMP_DIR}; jar -xf ${FRAMEWORKRESJAR}) | |
$(cd ${TMP_DIR}; jar -xf ${TELEPHONYJAR}) | |
echo "Done" | |
echo -n "Creating output library..." | |
jar -cf ${OUTDIR}/android.jar -C ${TMP_DIR}/ . | |
echo "Done." | |
echo "android.jar created at ${OUTDIR}/android.jar" | |
echo "Now attempting to create new sdk platform with it..." | |
if [ -z "$ANDROID_HOME" ]; then | |
ANDROID=$(command -v emulator) | |
ANDROID_HOME=${ANDROID%/*} | |
if [ -z "$ANDROID_HOME" ]; then | |
echo "ANDROID_HOME variable is not set. Do you have the sdk installed ?" | |
exit 1 | |
fi | |
fi | |
# Build custom SDK, but location paths differ for various platforms | |
# TODO: Automagically find the platform/sdk version (separate from API version) | |
if [ "$UNAME" == "Darwin" ]; then | |
cp -rf ${ANDROID_HOME}/$SDK_VER/platforms/android-${API_VER} ${ANDROID_HOME}/$SDK_VER/platforms/android-${API_VER}-${CUSTOM_NAME} | |
rm -f ${ANDROID_HOME}/$SDK_VER/platforms/android-${API_VER}-${CUSTOM_NAME}/android.jar | |
cp -f ${OUTDIR}/android.jar ${ANDROID_HOME}/$SDK_VER/platforms/android-${API_VER}-${CUSTOM_NAME}/android.jar | |
sed -i 's/^ro\.build\.version\.sdk=.*/ro.build.version.sdk=122/g' ${ANDROID_HOME}/$SDK_VER/platforms/android-${API_VER}-${CUSTOM_NAME}/build.prop | |
sed -i 's/^ro\.build\.version\.release=.*/ro.build.version.release=CM/g' ${ANDROID_HOME}/$SDK_VER/platforms/android-${API_VER}-${CUSTOM_NAME}/build.prop | |
sed -i 's/AndroidVersion.ApiLevel=22/AndroidVersion.ApiLevel=122/' ${ANDROID_HOME}/$SDK_VER/platforms/android-${API_VER}-${CUSTOM_NAME}/source.properties | |
sed -i 's/Pkg.Desc=/Pkg.Desc=CM /' ${ANDROID_HOME}/$SDK_VER/platforms/android-${API_VER}-${CUSTOM_NAME}/source.properties | |
elif [ "$UNAME" == "Linux" ]; then | |
cp -rf ${ANDROID_HOME}/platforms/android-${API_VER} ${ANDROID_HOME}/platforms/android-${API_VER}-${CUSTOM_NAME} | |
rm -f ${ANDROID_HOME}/platforms/android-${API_VER}-${CUSTOM_NAME}/android.jar | |
cp -f ${OUTDIR}/android.jar ${ANDROID_HOME}/platforms/android-${API_VER}-${CUSTOM_NAME}/android.jar | |
sed -i 's/^ro\.build\.version\.sdk=.*/ro.build.version.sdk=122/g' ${ANDROID_HOME}/platforms/android-${API_VER}-${CUSTOM_NAME}/build.prop | |
sed -i 's/^ro\.build\.version\.release=.*/ro.build.version.release=CM/g' ${ANDROID_HOME}/platforms/android-${API_VER}-${CUSTOM_NAME}/build.prop | |
sed -i 's/AndroidVersion.ApiLevel=22/AndroidVersion.ApiLevel=122/' ${ANDROID_HOME}/platforms/android-${API_VER}-${CUSTOM_NAME}/source.properties | |
sed -i 's/Pkg.Desc=/Pkg.Desc=CM /' ${ANDROID_HOME}/platforms/android-${API_VER}-${CUSTOM_NAME}/source.properties | |
fi | |
echo "Done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment