mark cerqueira well-rounded nerd

Satisfying the UnsatisfiedLinkError in ReLinker

In the Twitch Android app we leverage some native C++ code. Android’s default PackageManager used to load libraries in these situations is brittle so we leverage ReLinker to provide more robust loading. We recently moved from compiling our C++ externally to setting it as a Gradle dependency and letting Gradle handle compilation.

As we rolled out the update that included this change, we saw a bunch of UnsatisfiedLinkErrors pop up:

The vast majority of these errors were happening on Android 4.x. We didn’t have to look far for a potential solution as ReLinker has an awesome README that mentions that recursive loading can solve intra-library dependencies that the system’s library loader may fail to “on older versions of Android.”

Our theory is that moving from externally compiling the native code to having Gradle do it changed how the library’s dependencies were being packaged and older devices were choking because of this change. So we threw the recursively() method at it and fortunately it solved our problem 100%.