Android11 Hal层链接NDK-Build编译的第三方错误解析

1、错误现象
{
37 error: external/audio_hal_catpure_algorithm/tinyalsa/Android.bp:36:1: dependency “libuvIntf” of “libtinyalsa” missing variant:
38 os:linux_glibc, arch:x86_64, link:shared
39 available variants:
40 os:android, image:vendor.30, arch:arm_armv8-a_cortex-a73, sdk:, link:shared, version:
41 os:android, image:vendor.30, arch:arm_armv8-a_cortex-a73, sdk:, link:static, version:
42 ninja: build stopped: subcommand failed.
}

 37 error: external/audio_hal_catpure_algorithm/tinyalsa/Android.bp:36:1: dependency "libuvIntf" of "libtinyalsa" missing variant:
 38   os:linux_glibc, arch:x86_64, link:shared
 39 available variants:
 40   os:android, image:vendor.30, arch:arm_armv8-a_cortex-a73, sdk:, link:shared, version:
 41   os:android, image:vendor.30, arch:arm_armv8-a_cortex-a73, sdk:, link:static, version:
 42 ninja: build stopped: subcommand failed.

从错误表现看,os,arch,image不匹配,
通过file命令查看对应库的属性:

file libuvIntf
libuvIntf.so: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, BuildID[sha1]=72762bbb9a74890fd9fd6214f7fa32c01e52e8a5, stripped

file libtinyalsa.so
libtinyalsa.so : ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /system/bin/linker, stripped

通过属性上看,两者属性上是没有什么区别的,怎么看都像是Android.bp里面配置不对

下面是原始出错条件下的配置;

  cc_prebuilt_library_shared {
      name: "libuvIntf",
      srcs: ["yuer/algorithm/algorithm/android/lib/libuvIntf.so"],
  }
  
  cc_library {
      name: "libtinyalsa",
      host_supported: true,
      vendor_available: true,
      vndk: {
          enabled: true,
      },
	  shared_libs: ["libutils", "libbase", "libbinder", "liblog", "libcutils", "libuvIntf"],
}

问题折腾了挺久的,网上关于这方面的说法特别少,有类似问题的也对问题解决没有分析说明,

下面是解决后的配置:

  cc_prebuilt_library_shared {
      name: "libuvIntf",
      vendor_available: true,  //表示image属性,该库包含于vendor.img,由vendor使用
      host_supported: true,  //创建一个以主机为目标的库,这句话什么意思没明白,网上没有直观的说法
      vndk: {
          enabled: true, //表示image属性,该库包含于system.img,由vendor使用
      },
      srcs: ["yuer/algorithm/algorithm/android/lib/libuvIntf.so"],
  }
  cc_library {
      name: "libtinyalsa",
      host_supported: true,
      vendor_available: true,
      vndk: {
          enabled: true,
      },
	  shared_libs: ["libutils", "libbase", "libbinder", "liblog", "libcutils", "libuvIntf"],
}

Android.bp中关于vendor配置参考链接

从上面看,大家在给系统添加第三方用ndk-build或者交叉编译的库时,配置cc_prebuilt_library_shared时,一定要和主依赖该库的对象保持一致的编译配置,这样才能保障两者会是同样的属性,也就是os、image、arch保持一致。

你可能感兴趣的:(Android11,android,android,studio,java)