An Android library that checks for app updates.
- Add Jitpack to your project
repositories {
...
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.Sharkaboi:AppUpdateChecker:<Latest version>'
}
val updateChecker = AppUpdateChecker(
// Any of the sources mentioned below
source = <AppUpdateCheckerSource<*>>(
... // params,
currentVersion = "v1.0.0"
)
)
This is so that you can instantiate with your existing DI setup.
Github public API has rate limit as mentioned here.
GithubTagSource(
ownerUsername = "Sharkaboi",
repoName = "AppUpdateChecker",
currentVersion = "v1.0.0"
)
Github authenticated API has higher rate limit. Check github's docs to obtain a token.
GithubTagSource(
ownerUsername = "Sharkaboi",
repoName = "AppUpdateChecker",
currentVersion = "v1.0.0",
bearerToken = "<MY TOKEN>"
)
FDroidVersionNameSource(
packageName = "com.sharkaboi.appupdatechecker",
currentVersion = "v1.0.0"
)
FDroidVersionCodeSource(
packageName = "com.sharkaboi.appupdatechecker",
currentVersion = 10100
)
JsonVersionNameSource(
jsonEndpoint = "https://mywebsite.com/version.json",
currentVersion = "v1.0.0"
)
JSON structure supported by default :
{
"latestVersionName": "v1.2",
"latestVersionUrl": "https://mywebsite.com/v1.2",
"releaseNotes": "My epic changelog"
}
JsonVersionCodeSource(
jsonEndpoint = "https://mywebsite.com/version.json",
currentVersion = 10100
)
JSON structure supported by default :
{
"latestVersionCode": 10102,
"latestVersionUrl": "https://mywebsite.com/v1.2",
"releaseNotes": "My epic changelog"
}
XMLVersionNameSource(
xmlEndpoint = "https://mywebsite.com/version.xml",
currentVersion = "v1.0.0"
)
XML structure supported by default :
<version>
<latestVersionName>v1.2</latestVersionName>
<latestVersionUrl>https://mywebsite.com/v1.2</latestVersionUrl>
<releaseNotes>My epic changelog</releaseNotes>
</version>
XMLVersionCodeSource(
xmlEndpoint = "https://mywebsite.com/version.xml",
currentVersion = 10100
)
XML structure supported by default :
<version>
<latestVersionCode>10102</latestVersionCode>
<latestVersionUrl>https://mywebsite.com/v1.2</latestVersionUrl>
<releaseNotes>My epic changelog</releaseNotes>
</version>
class CustomVersionSource(
override val currentVersion: String,
override var versionComparator: VersionComparator<String> = DefaultStringVersionComparator
) : AppUpdateCheckerSource<String>() {
private val customSource = "https://mywebsite.com/latestVersion"
override suspend fun queryVersionDetails(): VersionDetails<String> {
// Do your processing to fetch from source here
...
// Handle exceptions if needed here, wrap with AppUpdateCheckerException if needed
return VersionDetails(
latestVersion = version,
latestVersionUrl = "https://mywebsite.com/download.apk",
releaseNotes = null
)
}
}
viewModelScope.launch {
val result = updateChecker.checkUpdate()
// or
val deferred = updateChecker.checkUpdateAsync()
val result = deferred.await()
when (result) {
// Update found
is UpdateResult.NoUpdate -> println(result.versionDetails.toString())
// Already has the latest version installed
UpdateState.NoUpdate ->..
}
}
if (throwable is AppUpdateCheckerException) {
when (throwable) {
is GenericError -> {
// Generic errors (network, ssl, parse)
}
is InvalidEndPointException -> {
// Invalid endpoint passed for sources with endpoints (json/xml)
}
is InvalidPackageNameException -> {
// Invalid package name passed
}
is InvalidRepositoryNameException -> {
// Invalid repository name passed
}
is InvalidUserNameException -> {
// Invalid username passed
}
is InvalidVersionException -> {
// Invalid version format for default version name comparator
}
is PackageNotFoundException -> {
// Remote Service returned 404
}
is RemoteError -> {
// Other remote server error code
}
}
}
val source = JsonVersionNameSource(
jsonEndpoint = "https://mywebsite.com/version.json",
currentVersion = "v1.0-alpha"
)
val customVersionComparator = object : VersionComparator<String> {
override fun isNewerVersion(
currentVersion: String,
newVersion: String
): Boolean {
// Perform custom logic here or can use default comparators provided with library.
return DefaultStringVersionComparator.isNewerVersion(
currentVersion.substringBefore('-'),
newVersion.substringBefore('-')
)
}
}
source.setCustomVersionComparator(customVersionComparator)
val testChecker = AppUpdateChecker(source = source)
val result = testChecker.checkUpdate()
...
- Kotlin
- Coroutines
- Retrofit
- Moshi
- SimpleXML
This project is heavily inspired by javiersantos/AppUpdater. The project had been stale for a while and had been on AsyncTasks so decided to write my own library.
Of course, the library is very early stage and doesn't have all the features but is WIP.
See the open issues for a list of proposed features (and known issues).
PR's are welcome. Please try to follow the template.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
MIT License
Copyright (c) 2021 Sarath S
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.