DEV Community

Cover image for Update your App when you release APK on GitHub (using Library)
Sumanth Perambuduri
Sumanth Perambuduri

Posted on • Updated on

Update your App when you release APK on GitHub (using Library)

GitHub logo supersu-man / apkupdater-library

Checks for the latest release in the GitHub repo and if latest apk release is found, it downloads the apk for you.

If you also release APK file with every new release as an asset on GitHub just like me, this could be a very useful Library to you.

Requirements

  • Your App Version name in Gradle and your release Tag version on GitHub needs to be SAME (adding 'v' is optional in GitHub Tag version).

Gradle:

versionName "X.Y"
Enter fullscreen mode Exit fullscreen mode

GitHub Tag version for release:

vX.Y or X.Y
Enter fullscreen mode Exit fullscreen mode
  • Add these lines in top level build.gradle
allprojects {
    repositories {
        /// ....
        maven { url "https://jitpack.io" }
    }
}
Enter fullscreen mode Exit fullscreen mode
  • Add this line in build.gradle
implementation 'com.github.supersu-man:GitHubAPKUpdater-Library:v1.6'
Enter fullscreen mode Exit fullscreen mode

Usage

Usage in one of my Apps here

Simple implementation here

Example

thread {
    val updater = Updater(this, "Link_to_your_repo")
    checkForUpdates(updater)
}
Enter fullscreen mode Exit fullscreen mode
private fun checkForUpdates(updater: Updater) {
    if (updater.isInternetConnection()){
        updater.init()
        updater.isNewUpdateAvailable {
            if (updater.hasPermissionsGranted()){
                updater.requestDownload()
            } else{
                updater.requestMyPermissions {
                    updater.requestDownload()
                }
            }
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Explanation

  • Initializing (use your repo link like this)
val updater = Updater(this,"https://github.com/supersu-man/Macronium/releases/latest")
Enter fullscreen mode Exit fullscreen mode
  • Checking for required Permissions
updater.hasPermissionsGranted()
Enter fullscreen mode Exit fullscreen mode
  • Requesting required permissions (it's WRITE_EXTERNAL_STORAGE here)
updater.requestMyPermissions {
    //Your code after user gives the permission 
}
Enter fullscreen mode Exit fullscreen mode
  • Checking for Internet Connection
updater.isInternetConnection()
Enter fullscreen mode Exit fullscreen mode
  • Checking for New Update (if the version name and latest tag version don't match it detects as new update)
updater.init()
updater.isNewUpdateAvailable {
    //Your code when new update is found in the repo
}
Enter fullscreen mode Exit fullscreen mode
  • Download latest APK
updater.requestDownload()
Enter fullscreen mode Exit fullscreen mode

Oldest comments (0)