Short version:
Add a platform - tns platform add android
State desired compileSdk during build - tns run android --compileSdk 22 or tns build android --compileSdk 22
Longer version:
Adding the android platform to a {N} project only creates the android-studio-project structure. When the gradle script is invoked, the {N} CLI will pass along compileSdk, targetSdk, support libraries version flags to the build.
So doing tns platform add android is enough to bootstrap the project structure.
When building/running your project: By default, the CLI reads the $ANDROID_HOME/platforms directory to see what Android API level sdks are installed, and will work with the latest supported version. Say if I had android-22, android-23, android-25, android-26, the project will be built against compileSdk 26. If, your latest installed is android-22, then that will be the version your android project will be built against.
But what if you have other platform levels installed? Well, when building/running an android project, you can supply the --compileSdk flag followed by your desired version, and the gradle build will pick that up.
tns run android --compileSdk 22 is what you should run to get the desired results in your case, I assume.
Alternatively, you could override any, or at least most of the Android settings by writing gradle configuration inside the app/App_Resources/Android/app.gradle script, where changes are persistent.
Copied response from https://discourse.nativescript.org/t/nativescript-building-for-a-specific-api-level-android/2140/2?u=pete.k