Why androidx.security.crypto.MasterKeys is deprecated?

Viewed 1829

In the android developer's docs reference,here is the url androidx.security.crypto.MasterKeys

I found the MasterKeys class is deprecated and advise to use MasterKey.Builder to work with master keys.

But when i refer to the source code of "MasterKey.Builder" and found that it still call MasterKeys in the end.

I'm confused, why MasterKeys is deprecated but still worked.

3 Answers

An API that is marked deprecated means that it should not be used because it will be most likely removed in the future.

Until the deprecated API has been removed (this can take months or even years) it can be used as before without problems. So not using the deprecated API means that you are prepared for the future.

If you don't want to you can sill use the deprecated API until it has been removed, however when you upgrade to a version that has the API removed you have to adapt your code as compilation breaks. However if you now switch to the new API you are fine and don't have to worry when upgrading the library the next time.

That deprecated class and new class object are basically the same. The latest one follows the builder pattern instead of the constructor for creating a new object of that class. Please give a read this answer https://stackoverflow.com/a/29881683/10436885

Only actualice the implementation library at your build.gradle app inside dependencies with the newer version, at this time is:

implementation "androidx.security:security-crypto:1.0.0-rc04"

implementation "androidx.security:security-identity-credential:1.0.0-alpha02"

https://developer.android.com/jetpack/androidx/releases/security

Related