Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 19317362/94c709d74a6736f8b0f2b732b539d872 to your computer and use it in GitHub Desktop.
Save 19317362/94c709d74a6736f8b0f2b732b539d872 to your computer and use it in GitHub Desktop.
Recursively calculate shared library dependencies and generate System.load(); statements
# Set correct path to readelf binary in Android NDK
READELF=/opt/crystax-ndk-10.3.1/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-readelf
# List libraries that exist in /system/lib
STANDARD_LIBS=(c dl m stdc++ log z)
has() {
local p=$1
shift
local x
for x in "$@"; do
[[ "${x}" == "${p}" ]] && return 0
done
return 1
}
LIBS=()
x() {
local lib=$1
if [ ! -f "lib$lib.so" ]; then
return
fi
local i
for i in `$READELF -d "lib$lib.so" | grep NEEDED | sed -e "s/.*\[lib//g" | sed -e "s/\.so.*$//g" | xargs`; do
if has $i ${STANDARD_LIBS[*]}; then
continue
fi
x $i
if has $i ${LIBS[*]}; then
continue
fi
LIBS+=($i)
done
if has $lib ${LIBS[*]}; then
continue
fi
LIBS+=($lib)
}
x $1
for lib in ${LIBS[*]}; do
echo "System.loadLibrary(\"$lib\");"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment