Can I use Kotlin contracts to validate a minimum Android SDK level?
I’m hoping for something like the following, to encapsulate the version test with the feature test:
Copy code
`at`ExperimentalContracts
fun isMyFeatureSupported(): Boolean {
contract {
// The implies expression fails to build with "Error in contract description: unsupported construction"
returns(true) implies (Build.VERSION.SDK_INT >= BUILD.VERSION_CODES.something)
}
return (Build.VERSION.SDK_INT >= BUILD.VERSION_CODES.something) &&
myFeatureTest()
}
t
tseisel
06/17/2020, 1:19 PM
Are you trying to make the Android linter understand that it is safe to call a method annotated with
@RequiresApi
? I don't think you could do that with Kotlin contracts
That looks awesome, thanks!
I had to update to the 1.2.0-alpha01 version of the annotations library to find it — I wish the Android docs specified which library dependency you need, and the minimum version