How to use *.jar file in native script



I have a third party .jar file(for printing) built in JAVA and I want to include that .jar file in ‘angular 5 + Native Script’ project and use that .jar file classes in Native Script Project. where to and how to place that .jar file in angular5native script


Just place the jar file inside app/App_Resources/android folder and rebuild your project.
The classes of that jar file will be available to your nativescript app.

Another way would be to build a plugin that uses that jar file.


Thanks for the help. I am new to native script. can you just tell me how to rebuild the project


use the cli command for building:
$ tns build android


thank you @jpedraza. I imported the package like this.

const leopardPkg = com.leopard.api;

Now I am getting the error like cannot find the name com . can you tell me how to import the package correctly.


these articles can help you:


with out creating the package can’t we directly import the *.jar file in the angular component


Hi @janardhan, did you find a solution?
I’m in a similar situation, I have a *.jar file and I want to use it in a nativescript-ng project; if you have any suggestion it will be much appreciated.


It must be possible since 4.x


Hi @manojdcoder, thanks for the tip. Still I don’t get how to use the classes/functions from the library/jar file that I added. After the build this is what I got:

Gradle build...
         + setting applicationId
         + applying user-defined configuration from /Users/MYPATH/Garmin/app/App_Resources/Android/app.gradle
         + adding nativescript runtime package dependency: nativescript-optimized-with-inspector
         + adding aar plugin dependency: /Users/MYPATH/Garmin/node_modules/tns-core-modules-widgets/platforms/android/widgets-release.aar
         + adding jar plugin dependency: /Users/MYPATH/Garmin/app/App_Resources/Android/libs/garmin-fleet-api.jar

How can I call the lib? Thanks for any further advice


Access your class / functions with fully qualified names (for example - new com.gramin.some.Classname())


Thanks for your reply @manojdcoder.
I’ve read the link you posted. This is what I’ve tried:

  • installed the tns-platform-declarations
  • create the references.d.ts file to call the tns-platform.declaration for android
  • tried to import the library in different way in the top of my *.ts file, like:

// import { garmin_fleet_api } from "../App_Resources/Android/libs";
// import * as garmin from "../App_Resources/Android/libs";
// var garmin = require("../App_Resources/Android/libs");
  • tried what you suggest

let Serial = new;

this above gave me the error “error TS2304: Cannot find name ‘com’.”

  • tried also something like this

var garmin = new"../App_Resources/Android/libs");

Nothing is working, any suggestion or article?


This is right syntax if your package & class name are correct.

let Serial = new;

Typescript will obviously throw error as it won’t know what is com.garmin..., simply declare

declare var com: any;

at top of the file. If you like to get type declarations for JAR, use this.


Thanks for your quick reply; I’ll have a look! cheers!


I’ve tried different way and path to access the library without success.

Attached here the link to the app with the jar file I’m trying to use.

jar source

I’ve also opened it (added to the *.jar .zip so it’s possible to read the content) and the path is right. trying this:

let serial = new;

reply with error:
ERROR TypeError: Cannot read property 'android' of undefined

also tried a simple class:
let test = new com.garmin.dashcam.VideoProperties("aa", 1, 1, 1);

ERROR TypeError: Cannot read property 'dashcam' of undefined

with or without passing the parameters, same result; it looks like it does not read/access the path or something.


I just cloned your repo and run the project, it works just fine on my end.

Note: I’m using the latest version of CLI. Make sure you run a clean build.


It works, thank you very much for your help @manojdcoder! I forgot that sometimes in this “world” is necessary to delete the famous folders from scratch.