NativeScript for Mobile App Development Plugins and Native API Access 1 — Questions and Answers
Question 1: Where is the primary marketplace for NativeScript plugins?
- market.nativescript.org (Correct answer)
- npmjs.com (prefix @nativescript/)
- plugins.nativescript.io
- nativescript-plugins.com
Correct answer: market.nativescript.org
market.nativescript.org is the official plugin marketplace where community and official plugins are listed and rated.
Question 2: Which NativeScript plugin provides camera access?
- @nativescript/camera (Correct answer)
- nativescript-camera-plugin
- @nativescript/media
- ns-camera
Correct answer: @nativescript/camera
@nativescript/camera is the official plugin that wraps native camera APIs for taking photos and accessing the photo library.
Question 3: What file in a NativeScript plugin defines Android-specific Gradle dependencies?
- include.gradle (Correct answer)
- android.gradle
- build.gradle (plugin root)
- dependencies.gradle
Correct answer: include.gradle
The `include.gradle` file in the plugin's platforms/android folder specifies Android dependencies that are merged into the app's Gradle build.
Question 4: How do you access a raw native Android API class from NativeScript JavaScript?
- Reference it by its fully qualified Java class name (e.g., android.content.Intent) (Correct answer)
- Import it from '@nativescript/core'
- Use require('android')
- Call ns.android.import()
Correct answer: Reference it by its fully qualified Java class name (e.g., android.content.Intent)
NativeScript's metadata system exposes native Android classes globally by their Java package names, so you can write `new android.content.Intent()` directly.
Question 5: Which file in a NativeScript plugin lists iOS frameworks and Podfile dependencies?
- Podfile (in platforms/ios/) (Correct answer)
- ios.config.json
- include.xcconfig
- frameworks.plist
Correct answer: Podfile (in platforms/ios/)
A Podfile in the plugin's platforms/ios directory specifies CocoaPods dependencies that NativeScript merges during iOS builds.
Question 6: What is the purpose of the `tns-platform-declarations` npm package?
- Provides TypeScript type definitions for native iOS and Android APIs (Correct answer)
- Generates native platform code stubs
- Compiles TypeScript to native code
- Manages platform SDK versions
Correct answer: Provides TypeScript type definitions for native iOS and Android APIs
tns-platform-declarations contains d.ts type definition files for Android and iOS native APIs, enabling TypeScript IntelliSense when calling native APIs.
Where is the primary marketplace for NativeScript plugins?