Mobile Development 8 min read

Asynchronous Loading of Android .so Libraries: Problems, Solutions, and Best Practices

This article examines the challenges of loading large third‑party .so libraries in Android apps, analyzes traditional and advanced asynchronous loading methods, discusses dependency and text‑relocation issues, and presents practical solutions and implementation steps to reduce package size while maintaining stability.

TAL Education Technology
TAL Education Technology
TAL Education Technology
Asynchronous Loading of Android .so Libraries: Problems, Solutions, and Best Practices

In mobile development, integrating third‑party SDKs often brings large native .so libraries that increase the app package size, prompting the need for asynchronous network loading of these libraries.

Traditional approach : download the .so to the sandbox, then load it with System.load . However, this can fail when dependent libraries are missing, e.g., loading libunity.so without first loading libmain.so results in java.lang.UnsatisfiedLinkError: dlopen failed: library "libmain.so" not found .

Root cause analysis shows that native libraries have dependency relationships that must be resolved in order. Tools like SoLoader and ReLinker parse ELF headers to load dependencies recursively.

Extended thinking : controlling load order can be achieved by parsing ELF dependencies and loading them recursively before the target library.

Text relocations issue : loading liblbs.so may trigger java.lang.UnsatisfiedLinkError: dlopen failed: … has text relocations , which requires either rebuilding the library without text relocations or lowering targetSdkVersion as a temporary workaround.

Advanced solution : use Tencent's Tinker to prepend a custom native library path via reflection, ensuring the external .so is loaded before any same‑named library in the app bundle. Example code resides in com.tencent.tinker.lib.library.TinkerLoadLibrary.java .

Project application : identify which .so files are needed for specific features, intercept System.loadLibrary calls with an aspect‑oriented plugin (e.g., gradle_plugin_android_aspectjx ) to log usage, and configure asynchronous loading rules via JSON.

Handling user experience : intercept activity start to show a loading dialog, ensure the dialog is dismissed properly, and consider fallback mechanisms for network variability.

Packaging optimization : exclude unnecessary .so files in build.gradle and hook the build process to keep configuration and packaging in sync.

Summary : The presented asynchronous loading strategy offers low‑intrusion integration, reduces APK size, and can be extended with custom rules, but still requires attention to dependency ordering, text‑relocation constraints, and compatibility with future Android versions.

Mobile DevelopmentAndroidNative LibrariesTinkerAsynchronous Loadingsystem loadSoLoader
TAL Education Technology
Written by

TAL Education Technology

TAL Education is a technology-driven education company committed to the mission of 'making education better through love and technology'. The TAL technology team has always been dedicated to educational technology research and innovation. This is the external platform of the TAL technology team, sharing weekly curated technical articles and recruitment information.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.