Skip to content

feat: add Android APK update sample with GeneralUpdate.Avalonia#118

Merged
JusterZhu merged 4 commits into
mainfrom
feat/android-update-sample
Jun 13, 2026
Merged

feat: add Android APK update sample with GeneralUpdate.Avalonia#118
JusterZhu merged 4 commits into
mainfrom
feat/android-update-sample

Conversation

@JusterZhu

Copy link
Copy Markdown
Collaborator

Closes #117

Summary

Adds a new Android APK auto-update sample project at UI/AndroidUpdate/ and modifies the Server to support .apk format downloads.

Key files

  • UI/AndroidUpdate/AndroidUpdate.slnx
  • UI/AndroidUpdate/src/AndroidUpdate.Android/AndroidUpdate.Android.csproj
  • src/Server/Program.cs
  • src/Server/wwwroot/packages/versions.json

Verification

  • Builds with 0 errors
  • APK installs and runs on Honor X30 (Android 14)
  • Server correctly serves .apk files via /File/Download/{hash}
  • End-to-end update flow: check → download → install

JusterZhu and others added 3 commits June 11, 2026 16:58
- Remove UpgradeMode from VerifyDTO and VerificationResultDTO
- Remove UpgradeMode-based filtering and logging in Program.cs

Co-Authored-By: Claude <noreply@anthropic.com>
- Add UI/AndroidUpdate/ sample project (net10.0-android)
  - Avalonia UI with MVVM pattern (CommunityToolkit.Mvvm)
  - Confirmation dialogs for check and download actions
  - Real-time progress bar with percentage display
  - App version read from PackageManager (not hardcoded)
  - Permission check for Android 8+ unknown app sources
- Reference GeneralUpdate.Avalonia.Android via compiled DLL
  (libs/GeneralUpdate.Avalonia.Android.dll)
- Modify Server/Program.cs to support .apk format downloads
  - Use Format field from versions.json for file extension
  - Search both .zip and .apk in hash lookup
  - Support non-.zip file extensions in hash computation
- Add Android platform entry (Platform=4) to versions.json
- Add BaseUrl and Urls config to Server appsettings.json

Co-Authored-By: Claude <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 13, 2026 07:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new Avalonia-based Android sample app that demonstrates APK self-update using GeneralUpdate.Avalonia.Android, and extends the sample server to serve non-.zip package formats (notably .apk) via the existing download-by-hash endpoint.

Changes:

  • Added UI/AndroidUpdate/ Android APK auto-update sample (UI, MVVM, handler abstraction + Android implementation).
  • Updated sample Server download logic to honor package Format/extensions and search .apk packages.
  • Updated server configuration (Urls, BaseUrl) and package metadata (versions.json) to include an Android platform entry.

Reviewed changes

