Android NDK path variable for “strip” command in CMake build tool chain
I am trying to add a strip debug symbols step for my Android library which includes native shared libraries for different ABIs, e.g. x86/native-lib.so
, x86_64/native-lib.so
, arm64-v8a/native-lib.so
, etc.
I understand that the strip command must be respective to each ABI. So, I need to invoke the correct strip command, for which I need to know its correct path during build time.
For example, for ABI x86_64, I need to have below path setting:
set(STRIP ~/Library/Android/android-ndk-r16b/toolchains/x86_64-4.9/prebuilt/darwin-x86_64/bin/x86_64-linux-android-strip)
add_custom_command(TARGET ${SHARED_LIBRARY_NAME} POST_BUILD
COMMAND ${STRIP}
"${DIST_LIBS_DIR}/${LIB_BUILD_TYPE}/${ANDROID_ABI}/lib${SHARED_LIBRARY_NAME}.so"
COMMENT "Strip debug symbols done on final binary.")
Path I need is illustrated as below:
So, my question:
Is there an existing CMake variable to point at this path, i.e.
/android-ndk-r16b/toolchains/???/prebuilt/???/bin/???-???-???-strip
?If not, is there a way to form this path utilising other known Android CMake variable, e.g.
ANDROID_NDK
,ANDROID_ABI
, etc?

add a comment |
I am trying to add a strip debug symbols step for my Android library which includes native shared libraries for different ABIs, e.g. x86/native-lib.so
, x86_64/native-lib.so
, arm64-v8a/native-lib.so
, etc.
I understand that the strip command must be respective to each ABI. So, I need to invoke the correct strip command, for which I need to know its correct path during build time.
For example, for ABI x86_64, I need to have below path setting:
set(STRIP ~/Library/Android/android-ndk-r16b/toolchains/x86_64-4.9/prebuilt/darwin-x86_64/bin/x86_64-linux-android-strip)
add_custom_command(TARGET ${SHARED_LIBRARY_NAME} POST_BUILD
COMMAND ${STRIP}
"${DIST_LIBS_DIR}/${LIB_BUILD_TYPE}/${ANDROID_ABI}/lib${SHARED_LIBRARY_NAME}.so"
COMMENT "Strip debug symbols done on final binary.")
Path I need is illustrated as below:
So, my question:
Is there an existing CMake variable to point at this path, i.e.
/android-ndk-r16b/toolchains/???/prebuilt/???/bin/???-???-???-strip
?If not, is there a way to form this path utilising other known Android CMake variable, e.g.
ANDROID_NDK
,ANDROID_ABI
, etc?

Note that Android Studio (or, to be more exact, the Android Gradle plugin) will strip the shared objects for you. The trick is they perform the strip step later, not as part of CMake.
– Alex Cohn
Nov 21 '18 at 10:08
This is true for application projects, but for library projects with native shared .so, I want to ship a slimmed package rather than leave a heavy bundle to customers.
– shizhen
Nov 21 '18 at 10:17
add a comment |
I am trying to add a strip debug symbols step for my Android library which includes native shared libraries for different ABIs, e.g. x86/native-lib.so
, x86_64/native-lib.so
, arm64-v8a/native-lib.so
, etc.
I understand that the strip command must be respective to each ABI. So, I need to invoke the correct strip command, for which I need to know its correct path during build time.
For example, for ABI x86_64, I need to have below path setting:
set(STRIP ~/Library/Android/android-ndk-r16b/toolchains/x86_64-4.9/prebuilt/darwin-x86_64/bin/x86_64-linux-android-strip)
add_custom_command(TARGET ${SHARED_LIBRARY_NAME} POST_BUILD
COMMAND ${STRIP}
"${DIST_LIBS_DIR}/${LIB_BUILD_TYPE}/${ANDROID_ABI}/lib${SHARED_LIBRARY_NAME}.so"
COMMENT "Strip debug symbols done on final binary.")
Path I need is illustrated as below:
So, my question:
Is there an existing CMake variable to point at this path, i.e.
/android-ndk-r16b/toolchains/???/prebuilt/???/bin/???-???-???-strip
?If not, is there a way to form this path utilising other known Android CMake variable, e.g.
ANDROID_NDK
,ANDROID_ABI
, etc?

