Android SDK 28 - versionCode in PackageInfo has been deprecated

前端 未结 4 954
既然无缘
既然无缘 2021-01-07 16:08

I just upgraded my app\'s compileSdkVersion to 28 (Pie).

I\'m getting a compilation warning:

warning: [deprecation]

4条回答
  •  长情又很酷
    2021-01-07 16:47

    It says what to do on the Java doc (I recommend not using the Kotlin documentation for much; it's not really maintained well):

    versionCode

    This field was deprecated in API level 28. Use getLongVersionCode() instead, which includes both this and the additional versionCodeMajor attribute. The version number of this package, as specified by the tag's versionCode attribute.

    This is an API 28 method, though, so consider using PackageInfoCompat. It has one static method:

    getLongVersionCode(PackageInfo info)
    

提交回复
热议问题