Skip to main content

native_update 1.2.0 copy "native_update: ^1.2.0" to clipboard
native_update: ^1.2.0 copied to clipboard

Signed over-the-air asset updates, Play in-app update and in-app review for Flutter apps, on Native Update.

native_update #

Signed over-the-air asset updates, Google Play in-app update and in-app review for Flutter apps. It runs on the same Native Update account and licence as the Capacitor, Android and React Native SDKs.

An asset bundle is a ZIP of files your app reads: images, JSON config, copy. It is never Dart code. Store policy doesn't allow a downloaded code change, and the Native Update server never offers a Flutter app a code bundle.

Version 1.2.0
Android minSdk 26. Fully supported and proven on a phone.
iOS Foundation only: in-app review works, and asset updates answer UNAVAILABLE_ON_IOS until a later release
Protocol the same one every Native Update SDK speaks

Install #

dependencies:
  native_update: ^1.2.0

The Android app's minSdk must be 26 or higher.

Use #

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 a file that may have been updated; fall back to the asset in the app.
final path = await NativeUpdate.file('config/flags.json');
final flags = path != null ? File(path).readAsStringSync() : await rootBundle.loadString('assets/config/flags.json');

// Check and download. The new files are used from the next cold start.
final result = await NativeUpdate.checkForUpdate();
if (result case UpdateAvailable(:final info)) await NativeUpdate.download(info);

Publish a bundle with the CLI. Sign it with your private key first:

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) #

From 1.1.0, an app you distribute outside Google Play can also take updates to its Dart code. A build installed from Google Play never asks for one and never loads one, because Play does not allow downloaded code. iOS does not take them.

  1. Make MainActivity extend NativeUpdateFlutterActivity (or NativeUpdateFlutterFragmentActivity when it must be a FlutterFragmentActivity, as local_auth requires). It picks the code to run before the Flutter engine starts.

  2. 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" />
    
  3. In main(), call await NativeUpdate.initFromManifest(); instead of init(...), then notifyAppReady() as usual.

Build the release APK of the new code with the same Flutter version as the installed app, then turn it into a patch:

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

flutter-patch writes patch.zip.runtime-keys beside the patch: the SHA-256 of the APK's libflutter.so. The server offers the patch only to installs running that exact engine and answers RUNTIME_MISMATCH to the rest, so after a Flutter upgrade you ship a new APK first. NativeUpdate.codeUpdatesActive() says whether the running Dart code came from a patch. A patch is the whole compiled Dart program, not a diff, and any APK install sets it aside.

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. Signatures can only be switched off in a debug build.
  • 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.

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.

0
likes
150
points
192
downloads

Documentation

Documentation
API reference

Publisher

unverified uploader

Weekly Downloads

Signed over-the-air asset updates, Play in-app update and in-app review for Flutter apps, on Native Update.

Homepage

Topics

#ota #updates #in-app-update #in-app-review

License

unknown (license)

Dependencies

flutter

More

Packages that depend on native_update

Packages that implement native_update