Do you know if there’s any way to prevent the use ...
# android
a
Do you know if there’s any way to prevent the use of part of the native SDK in Android Studio ? For instance, I don’t want developers to be able to use SharedPreferences and want to force them to use another class I made called LocalStorage (or at least give them the deprecated warning)
b
On our team we write custom lint rules to prohibit use of certain classes
In our case, the Android
Log
utility.
k
you can also override getSharedPreferences on your application class
b
Assuming your
LocalStorage
is of type
SharedPreferences
, that is 🙂
Or whatever
getSharedPreferences
returns...
a
LocalStorage wouldn’t be of the type SharedPreferences. But I do think doing it via lint rules is the right call!
b
Feel free to reach out if you're just jumping into lint rules and need guidance -- also utilize the
lint-dev
google group 👍
k
i mean, you can log a warning, throw an exception (not recommended), get creative
perhaps plug into strict mode
b
Any reason you think lint isn't the way to go here @Kris Wong?
Gives you the benefit of finding those issues at build/merge time versus runtime
k
i never said lint is not a good way to go
i would go both ways