native_update 1.0.0
native_update: ^1.0.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.0.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.0.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
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.
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.