Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
createStrippedAndDebugInfo() {
cd ${REPO_PATH} # assuming we're in your repository's directory
AAR=`find -name '*.aar'` # find the path to the AAR containing the binaries
mkdir -p ${TMP_DIR_NAME}
try cd ${TMP_DIR_NAME}
try cp $AAR . # copy the AAR with symbolised binaries to the temp directory
try unzip $AAR -d .
mkdir -p obj
try cp -R jni/* obj/ # copy all symbolised binaries from the jni/ directory to the obj/ directory
JNI_ARCHS=(`find jni/ -type d -maxdepth 1 -mindepth 1 -exec basename {} \; | perl -ne 'print $1." " if /(.*)/g'`)
# Strip the binaries for each CPU architecture (ABI) under the jni/ directory
for jni_arch in ${JNI_ARCHS[@]};
echo "Stripping ${jni_arch}"
SO_FILE=`find jni/${jni_arch} -name '*.so'` # find the .so binary for the given ABI
# Make sure we use the correct `strip` and `nm` tools for each ABI case
case ${jni_arch} in
STRIP=`find ${ANDROID_NDK}/toolchains/arm-*/prebuilt/*/bin -name '*strip'`
NM=`find ${ANDROID_NDK}/toolchains/arm-*/prebuilt/*/bin -name '*-nm' | grep -v "gcc-nm$"`
STRIP=`find ${ANDROID_NDK}/toolchains/aarch64-*/prebuilt/*/bin -name '*strip'`
NM=`find ${ANDROID_NDK}/toolchains/aarch64-*/prebuilt/*/bin -name '*-nm' | grep -v "gcc-nm$"`
STRIP=`find ${ANDROID_NDK}/toolchains/x86_64-*/prebuilt/*/bin -name '*strip'`
NM=`find ${ANDROID_NDK}/toolchains/x86_64-*/prebuilt/*/bin -name '*-nm' | grep -v "gcc-nm$"`
STRIP=`find ${ANDROID_NDK}/toolchains/x86-*/prebuilt/*/bin -name '*strip'`
NM=`find ${ANDROID_NDK}/toolchains/x86-*/prebuilt/*/bin -name '*-nm' | grep -v "gcc-nm$"`
# you can add more cases if you support different ABI combinations
die "unknown architecture found in jni folder!"
# Exit the script if no debug symbols were found in the allegedly "simbolysed" script,
# to make sure we didn't have issues in previous build steps (for example, with Gradle scripts)
${NM} ${SO_FILE} | test $(wc -l) -eq 0 && die "No symbols present in the shared library"
echo "${STRIP} --strip-debug ${SO_FILE}"
${STRIP} --strip-unneeded ${SO_FILE} || die "Failed to strip symbols"
# Zip the new files back into another AAR
try cd <PATH_TO_TMP_DIR>
try zip -ru ${AAR} .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment