Skip to content

Instantly share code, notes, and snippets.

@danielcarr
Created January 18, 2018 07:36
Show Gist options
  • Save danielcarr/caf9cfbd0da81402a940ecf7d3a87cfc to your computer and use it in GitHub Desktop.
Save danielcarr/caf9cfbd0da81402a940ecf7d3a87cfc to your computer and use it in GitHub Desktop.
Copy Android locally built libraries from a library source path into the /libs/ directory of a specific module
#! /usr/bin/env bash
# if there are no arguments, or if the first argument is -h or --help
if test ${1:--h} = -h -o ${1:--h} = --help; then
echo "Usage: ${0} <buildtype> <src lib root> <destination lib dir> [<libnames>...]"
echo "<buildtype> is eg debug or release"
echo "<src lib root> is the directory containing the repos where libraries are to be found"
echo "<destination lib dir> is the directory within the repo to which files should be copied"
echo "<libnames> are the names of all libraries that should be copied (eg 'libcore')"
echo "if no libraries are specified, the libraries already found in the destination will be copied again."
exit
fi
AARPATH="build/outputs/aar"
buildtype=$1 # eg debug or release
libroot=$2 # The path to the directory containing the library repos
aardir=$3 # The path to the library directory within the repo to be updated
if test $# -gt 3; then
libset=${@:4} # All remaining arguments are library names
else # get library names from destination directory
libset="$(find ${aardir} -name *.aar -exec basename {} .aar \; | tr "\n" " ")"
fi
suffix="${buildtype}.aar"
# iterate over all build directories for all modules in all libraries
for dir in $(ls -d ${libroot}/*/*/${AARPATH}); do
aar=$(ls "${dir}"/*-${suffix}) # find the relevant compiled library file
libname=$(basename "${aar%%-${suffix}}") # get the resulting library name
if [[ " ${libset} " == *" ${libname} "* ]]; then
# if the library is in the set of libraries to copy,
# copy it to the repo where it's needed (without the suffix)
cp "${aar}" "${aardir}/${libname}.aar"
echo "copied ${libname}.aar to ${aardir}" # and give feedback
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment