Scene:

You are working on a tricky project whose functionality requires dependency pants (AAR) from several different SDKS. These SDKS use dynamic link libraries, which are known as.so files. Some of their.so files are not their own, they are treasures dug up from open source projects. Called as platform A with the name ADC.so. Platform B also happens to call a dynamic link library named ADC.so. As you are developing diao Fei’s project, you have access to the SDK of platform A and PLATFORM B at the same time. Then the problems are just beginning. A picture is worth a thousand words. Please refer to the description below.





The first thing you need to find out is that it’s not easy. Because you can access the SDK of platform A first and run without any problems. But when you connect to platform B, you start throwing strange errors in so files. It doesn’t throw a conflict problem, and the packaging and compilation work just fine. Throw the following exception at runtime:

E/AndroidRuntime: FATAL EXCEPTION: main  java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "_ZSt14__once_functor" referenced by "libfb.so"...Copy the code

You may be thinking, “I added the libs library libfb.so, and threw _ZSt14__once_functor.” No, decompile to see if apK even has this so file. Unzip it and find it exists. Why would throw such a question, can not understand ah?

It works again after you try to remove the SDK for platform B. Coincidentally, platform B independent demo works. Such questions are not easy to find. But that’s not to say there’s no way. Our solution is not the point, the point is to find the idea of a solution. Let’s go down.


Ideas:

We said before that this problem was caused by the same SO used by both platforms. But we didn’t know that when we first encountered this problem. Here’s my idea:

1. Decompile the APK first. Unpack and check the normal and abnormal APKS. Compare whether SO is really packaged into APK. Explain that dynamically linked libraries packaged into APK for different platforms may have multiple directories. At this point, it depends on which platform the phone is suitable for. Apk does not write all library files to the phone, but only to the current platform. The recommended tool native Libs Monitor can be used to view the library files of the apps currently installed on the phone. Pea pods can be downloaded.

Adb shell cat /proc/cpuinfoCopy the code

2. Compare the SO file between the SDK before integration and the packaged APK. Check to see if there is a public SO.

If there is a common part, we can do as follows

  • 1. Create a separate Module and make the main project depend on the current Module.
  • 2. Integrate SDK in Module.
  • 3. Delete so with repeated comparison. Delete only one copy. Keep a copy of another SDK.
  • 4. Note: Duplicate so cannot be excluded using packagingOptions exclude. Because once exclusion is used, the whole excluded SO cannot be packed in.

Other references to dynamically linked libraries:

Segmentfault.com/a/119000000… Developer.android.com/ndk/index.h…


How can you find me next time?

  • Focus on my Jane book
  • This article synchronizes the Github repository:Github.com/BolexLiu/My…(You can follow)