NDK abiFilters含义

  • Post author:
  • Post category:其他


NDK开发时,在build.gradle中,cmake和ndk都有abiFilters的设置。如下所示:

            cmake {
                cppFlags ""
                abiFilters "armeabi-v7a"
            }
            ndk {
                abiFilters "armeabi-v7a"
            }

它们的含义有所不同。cmake设置的abiFilters会让项目编译时只生成对应abi的so, ndk 设置的abiFilters会成为对应apk的primaryCpuAbi。如果不设置这一项,系统会寻找ro.product.cpu.abilist的值,将ro.product.cpu.abilist的值的第一项(64位处理器手机下为arm64-v8a)作为应用的abi,那么寻找so目录是在lib/arm64/下寻找的。所以,如果设置了cmake的abiFilters为armeabi-v7a,务必把ndk的abiFilters也设置为armeabi-v7a,不然会报以下错误:

--------- beginning of crash
03-24 18:17:52.113  5739  5739 E AndroidRuntime: FATAL EXCEPTION: main
03-24 18:17:52.113  5739  5739 E AndroidRuntime: Process: com.example.inlinehook, PID: 5739
03-24 18:17:52.113  5739  5739 E AndroidRuntime: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.example.inlinehook-ZI6gBWAJBMiKAWoKzcH-hA==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.inlinehook-ZI6gBWAJBMiKAWoKzcH-hA==/lib/arm64, /system/lib64, /vendor/lib64]]] couldn't find "libinlinehook.so"
03-24 18:17:52.113  5739  5739 E AndroidRuntime: 	at java.lang.Runtime.loadLibrary0(Runtime.java:1011)
03-24 18:17:52.113  5739  5739 E AndroidRuntime: 	at java.lang.System.loadLibrary(System.java:1657)
03-24 18:17:52.113  5739  5739 E AndroidRuntime: 	at com.example.inlinehook.MainActivity.<clinit>(MainActivity.java:12)
03-24 18:17:52.113  5739  5739 E AndroidRuntime: 	at java.lang.Class.newInstance(Native Method)
03-24 18:17:52.113  5739  5739 E AndroidRuntime: 	at android.app.Instrumentation.newActivity(Instrumentation.java:1174)
03-24 18:17:52.113  5739  5739 E AndroidRuntime: 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2862)
03-24 18:17:52.113  5739  5739 E AndroidRuntime: 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3054)
03-24 18:17:52.113  5739  5739 E AndroidRuntime: 	at android.app.ActivityThread.-wrap11(Unknown Source:0)
03-24 18:17:52.113  5739  5739 E AndroidRuntime: 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1724)
03-24 18:17:52.113  5739  5739 E AndroidRuntime: 	at android.os.Handler.dispatchMessage(Handler.java:106)
03-24 18:17:52.113  5739  5739 E AndroidRuntime: 	at android.os.Looper.loop(Looper.java:164)
03-24 18:17:52.113  5739  5739 E AndroidRuntime: 	at android.app.ActivityThread.main(ActivityThread.java:7009)
03-24 18:17:52.113  5739  5739 E AndroidRuntime: 	at java.lang.reflect.Method.invoke(Native Method)
03-24 18:17:52.113  5739  5739 E AndroidRuntime: 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
03-24 18:17:52.113  5739  5739 E AndroidRuntime: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
03-24 18:17:52.118   869   900 W ActivityManager:   Force finishing activity com.example.inlinehook/.MainActivity



版权声明:本文为Invoker123原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。