Nativescript building for a specific API level android


#1

Hey there,

I want to know a bit about the nativescript build process. I have android SDK level 22 installed as I want to build for that platform.

So I create a new app and added the platform using tns plafrom add android --sdk 22

While building I am getting an error nativescript “Install Android SDK Platform 25” failed.

My confusion is that where does platform 25 come in the picture? I added sdk 22 and want to build for it and I have sdk 22 in my Android SDK manager.

Comming from Cordova side of things where there is config.xml where you can change the API level. Is there something similar in Nativescript?

How does this fit in the build proccess?

Thanks


#2

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.


Nativescript “Install Android SDK Platform 25” failed