I am trying to add a strip debug symbols step for my Android library which includes native shared libraries for different ABIs, e.g. x86/native-lib.so
, x86_64/native-lib.so
, arm64-v8a/native-lib.so
, etc.
I understand that the strip command must be respective to each ABI. So, I need to invoke the correct strip command, for which I need to know its correct path during build time.
For example, for ABI x86_64, I need to have below path setting:
set(STRIP ~/Library/Android/android-ndk-r16b/toolchains/x86_64-4.9/prebuilt/darwin-x86_64/bin/x86_64-linux-android-strip)
add_custom_command(TARGET ${SHARED_LIBRARY_NAME} POST_BUILD
COMMAND ${STRIP}
"${DIST_LIBS_DIR}/${LIB_BUILD_TYPE}/${ANDROID_ABI}/lib${SHARED_LIBRARY_NAME}.so"
COMMENT "Strip debug symbols done on final binary.")
Path I need is illustrated as below:
So, my question:
Is there an existing CMake variable to point at this path, i.e.
/android-ndk-r16b/toolchains/???/prebuilt/???/bin/???-???-???-strip
?If not, is there a way to form this path utilising other known Android CMake variable, e.g.
ANDROID_NDK
,ANDROID_ABI
, etc?


edited Dec 21 '18 at 2:12
shizhen
asked Nov 21 '18 at 9:59


