编译armeabi架构的so

为了减少APP的包大小,通常项目中都只放armeabi一种架构的so库(参考微信),最近有些工作需要放到so中实现,用NDK写好代码编译,发现生成的库只有arm64-v8a, armeabi-v7a, x86, x86_64四种架构,以前打包默认有7中架构的,我在gradle里面配置了armeabi架构再编译,会报如下错误:

ABIs [armeabi] are not supported for platform. Supported ABIs are [arm64-v8a, armeabi-v7a, x86, x86_64]

查了下资料发现从NDK R17开始只支持上面四种架构的so库了,于是去官网下载R16的NDK,然后在项目的local.properties里面指向R16 NDK地址:

ndk.dir=/xxx/Android/sdk/android-ndk-r16b

编译时报错:

"clang" is not able to compile a simple test program. It fails with the following output

意思就是clang是从网上下载的不能直接运行,因为我是mac电脑,浏览器下载的程序不能直接运行,参考下面方法https://www.mobibrw.com/2019/20766
发现还是不行,如果手工挨个去运行NDK里面的程序,又太费时间,还好网上找到了一篇完成通过脚本去修改执行权限 https://blog.csdn.net/hyb1234hi/article/details/106469613 ,把下面的代码保存到NDK根目录,起名叫 xxx.sh,然后运行 sudo sh ./xxx.sh 即可

#!/bin/bash
echo "Resetting Extended Attributes"
sudo xattr -cr toolchains/llvm/prebuilt/darwin-x86_64/bin/clang
sudo xattr -cr toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++
sudo xattr -cr toolchains/llvm/prebuilt/darwin-x86_64/lib64/libc++.dylib
sudo xattr -cr toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/arm-linux-androideabi/bin/ld.bfd
sudo xattr -cr toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/arm-linux-androideabi/bin/ld.gold
sudo xattr -cr toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-objcopy
sudo xattr -cr toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-strip
sudo xattr -cr toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/aarch64-linux-android/bin/ld.bfd
sudo xattr -cr toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/aarch64-linux-android/bin/ld.gold
sudo xattr -cr toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin/aarch64-linux-android-objcopy
sudo xattr -cr toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin/aarch64-linux-android-strip
sudo xattr -cr toolchains/x86-4.9/prebuilt/darwin-x86_64/i686-linux-android/bin/ld.bfd
sudo xattr -cr toolchains/x86-4.9/prebuilt/darwin-x86_64/i686-linux-android/bin/ld.gold
sudo xattr -cr toolchains/x86-4.9/prebuilt/darwin-x86_64/bin/i686-linux-android-objcopy
sudo xattr -cr toolchains/x86-4.9/prebuilt/darwin-x86_64/bin/i686-linux-android-strip
sudo xattr -cr toolchains/x86_64-4.9/prebuilt/darwin-x86_64/bin/x86_64-linux-android-objcopy
sudo xattr -cr toolchains/x86_64-4.9/prebuilt/darwin-x86_64/bin/x86_64-linux-android-strip
echo "Fixing NDK Signing"
sudo codesign --force --deep --sign - toolchains/llvm/prebuilt/darwin-x86_64/bin/clang
sudo codesign --force --deep --sign - toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++
sudo codesign --force --deep --sign - toolchains/llvm/prebuilt/darwin-x86_64/lib64/libc++.dylib
sudo codesign --force --deep --sign - toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/arm-linux-androideabi/bin/ld.bfd
sudo codesign --force --deep --sign - toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/arm-linux-androideabi/bin/ld.gold
sudo codesign --force --deep --sign - toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-objcopy
sudo codesign --force --deep --sign - toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-strip
sudo codesign --force --deep --sign - toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/aarch64-linux-android/bin/ld.bfd
sudo codesign --force --deep --sign - toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/aarch64-linux-android/bin/ld.gold
sudo codesign --force --deep --sign - toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin/aarch64-linux-android-objcopy
sudo codesign --force --deep --sign - toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin/aarch64-linux-android-strip
sudo codesign --force --deep --sign - toolchains/x86-4.9/prebuilt/darwin-x86_64/i686-linux-android/bin/ld.bfd
sudo codesign --force --deep --sign - toolchains/x86-4.9/prebuilt/darwin-x86_64/i686-linux-android/bin/ld.gold
sudo codesign --force --deep --sign - toolchains/x86-4.9/prebuilt/darwin-x86_64/bin/i686-linux-android-objcopy
sudo codesign --force --deep --sign - toolchains/x86-4.9/prebuilt/darwin-x86_64/bin/i686-linux-android-strip
sudo codesign --force --deep --sign - toolchains/x86_64-4.9/prebuilt/darwin-x86_64/bin/x86_64-linux-android-objcopy
sudo codesign --force --deep --sign - toolchains/x86_64-4.9/prebuilt/darwin-x86_64/bin/x86_64-linux-android-strip

你可能感兴趣的:(编译armeabi架构的so)