Tencent / mars

Mars is a cross-platform network component developed by WeChat.
Other
17.17k stars 3.62k forks source link

Conflict with other library JNI libc++_shared.so which is from different NDK version #1284

Open zhlinh opened 1 week ago

zhlinh commented 1 week ago

When import mars-xlog and other library with libc++_shared.so, it encountered with the crash on launch that:

dlopen failed: cannot locate symbol "__emutls_get_address" referenced by
 "/data/app/~~9F9bkWmsoCf0Zx7jUEQu2A==/com.tencent.xriver.debug-I19tY0VOUbMwJzdk9fuJKw==/lib/arm64/libotherlib.so"...

Search the problem, noticed that it's because the mars-xlog use the ndk r20 to build and include the libc++_shared.so with r20 toolchain, which is different with other lib with r25c toolchain.

1. Info

1.1 With the help of parse_elfnote.py mars-xlog: libc++_shared.so

$ parse_elfnote.py libc++_shared.so
----------ABI INFO----------
ABI_ANDROID_API: 21
ABI_NDK_VERSION: r20
ABI_NDK_BUILD_NUMBER: 5594570

other-lib: libc++_shared.so

$ parse_elfnote.py libc++_shared.so
----------ABI INFO----------
ABI_ANDROID_API: 21
ABI_NDK_VERSION: r25c
ABI_NDK_BUILD_NUMBER: 9519653

1.2 See the __emutls_get_address symbol with readelf mars-xlog: libc++_shared.so

$ readelf -s libc++_shared.so | grep __emutls_get_address
Nothing

other-lib: libc++_shared.so

$ readelf -s libc++_shared.so | grep __emutls_get_address
   374: 00000000000ec5bc   448 FUNC    WEAK   DEFAULT   16 __emutls_get_address

So, the problem is the libc++_shared.so on r25c has __emutls_get_address weak symbol, but libc++_shared.so on r20 doesn't.

2. Try To Resolve

Choose libc++_shared.so on r25c will solve this problem, it can be compatitable with the so created by r20 toolchain.

  1. Try to use pickFirst **/libc++_shared.so on gradle packagingOptions. Unfortunately, not working

Not working, becasause it can not be sure choose which so, sometimes choose r25c, it's OK, but sometimes not.

3. Hope

the MARS TEAM

  1. can update the toolchain with r25c or above
  2. or SEPARATED libc++_shared.so on a independent project as mars dependence, apply different version to choose, like
    
    com.tencent.mars:mars-xlog:1.2.5
    - com.tencent.mars:mars-c++_shared:20.0.5594570

then can offer diffrent version of c++shared to choose

wenideveloper commented 1 week ago

这个问题解决了吗,我也遇到了这个冲突问题,引用了Xlog ,又引用了一个其他三方库,就报这个libc++_shared.so冲突 image

zhlinh commented 1 week ago

@wenideveloper have you tried adding pickFirst **/libc++_shared.so in the Gradle packagingOptions?

If your libc++_shared.so is the same NDK version, pickFirst will work.