Skip to content

Latest commit

 

History

History
56 lines (40 loc) · 2.14 KB

File metadata and controls

56 lines (40 loc) · 2.14 KB
nav-title title description position
Simple Jar Libs
Simple Jar Libs
NativeScript Android Runtime Requirements
1

Overview

Often Android projects use third-party libraries in order to provide and/or consume application functionality. NativeScript for Android supports this scenario as well. In this article you will learn how to add JAR libraries to your NativeScript for Android project.

Adding JAR libraries

One of the most common formats in which third-party libraries for Android are distributed is ordinary JAR file. Adding one or more JAR files to your NativeScript for Android project is done through tns command tool.

For the purpose of this article we assume that you alredy setup an Android project.

tns create <project_name>
tns platform add android <project_name>

You can add one or more JAR files to your NativeScripr for Android project with the following commnad.

tns library add android <path_to_dir>

This command will read all JAR files from <path_to_dir> folder and will add reference to them in your project. As a result, this will create a new folder lib which is sibling to already existing app and platforms.

<project_name>
|--app
|--platforms
<project_name>
|--app
|--lib
   |--Android
|--platforms

The newly created lib folder will contain a copy of the third-party libraries. The libraries in this folder will be referenced from your project.

Generate metadata

Once yoy added third-party libraries to your project, you have to generate metadata. Generating metadata is part from build command.

tns build android

The metadata is the key piece that allows you to instantiate and use the Java classes defined in the third-party libraries. It contains information what packages, types and methods are defined in the JAR libraries. The metadata files are located in <project_name>/platforms/android/assets/metadata/ folder.

Metadata alone is not enought to use third-party libraries. Your libraries must become part of the *.apk file that you will deploy. To make this possilbe the build command copies the JAR files in <project_name>/platforms/android/libs/ folder.