github_release_apk_updater 1.0.1
github_release_apk_updater: ^1.0.1 copied to clipboard
A Flutter plugin to automatically check for, download, and install updates directly from GitHub releases.
GitHub Release APK Updater #
A Flutter plugin for Android that enables automatic updates by fetching release information directly from a GitHub repository. It handles checking for newer versions, downloading the APK, and launching the installation process. Aditionally, it provides authentication by token to use private repositories.
Features #
- GitHub Release Integration: Fetch latest release metadata (tag, assets, release notes).
- Version Comparison: Built-in semantic versioning comparison between the installed app and the GitHub release.
- Background Downloading: Downloads the APK to a secure local directory using
dio. - Easy Installation: Launches the Android native APK installer directly from your app.
- Customizable UI: Use the library headless to build your own update dialogs.
Getting started #
Android Setup #
- File Provider: You must define a
FileProviderin yourAndroidManifest.xmlto allow the package to share the downloaded APK with the system installer.
<manifest ...>
<application ...>
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
</application>
</manifest>
- File Paths: Create
android/app/src/main/res/xml/file_paths.xml:
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path name="external_files" path="." />
</paths>
Usage #
Create a GitHub tag and release #
- Go to your GitHub repository and navigate to the "Releases" section.
- Click on "Draft a new release".
- Fill in the release details:
- Tag version: Use semantic versioning (e.g.,
v1.0.0). - Release title: A descriptive title for the release.
- Description: Add release notes or changelog information.
- Tag version: Use semantic versioning (e.g.,
- Upload your APK file as an asset by dragging and dropping it into the "Attach binaries by dropping them here or selecting them" area.
- Once everything is filled out, click "Publish release" to make it available.
Simple Update Flow #
import 'package:github_release_apk_updater/github_release_apk_updater.dart';
void checkForUpdates() async {
final updater = GithubReleaseApkUpdater();
final apiService = GitHubApiService(
owner: 'guido-cutipa',
repo: 'dummy-repo',
);
// 1. Get latest release
final latestRelease = await apiService.getLatestRelease();
// 2. Compare versions
final currentVersion = await updater.getCurrentAppVersion();
final hasUpdate = VersionComparator.isNewer(
currentVersion,
latestRelease.tagName.replaceFirst('v', ''),
);
if (hasUpdate) {
// 3. Download APK
final downloader = ApkDownloaderService();
final apkFile = await downloader.downloadApk(
url: latestRelease.assets.first.browserDownloadUrl,
fileName: 'app-update.apk',
);
// 4. Install
await updater.installApk(apkFile.path);
}
}
Example App #
- A complete example app demonstrating the usage of the
github_release_apk_updaterpackage can be found in the [example] - Modify main.dart to include your GitHub repository details and run the app to see the update flow in action.
final ownerGithub = 'guido-cutipa'; // Replace with your owner
final repositoryGithub = 'dummy-repo'; // Replace with your repository
final apkKeyName = '';
dynamic tokenGithub; // optional: only needed for private repos
- Compile and run the example app on an Android device to test the update functionality.
Additional information #
- Repository: https://github.com/dozmaz/github_release_apk_updater
- Issues: https://github.com/dozmaz/github_release_apk_updater/issues
- License: MIT