Flutter
native_update brings Native Update to Flutter apps, on the same
account, licence and dashboard as the Capacitor plugin.
What it updates: an asset bundle, a ZIP of files your app reads (images, JSON config, copy), on every install. From 1.1.0, an app you distribute outside Google Play can also take updates to its Dart code (below). A build installed from Google Play never asks for one.
| Package | native_update |
|---|---|
| Version | 1.2.0 |
| Android | minSdk 26; fully supported |
| iOS | foundation only: in-app review works, and asset updates answer UNAVAILABLE_ON_IOS for now |
Install
dependencies:
native_update: ^1.2.0
Set the Android app's minSdk to 26 or higher. The plugin declares the INTERNET permission itself.
Start it
Call init in main(), before any screen reads an updated file:
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await NativeUpdate.init(const NativeUpdateConfig(
serverUrl: 'https://nativeupdatebe.aoneahsan.com/api',
apiKey: String.fromEnvironment('NU_API_KEY'), // the app's nu_app_ key
publicKey: String.fromEnvironment('NU_PUBLIC_KEY'), // verifies every bundle
));
runApp(const MyApp());
}
Once the first screen works, on every start:
await NativeUpdate.notifyAppReady();
Read updated files
final path = await NativeUpdate.file('config/flags.json');
final flags = path != null
? File(path).readAsStringSync()
: await rootBundle.loadString('assets/config/flags.json');
file() returns the updated copy, or null when the active bundle doesn't have it. In that case use the asset
built into the app.
Check and download
final result = await NativeUpdate.checkForUpdate();
switch (result) {
case UpdateAvailable(:final info):
await NativeUpdate.download(info); // used from the next cold start
case NativeUpdateRequired():
// ask for a store update
case UpToDate() || UpdateHeld():
break;
}
download(info, activation: Activation.now) switches straight away instead.
Publish a bundle
npx native-update bundle sign ./bundle.zip --key ./private.pem
npx native-update deploy ./bundle.zip --app com.example.app --version 1.0.1 --payload-type assets --wait
Dart code updates (sideloaded Android builds)
Play does not allow apps to download code, so this is for apps you hand out yourself: a direct APK download, an enterprise rollout, a test group. A build installed from Google Play never asks for a code patch and never loads one, even with the switch on. iOS does not take them.
-
Make
MainActivityextendNativeUpdateFlutterActivity, orNativeUpdateFlutterFragmentActivitywhen it must be aFlutterFragmentActivity(aslocal_authrequires). It picks the Dart code to run before the Flutter engine starts, so a bad patch can never stop the app from starting. -
Put the configuration in
android/app/src/main/AndroidManifest.xml, inside<application>:<meta-data android:name="com.aoneahsan.native_update.SERVER_URL" android:value="https://nativeupdatebe.aoneahsan.com/api" /><meta-data android:name="com.aoneahsan.native_update.API_KEY" android:value="nu_app_..." /><meta-data android:name="com.aoneahsan.native_update.PUBLIC_KEY" android:value="MIIC..." /><meta-data android:name="com.aoneahsan.native_update.CODE_UPDATES" android:value="true" /> -
In
main(), callawait NativeUpdate.initFromManifest();instead ofinit(...), thennotifyAppReady()once the app is up, as with asset bundles.
To ship new Dart code, build a release APK of it with the same Flutter version as the installed app, then:
npx native-update bundle flutter-patch build/app/outputs/flutter-apk/app-release.apk -o patch.zip
npx native-update deploy patch.zip --app com.example.app --version 1.0.2 --payload-type dart_aot --wait
How it behaves:
- One engine per patch.
bundle flutter-patchrecords the SHA-256 of the APK'slibflutter.soinpatch.zip.runtime-keys. The server offers the patch only to installs running that engine and answersRUNTIME_MISMATCHto the rest. After a Flutter upgrade, ship a new APK first. - Whole program, not a diff. A patch is the complete compiled Dart code. Any APK install sets it aside, even one
that kept
versionCodeandversionName, so a patch never outlives the APK it was built from. - Same checks as asset bundles. SHA-256 and RSA-SHA256 before the engine starts, rollback after two starts without
notifyAppReady(), and a rolled-back version is not offered to that device again. NativeUpdate.codeUpdatesActive()says whether the running Dart code came from a patch.
What it guarantees
- Integrity: a bundle is used only after its SHA-256 matches and its RSA-SHA256 signature verifies. Both are checked again on every cold start.
- Safety: unpacking refuses any entry that escapes its folder (Zip-Slip) and anything over the size limits.
- Rollback: a new bundle that hasn't reached
notifyAppReady()within two cold starts is rolled back, and that bundle is never offered to that device again. - New binary: a store or sideload update retires bundles made for the older build. With code updates on, any APK install retires them.
- Delta downloads (1.2.0+): when the device runs a version the server still holds, it downloads a small
NUDELTA/1patch and rebuilds the new bundle from the current one, then checks it exactly like a full download. Any problem falls back to the full download.
Play in-app update and review
await NativeUpdate.startPlayImmediateUpdate(); // immediate flow only
if (NativeUpdate.shouldAskForReview(successes: wins, lastAsked: lastAsked, now: DateTime.now())) {
await NativeUpdate.requestPlayReview();
}
A build installed from outside Google Play gets PlayUpdateOutcome.notPlayInstall. Send those people to your own
download page instead.