Features
-
Simple: Out-of box self-update process within ~500L of code
-
Flexible: Decoupled handlers to easily replace
-
Kotlin-ism: The fastest
droidUp {}
builder to configure update within seconds
Installation
AAR
Gradle
// Root build.gradle (/build.gradle)
allprojects {
repositories {
// ...
maven { url 'https://jitpack.io' }
}
}
// Module build.gradle (/app/build.gradle)
dependencies {
implementation 'com.ilharper:droidup:latest.version.here'
// Or use snapshot
// implementation 'com.ilharper:droidup:master-SNAPSHOT'
}
Usage
Quick Setup
Run this after your MainActivity
loaded:
droidUp {
useSimpleChecker("https://my.app/releases")
}.check()
That's it! DroidUp will automatically fetch the update info in background thread, prompt user to get the update when there's new version available, download and verify the apk file and finally install the new app.
Flow & Handlers
DroidUp
calls the following handlers in order:
checker
1. var checker: (DroidUpContext) -> DroidUpInfo
checker
is for handling version checking, and useSimpleChecker()
is the default checker
implementation.
First, put a latest.json
file like this on your static site (e.g. https://my.app/releases/latest.json
):
{
"version": 8, // versionCode
"url": "./app-8.apk", // Can be relative or absolute
"hash": "YVbrfcHla+8RriE+h2qIMavqIq/s0noO8mpIHerDHHxBYRVEgWrVV96CGSx9GbHYCUKw2EMIiCLVsvyjWtshFw==", // SHA512 by default
"size": 60294047, // long
"releaseNote": "Add new features" // Will be displayed in UpdatePrompt dialog
}
We provide droidup-gen to automatically generate latest.json
from apk file.
Then, useSimpleChecker()
to set update source:
droidUp {
+ useSimpleChecker("https://my.app/releases")
}
The URL will be resolved to https://my.app/releases/app-8.apk
.
If you want to check updates using encrypted API, or you have other needs, just implement the checker
yourself, and then
droidUp {
+ checker = myCustomChecker
}
comparator
2. var comparator: (DroidUpContext) -> Boolean
comparator
is used to determine whether the remote version is newer. useSimpleComparator()
is the default comparator
implementation, you don't need to call it manually.
useSimpleComparator()
emits update only when DroidUpInfo.version
> current version.
Use custom comparator
:
droidUp {
+ comparator = myCustomComparator
}
prompter
3. var prompter: (DroidUpContext, () -> Unit) -> Unit
prompter
is for popping update dialog. useSimplePrompter()
is the default prompter
implementation, you don't need to call it manually.
useSimplePrompter()
uses AlertDialog
.
Use custom prompter
for customizing dialog:
droidUp {
+ prompter = myCustomPrompter
}
downloader
4. var downloader: (DroidUpContext, (File) -> Unit) -> Unit
downloader
is for downloading the new apk file. useSimpleDownloader()
is the default downloader
implementation, you don't need to call it manually. It shows a notification with progress when downloading.
Use custom downloader
to use your own download service:
droidUp {
+ downloader = myCustomDownloader
}
verifier
5. var verifier: (DroidUpContext) -> Boolean
verifier
is for checking the hash of the downloaded apk file. useSimpleVerifier()
is the default verifier
implementation, you don't need to call it manually. It uses base64 encoded SHA-512 hash string.
Use custom verifier
:
droidUp {
+ verifier = myCustomVerifier
}
installer
6. var installer: (DroidUpContext) -> Unit
installer
is for installing app. useSimpleInstaller()
is the default installer
implementation, you don't need to call it manually.
Use custom installer
if you want to install apk automatically using ROOT privileges, or you have other needs:
droidUp {
+ installer = myCustomInstaller
}
Advanced
Singleton
It's recommended to use the DroidUp.default
singleton:
DroidUp.default = (DroidUp.default ?: (droidUp {
useSimpleChecker("https://my.app/releases")
})).check()
This way, DroidUp
instance won't be created multiple times.
Manual Check
Use check(true)
to show toast when processing:
droidUp {
useSimpleChecker("https://my.app/releases")
}.check(true)
Explicitly Specify Activity
DroidUp.check()
automatically uses the current activity by default. Use check(activity)
to explicitly specify activity:
droidUp {
useSimpleChecker("https://my.app/releases")
}.check(activity)
Bugs & Issues
Feel free to open issues.
Contributions
PRs are welcome! Feel free to contribute on this project.
Changelog
See releases
LICENSE
MIT