Copilot reviewed 27 out of 29 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
UI/AndroidUpdate/src/AndroidUpdate.Android/Views/MainView.axaml.cs Adds code-behind for the Android sample’s main view.
UI/AndroidUpdate/src/AndroidUpdate.Android/Views/MainView.axaml Implements the update/check/download UI and dialog overlay.
UI/AndroidUpdate/src/AndroidUpdate.Android/ViewModels/ViewModelBase.cs Introduces MVVM base type using CommunityToolkit.
UI/AndroidUpdate/src/AndroidUpdate.Android/ViewModels/UpdatePackageInfo.cs Adds DTO representing server verification response package metadata.
UI/AndroidUpdate/src/AndroidUpdate.Android/ViewModels/MainViewViewModel.cs Implements update flow: verify → download/verify → install.
UI/AndroidUpdate/src/AndroidUpdate.Android/ViewModels/IAndroidUpdateHandler.cs Defines abstraction for platform-specific download/install handler.
UI/AndroidUpdate/src/AndroidUpdate.Android/ViewLocator.cs Adds Avalonia ViewLocator for VM→View mapping.
UI/AndroidUpdate/src/AndroidUpdate.Android/Services/AndroidUpdateHandler.cs Android implementation using GeneralUpdate.Avalonia.Android bootstrap APIs.
UI/AndroidUpdate/src/AndroidUpdate.Android/Resources/xml/network_security_config.xml Adds dev cleartext network policy for local server access.
UI/AndroidUpdate/src/AndroidUpdate.Android/Resources/xml/file_paths.xml Configures FileProvider paths for sharing the downloaded APK.
UI/AndroidUpdate/src/AndroidUpdate.Android/Resources/values/styles.xml Adds theme/splash-related styles for Android.
UI/AndroidUpdate/src/AndroidUpdate.Android/Resources/values/colors.xml Adds splash background color (light).
UI/AndroidUpdate/src/AndroidUpdate.Android/Resources/values-v31/styles.xml Adds Android 12+ splash screen styling.
UI/AndroidUpdate/src/AndroidUpdate.Android/Resources/values-night/colors.xml Adds splash background color (night).
UI/AndroidUpdate/src/AndroidUpdate.Android/Resources/drawable/splash_screen.xml Adds splash screen drawable layer-list.
UI/AndroidUpdate/src/AndroidUpdate.Android/Resources/drawable-v31/avalonia_anim.xml Adds animated vector drawable for splash (v31).
UI/AndroidUpdate/src/AndroidUpdate.Android/Resources/drawable-night-v31/avalonia_anim.xml Adds night variant of animated vector drawable (v31).
UI/AndroidUpdate/src/AndroidUpdate.Android/Properties/AndroidManifest.xml Declares permissions + FileProvider for APK installation.
UI/AndroidUpdate/src/AndroidUpdate.Android/MainActivity.cs Adds Avalonia Android main activity.
UI/AndroidUpdate/src/AndroidUpdate.Android/App.axaml.cs Wires up DI-ish creation of VM + handler factory hook.
UI/AndroidUpdate/src/AndroidUpdate.Android/App.axaml Adds Fluent theme + ViewLocator template registration.
UI/AndroidUpdate/src/AndroidUpdate.Android/AndroidUpdate.Android.csproj Adds Android project config + package refs + GeneralUpdate DLL reference.
UI/AndroidUpdate/src/AndroidUpdate.Android/AndroidApp.cs Initializes handler factory and reads device version via PackageManager.
UI/AndroidUpdate/AndroidUpdate.slnx Adds solution for the new Android sample project.
src/Server/wwwroot/packages/versions.json Adds Android platform entry and .apk format metadata.
src/Server/Program.cs Extends download and package size/hash discovery logic to use Format/.apk.
src/Server/appsettings.json Adds Urls and BaseUrl configuration values.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +204 to +223
if (success)
{
CurrentVersion = _pendingUpdate.Version;
StatusText = $"Updated to v{CurrentVersion}!";
DownloadProgress = 100;
ProgressText = "Done";
}
}
catch (OperationCanceledException)
{
StatusText = "Cancelled.";
}
finally
{
IsDownloading = false;
_cts?.Dispose();
_cts = null;
_currentHandler?.Dispose();
_currentHandler = null;
}
);
}

private static string ServerBaseUrl => "http://192.168.50.204:5000";
Comment thread UI/AndroidUpdate/src/AndroidUpdate.Android/Properties/AndroidManifest.xml Outdated
Comment on lines +4 to +6
<cache-path name="cache" path="update/" />
<cache-path name="cache_root" path="/" />
<files-path name="files" path="update/" />
Comment thread src/Server/appsettings.json Outdated
Comment on lines +6 to +12
public sealed record PackageInfo(
string Version,
string DownloadUrl,
string Sha256,
long FileSize,
string? Description,
bool IsForced);
- Rename PackageInfo to UpdatePackageDto to avoid collision with Android SDK type
- Use TaskCreationOptions.RunContinuationsAsynchronously for dialog TCS
- Restore HasUpdate on download failure so retry is possible
- Reset _pendingUpdate only after successful update
- Replace global cleartext flag with targeted network_security_config
- Tighten FileProvider paths to dedicated update/ subfolder only
- Change BaseUrl to localhost (LAN IP was environment-specific)
- Make ServerBaseUrl configurable via ANDROID_UPDATE_SERVER_URL env var

Co-Authored-By: Claude <noreply@anthropic.com>
@JusterZhu

Copy link
Copy Markdown
Collaborator Author

All 7 review comments have been addressed in commit a160a2b:

  1. ✅ Restore HasUpdate on failure/cancel so retry button reappears
  2. TaskCreationOptions.RunContinuationsAsynchronously for dialog TCS
  3. ServerBaseUrl now configurable via ANDROID_UPDATE_SERVER_URL env var, defaulting to localhost
  4. ✅ Clear text config moved from global flag to targeted network_security_config.xml
  5. ✅ FileProvider paths narrowed to update/ subfolder only
  6. BaseUrl in appsettings.json changed from LAN IP to localhost
  7. PackageInfo renamed to UpdatePackageDto to avoid confusion with Android SDK type

@JusterZhu JusterZhu merged commit 96a89b0 into main Jun 13, 2026
2 checks passed
@JusterZhu JusterZhu deleted the feat/android-update-sample branch June 13, 2026 08:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: add Android APK update sample with GeneralUpdate.Avalonia

2 participants