安卓so库对应的ndk版本查看以及strip命令的使用
本人的电脑为mac,所以只谈mac
使用file命令
file libc++_shared.so
输出:
libc++_shared.so: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, BuildID[sha1]=e2abf2cdb6028797b0eae31bedb64809ae86fed1, with debug_info, not stripped
可以看到该so库为64位,含有调试信息
使用readelf查看ndk版本
如何找到readelf命令?
- 请至android sdk根目录,比如我的mac上sdk根目录是在/Users/admin/Library/Android/sdk
admin@C02D7132MD6R sdk % pwd
/Users/admin/Library/Android/sdk
cd到sdk根目录开始使用find命令查找,因为我要查找64位的,所以就使用grep过滤了以下
find . -name "*readelf"|grep arch64
./ndk/17.2.4988734/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/aarch64-linux-android/bin/readelf
./ndk/17.2.4988734/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin/aarch64-linux-android-readelf
./ndk/16.1.4479499/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/aarch64-linux-android/bin/readelf
./ndk/16.1.4479499/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin/aarch64-linux-android-readelf
./ndk/22.0.7026061/toolchains/llvm/prebuilt/darwin-x86_64/aarch64-linux-android/bin/readelf
./ndk/22.0.7026061/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android-readelf
./ndk/22.0.7026061/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/aarch64-linux-android/bin/readelf
./ndk/22.0.7026061/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin/aarch64-linux-android-readelf
./ndk/21.0.6113669/toolchains/llvm/prebuilt/darwin-x86_64/aarch64-linux-android/bin/readelf
./ndk/21.0.6113669/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android-readelf
./ndk/21.0.6113669/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/aarch64-linux-android/bin/readelf
./ndk/21.0.6113669/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin/aarch64-linux-android-readelf
当前我的ndk版本有16,17,21,22,我习惯用最新的readelf命令,从上可知ndk22下面的readelf命令其实都是可用的,随便选择一个:
执行readelf命令,查看so库的ndk版本
./ndk/22.0.7026061/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/aarch64-linux-android/bin/readelf -p ".comment" libc++_shared.so
String dump of section '.comment':
[ 0] Android (5900059 based on r365631c) clang version 9.0.8 (https://android.googlesource.com/toolchain/llvm-project 207d7abc1a2abf3ef8d4301736d6a7ebc224a290) (based on LLVM 9.0.8svn)
[ b4] GCC: (GNU) 4.9.x 20150123 (prerelease)
Clang version 9.0.8对应的ndk版本其实就是ndk21,我们可以验证一下
验证clang版本与ndk的对应关系
1.使用find命令,查找当前sdk根目录下面的所有clang可执行文件
admin@C02D7132MD6R sdk % find . -name clang |grep bin
./ndk/17.2.4988734/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang
./ndk/16.1.4479499/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang
./ndk/22.0.7026061/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang
./ndk/21.0.6113669/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang
./ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang
2.先看看ndk16的clang版本为多少呢? Android clang version 5.0.300080
admin@C02D7132MD6R sdk % ./ndk/16.1.4479499/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang -v
Android clang version 5.0.300080 (based on LLVM 5.0.300080)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Users/admin/Library/Android/sdk/./ndk/16.1.4479499/toolchains/llvm/prebuilt/darwin-x86_64/bin
3.再看看ndk21的clang版本为多少?Android (5900059 based on r365631c) clang version 9.0.8
admin@C02D7132MD6R sdk % ./ndk/21.0.6113669/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang -v
Android (5900059 based on r365631c) clang version 9.0.8 (https://android.googlesource.com/toolchain/llvm-project 207d7abc1a2abf3ef8d4301736d6a7ebc224a290) (based on LLVM 9.0.8svn)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Users/admin/Library/Android/sdk/./ndk/21.0.6113669/toolchains/llvm/prebuilt/darwin-x86_64/bin
所以本人测试所用的libc++_shared.so为ndk21对应的so库
使用strip命令将调试信息清除,减小so库大小
如何在sdk根目录找到strip命令
同样的在sdk根目录中去搜索
admin@C02D7132MD6R sdk % find . -name "*-strip" |grep arch64
./ndk/17.2.4988734/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin/aarch64-linux-android-strip
./ndk/16.1.4479499/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin/aarch64-linux-android-strip
./ndk/22.0.7026061/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android-strip
./ndk/22.0.7026061/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin/aarch64-linux-android-strip
./ndk/21.0.6113669/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android-strip
./ndk/21.0.6113669/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin/aarch64-linux-android-strip
./ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android-strip
./ndk-bundle/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin/aarch64-linux-android-strip
找到后可使用ndk21下面的strip命令
admin@C02D7132MD6R sdk % ./ndk/21.0.6113669/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android-strip -s libc++_shared.so -o libc++_shared.so.strip
再次使用file命令查看libc++_shared.so.strip文件信息
admin@C02D7132MD6R sdk % file libc++_shared.so.strip
libc++_shared.so.strip: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, BuildID[sha1]=e2abf2cdb6028797b0eae31bedb64809ae86fed1, stripped
我们看看strip前后文件的大小
admin@C02D7132MD6R sdk % ls -al libc++*
-rw-r--r-- 1 admin staff 6245712 3 15 13:20 libc++_shared.so
-rwxr-xr-x 1 admin staff 919888 3 15 13:42 libc++_shared.so.strip
是不是strip后文件大小 小了许多呢