shizhenshizhen
3,14041232
3,14041232
Note that Android Studio (or, to be more exact, the Android Gradle plugin) will strip the shared objects for you. The trick is they perform the strip step later, not as part of CMake.
– Alex Cohn
Nov 21 '18 at 10:08
This is true for application projects, but for library projects with native shared .so, I want to ship a slimmed package rather than leave a heavy bundle to customers.
– shizhen
Nov 21 '18 at 10:17
add a comment |
Note that Android Studio (or, to be more exact, the Android Gradle plugin) will strip the shared objects for you. The trick is they perform the strip step later, not as part of CMake.
– Alex Cohn
Nov 21 '18 at 10:08
This is true for application projects, but for library projects with native shared .so, I want to ship a slimmed package rather than leave a heavy bundle to customers.
– shizhen
Nov 21 '18 at 10:17
Note that Android Studio (or, to be more exact, the Android Gradle plugin) will strip the shared objects for you. The trick is they perform the strip step later, not as part of CMake.
– Alex Cohn
Nov 21 '18 at 10:08
Note that Android Studio (or, to be more exact, the Android Gradle plugin) will strip the shared objects for you. The trick is they perform the strip step later, not as part of CMake.
– Alex Cohn
Nov 21 '18 at 10:08
This is true for application projects, but for library projects with native shared .so, I want to ship a slimmed package rather than leave a heavy bundle to customers.
– shizhen
Nov 21 '18 at 10:17
This is true for application projects, but for library projects with native shared .so, I want to ship a slimmed package rather than leave a heavy bundle to customers.
– shizhen
Nov 21 '18 at 10:17
add a comment |
2 Answers
2
active
oldest
votes
You can use ${CMAKE_STRIP}
. It is set appropriately when you use the -DCMAKE_TOOLCHAIN_FILE=android.toolchain.cmake. I hope it is OK also if you work with 'built-in' Android support with supported NDK version.
Thanks a lot for pointing at the fileandroid.toolchain.cmake
. It does be helpful with solving my real problem.
– shizhen
Nov 22 '18 at 1:39
add a comment |
Thanks @Alex Cohn a lot for pointing out the file android.toolchain.cmake
which usually exists at directory ~/Library/Android/sdk/cmake/cmake_version_xxx/android.toolchain.cmake
on macOS.
There are many useful Android CMake variables already configured inside, e.g.
ANDROID_NDK
ANDROID_TOOLCHAIN
ANDROID_ABI
ANDROID_PLATFORM
ANDROID_STL
ANDROID_PIE
ANDROID_CPP_FEATURES
ANDROID_ALLOW_UNDEFINED_SYMBOLS
ANDROID_ARM_MODE
ANDROID_ARM_NEON
ANDROID_DISABLE_NO_EXECUTE
ANDROID_DISABLE_RELRO
ANDROID_DISABLE_FORMAT_STRING_CHECKS
ANDROID_CCACHE
And the one ANDROID_TOOLCHAIN_PREFIX
is exactly what I looked for, so my final CMake script comes into below:
add_custom_command(TARGET ${SHARED_LIBRARY_NAME} POST_BUILD
COMMAND "${ANDROID_TOOLCHAIN_PREFIX}strip" -g -S -d --strip-debug --verbose
"${DIST_LIBS_DIR}/${LIB_BUILD_TYPE}/${ANDROID_ABI}/lib${SHARED_LIBRARY_NAME}.so"
COMMENT "Strip debug symbols done on final binary.")
And I don't need to explicitly pass any additional arguments, i.e. DCMAKE_TOOLCHAIN_FILE=android.toolchain.cmake
, from command line to the build process. Because, this file, i.e. android.toolchain.cmake
, was already taken into account automatically by Android native build system.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53409479%2fandroid-ndk-path-variable-for-strip-command-in-cmake-build-tool-chain%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use ${CMAKE_STRIP}
. It is set appropriately when you use the -DCMAKE_TOOLCHAIN_FILE=android.toolchain.cmake. I hope it is OK also if you work with 'built-in' Android support with supported NDK version.
Thanks a lot for pointing at the fileandroid.toolchain.cmake
. It does be helpful with solving my real problem.
– shizhen
Nov 22 '18 at 1:39
add a comment |
You can use ${CMAKE_STRIP}
. It is set appropriately when you use the -DCMAKE_TOOLCHAIN_FILE=android.toolchain.cmake. I hope it is OK also if you work with 'built-in' Android support with supported NDK version.
Thanks a lot for pointing at the fileandroid.toolchain.cmake
. It does be helpful with solving my real problem.
– shizhen
Nov 22 '18 at 1:39
add a comment |
You can use ${CMAKE_STRIP}
. It is set appropriately when you use the -DCMAKE_TOOLCHAIN_FILE=android.toolchain.cmake. I hope it is OK also if you work with 'built-in' Android support with supported NDK version.
You can use ${CMAKE_STRIP}
. It is set appropriately when you use the -DCMAKE_TOOLCHAIN_FILE=android.toolchain.cmake. I hope it is OK also if you work with 'built-in' Android support with supported NDK version.
answered Nov 21 '18 at 10:28
Alex CohnAlex Cohn
41.4k553188
41.4k553188
Thanks a lot for pointing at the fileandroid.toolchain.cmake
. It does be helpful with solving my real problem.
– shizhen
Nov 22 '18 at 1:39
add a comment |
Thanks a lot for pointing at the fileandroid.toolchain.cmake
. It does be helpful with solving my real problem.
– shizhen
Nov 22 '18 at 1:39
Thanks a lot for pointing at the file
android.toolchain.cmake
. It does be helpful with solving my real problem.– shizhen
Nov 22 '18 at 1:39
Thanks a lot for pointing at the file
android.toolchain.cmake
. It does be helpful with solving my real problem.– shizhen
Nov 22 '18 at 1:39
add a comment |
Thanks @Alex Cohn a lot for pointing out the file android.toolchain.cmake
which usually exists at directory ~/Library/Android/sdk/cmake/cmake_version_xxx/android.toolchain.cmake
on macOS.
There are many useful Android CMake variables already configured inside, e.g.
ANDROID_NDK
ANDROID_TOOLCHAIN
ANDROID_ABI
ANDROID_PLATFORM
ANDROID_STL
ANDROID_PIE
ANDROID_CPP_FEATURES
ANDROID_ALLOW_UNDEFINED_SYMBOLS
ANDROID_ARM_MODE
ANDROID_ARM_NEON
ANDROID_DISABLE_NO_EXECUTE
ANDROID_DISABLE_RELRO
ANDROID_DISABLE_FORMAT_STRING_CHECKS
ANDROID_CCACHE
And the one ANDROID_TOOLCHAIN_PREFIX
is exactly what I looked for, so my final CMake script comes into below:
add_custom_command(TARGET ${SHARED_LIBRARY_NAME} POST_BUILD
COMMAND "${ANDROID_TOOLCHAIN_PREFIX}strip" -g -S -d --strip-debug --verbose
"${DIST_LIBS_DIR}/${LIB_BUILD_TYPE}/${ANDROID_ABI}/lib${SHARED_LIBRARY_NAME}.so"
COMMENT "Strip debug symbols done on final binary.")
And I don't need to explicitly pass any additional arguments, i.e. DCMAKE_TOOLCHAIN_FILE=android.toolchain.cmake
, from command line to the build process. Because, this file, i.e. android.toolchain.cmake
, was already taken into account automatically by Android native build system.
add a comment |
Thanks @Alex Cohn a lot for pointing out the file android.toolchain.cmake
which usually exists at directory ~/Library/Android/sdk/cmake/cmake_version_xxx/android.toolchain.cmake
on macOS.
There are many useful Android CMake variables already configured inside, e.g.
ANDROID_NDK
ANDROID_TOOLCHAIN
ANDROID_ABI
ANDROID_PLATFORM
ANDROID_STL
ANDROID_PIE
ANDROID_CPP_FEATURES
ANDROID_ALLOW_UNDEFINED_SYMBOLS
ANDROID_ARM_MODE
ANDROID_ARM_NEON
ANDROID_DISABLE_NO_EXECUTE
ANDROID_DISABLE_RELRO
ANDROID_DISABLE_FORMAT_STRING_CHECKS
ANDROID_CCACHE
And the one ANDROID_TOOLCHAIN_PREFIX
is exactly what I looked for, so my final CMake script comes into below:
add_custom_command(TARGET ${SHARED_LIBRARY_NAME} POST_BUILD
COMMAND "${ANDROID_TOOLCHAIN_PREFIX}strip" -g -S -d --strip-debug --verbose
"${DIST_LIBS_DIR}/${LIB_BUILD_TYPE}/${ANDROID_ABI}/lib${SHARED_LIBRARY_NAME}.so"
COMMENT "Strip debug symbols done on final binary.")
And I don't need to explicitly pass any additional arguments, i.e. DCMAKE_TOOLCHAIN_FILE=android.toolchain.cmake
, from command line to the build process. Because, this file, i.e. android.toolchain.cmake
, was already taken into account automatically by Android native build system.
add a comment |
Thanks @Alex Cohn a lot for pointing out the file android.toolchain.cmake
which usually exists at directory ~/Library/Android/sdk/cmake/cmake_version_xxx/android.toolchain.cmake
on macOS.
There are many useful Android CMake variables already configured inside, e.g.
ANDROID_NDK
ANDROID_TOOLCHAIN
ANDROID_ABI
ANDROID_PLATFORM
ANDROID_STL
ANDROID_PIE
ANDROID_CPP_FEATURES
ANDROID_ALLOW_UNDEFINED_SYMBOLS
ANDROID_ARM_MODE
ANDROID_ARM_NEON
ANDROID_DISABLE_NO_EXECUTE
ANDROID_DISABLE_RELRO
ANDROID_DISABLE_FORMAT_STRING_CHECKS
ANDROID_CCACHE
And the one ANDROID_TOOLCHAIN_PREFIX
is exactly what I looked for, so my final CMake script comes into below:
add_custom_command(TARGET ${SHARED_LIBRARY_NAME} POST_BUILD
COMMAND "${ANDROID_TOOLCHAIN_PREFIX}strip" -g -S -d --strip-debug --verbose
"${DIST_LIBS_DIR}/${LIB_BUILD_TYPE}/${ANDROID_ABI}/lib${SHARED_LIBRARY_NAME}.so"
COMMENT "Strip debug symbols done on final binary.")
And I don't need to explicitly pass any additional arguments, i.e. DCMAKE_TOOLCHAIN_FILE=android.toolchain.cmake
, from command line to the build process. Because, this file, i.e. android.toolchain.cmake
, was already taken into account automatically by Android native build system.
Thanks @Alex Cohn a lot for pointing out the file android.toolchain.cmake
which usually exists at directory ~/Library/Android/sdk/cmake/cmake_version_xxx/android.toolchain.cmake
on macOS.
There are many useful Android CMake variables already configured inside, e.g.
ANDROID_NDK
ANDROID_TOOLCHAIN
ANDROID_ABI
ANDROID_PLATFORM
ANDROID_STL
ANDROID_PIE
ANDROID_CPP_FEATURES
ANDROID_ALLOW_UNDEFINED_SYMBOLS
ANDROID_ARM_MODE
ANDROID_ARM_NEON
ANDROID_DISABLE_NO_EXECUTE
ANDROID_DISABLE_RELRO
ANDROID_DISABLE_FORMAT_STRING_CHECKS
ANDROID_CCACHE
And the one ANDROID_TOOLCHAIN_PREFIX
is exactly what I looked for, so my final CMake script comes into below:
add_custom_command(TARGET ${SHARED_LIBRARY_NAME} POST_BUILD
COMMAND "${ANDROID_TOOLCHAIN_PREFIX}strip" -g -S -d --strip-debug --verbose
"${DIST_LIBS_DIR}/${LIB_BUILD_TYPE}/${ANDROID_ABI}/lib${SHARED_LIBRARY_NAME}.so"
COMMENT "Strip debug symbols done on final binary.")
And I don't need to explicitly pass any additional arguments, i.e. DCMAKE_TOOLCHAIN_FILE=android.toolchain.cmake
, from command line to the build process. Because, this file, i.e. android.toolchain.cmake
, was already taken into account automatically by Android native build system.
answered Nov 22 '18 at 1:43


shizhenshizhen
3,14041232
3,14041232
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53409479%2fandroid-ndk-path-variable-for-strip-command-in-cmake-build-tool-chain%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Note that Android Studio (or, to be more exact, the Android Gradle plugin) will strip the shared objects for you. The trick is they perform the strip step later, not as part of CMake.
– Alex Cohn
Nov 21 '18 at 10:08
This is true for application projects, but for library projects with native shared .so, I want to ship a slimmed package rather than leave a heavy bundle to customers.
– shizhen
Nov 21 '18 at 10:17