You need to put it in gradle.properties
file which is present at the project level, outside of the app folder not in build.gradle
file which you are currently trying to do.
From the android developer documentation
Better debug info when using obsolete API: When the plugin detects that you’re using an API that’s no longer supported, it can now provide more-detailed information to help you determine where that API is being used. To see the additional info, you need to include the following in your project’s gradle.properties file:
android.debug.obsoleteApi=true
You can also enable the flag by passing -Pandroid.debug.obsoleteApi=true from the command line.
You can check this Link.