android 앱의 최신 버전을 체크하기 위해서 별도의 처리를 하기 번거럽다. 이럴때는 build 시 자동 생성되는 output-metadata.json 파일을 활용하는 방법이 좋은 것같다. 특정 s3 버킷에 다음과 같은 output-metadata.json 파일을 업로드 하여 버전체크를 한다.


{
  "version": 2,
  "artifactType": {
    "type": "APK",
    "kind": "Directory"
  },
  "applicationId": "xxx.yyyy.zzz",
  "variantName": "processReleaseResources",
  "elements": [
    {
      "type": "SINGLE",
      "filters": [],
      "versionCode": 2,
      "versionName": "0.x.x",
      "outputFile": "app-v0.9.11_12.apk"
    }
  ]
}

위 파일을 앱에서 json 읽어 들여 버전 체크를 한다.


private var latestVersionCode: Int? = null

private fun appVersionCheck(verCode: Int) {

    this.latestVersionCode = verCode
    val currentVersionCode: Int = BuildConfig.VERSION_CODE

    if (verCode > currentVersionCode) {
        // 업데이트 필요
    } else {
        // 업데이트 불필요
    }
}