Mobile Development 12 min read

How to Dynamically Update Flutter Android Apps Without Releasing New APKs

This article explains how to dynamically replace the Dart libapp.so library and asset resources in a Flutter Android app by modifying the AOT_SHARED_LIBRARY_NAME argument and using AssetManager reflection, enabling hot updates without publishing a new APK.

NetEase Media Technology Team
NetEase Media Technology Team
NetEase Media Technology Team
How to Dynamically Update Flutter Android Apps Without Releasing New APKs

Dynamic Dart Code Loading

From Flutter 1.7.8 the compiled Dart code is packaged as libapp.so. The engine loads the library based on the argument --AOT_SHARED_LIBRARY_NAME=... passed to FlutterLoader.ensureInitializationComplete. By supplying a custom argument before the engine adds its default entry, the custom path takes precedence.

Injecting a custom library path

Subclass FlutterActivity and override getFlutterShellArgs() to add the argument that points to a downloaded libapp.so file:

public class MyDynamicFlutterActivity extends FlutterActivity {
    @Override
    public FlutterShellArgs getFlutterShellArgs() {
        FlutterShellArgs args = FlutterShellArgs.fromIntent(getIntent());
        args.add("--AOT_SHARED_LIBRARY_NAME=/sdcard/dynamic/libapp.so");
        return args;
    }
}

The overridden method is called during activity creation, the argument is placed into shellArgs, and the native engine loads the library from the supplied absolute path.

Dynamic Asset Loading

Flutter loads assets through the platform channel flutter/assets. The native side uses APKAssetProvider::GetAsMapping, which ultimately calls AAssetManager_open on the AssetManager. Adding a new asset directory at runtime can be done via reflection on AssetManager.addAssetPath:

AssetManager assetManager = context.getAssets();
Method addAssetPath = assetManager.getClass()
        .getMethod("addAssetPath", String.class);
addAssetPath.setAccessible(true);
addAssetPath.invoke(assetManager, downloadedAssetPath);

Requirements for the added path:

The path must be a compressed zip (APK‑style) containing a valid AssetManifest.json and an AndroidManifest.xml.

Use the FlutterActivity context, not the application context, because the native engine binds to the activity’s AssetManager.

On some devices (e.g., Huawei Honor 9) an extracted directory fails; a zip file works reliably.

Practical Workflow

Build the original APK (e.g., app-old.apk).

Build a new APK with updated libapp.so and changed assets (e.g., app-new.apk).

Run a diff script to extract only the changed files: the new libapp.so, updated AssetManifest.json, AndroidManifest.xml, and any new image assets.

Package the extracted files into bundle.zip.

Distribute bundle.zip to devices that have the old APK. After verifying the bundle, load the new libapp.so via the overridden activity and invoke the reflection code to add the new asset path.

This approach updates UI elements (e.g., tab icons and labels) instantly without a full APK upgrade.

Considerations

The bundle size can be large; differential packaging (e.g., using Tinker) reduces traffic.

The method works only on Android; iOS does not allow native library path replacement.

Ensure the added asset bundle includes a correct AssetManifest.json so Flutter can resolve density‑specific variants.

Include an AndroidManifest.xml in the bundle; otherwise addAssetPath may fail on certain devices.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

FlutterAndroidDynamic LoadingHot Updateasset managementlibapp.so
NetEase Media Technology Team
Written by

NetEase Media Technology Team

NetEase Media Technology Team

0 followers
Reader feedback

How this landed with the community

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.