Import jar file using nativescript


A’m trying to import a jar file in my nativescript angular project, the path i placed the jar file is platform/android/app/libs/Myjar.jar .
After that i invoked that jar using my java file like import com.tns.ptouch.sdk.Printer. But i couldnt compile the script. Error occured is package path is not valid. Any help or lead will be appreciated.


Are you trying to add your jar to the complied project in the platforms folder? I think you must do it through plugin, you may use plugin seed to get started or if you don’t have a plan to reuse them then you can just create a folder inside your project with package.json and platform folders, more like a plugin within project.


@manojdcoder, thanks for reply, but i dint get your point clearly. Iam new to nativescript


Place the jar file inside app/App_Resources/Android folder nativescript cli will include the jar when compiling your app.

When the app builds if you see the name of your jar file in the cli logs, that means that it got included successfully.

Adding jar directly into platforms folder is a bad idea.
Because platforms folder is not something that you keep in source control.


Uhm, I am not sure NativeScript supports the App_Resources/Android libraries. I am fairly certain it doesn’t actually. We added support for App_Resources/Android/libs where you’ll be able to drop off your jar and aar files, but that will hit in the 4.0 release.


Thank you @Pete.K that is valuable info. Can you confirm if it’s still possible via plugins in 3.x?


Importing jars and aars through other means, like plugins remains unchanged.


Oops, sorry i missed typing /libs at the end of it.


@manojdcoder, i tried the method you adviced.
But whenever i tried to import the plugin in nativescript+angular project, got ERROR TypeError: Cannot read property ‘toaster’ of undefined error.


@Pete.K Hi. Nowadays , 4.1 , If I have a 3’rd party jar , And I need to use it in my app , where do I put it ?
and what about the AARs ?


Hey, you can place the jars and aars in your App_Resources/Android/libs. If there isn’t one, make a dir and place your aars and jars there. At least that’s how I implemented it to work for 4. Since I am no longer a contributor to the project I’ve lost track of the changes.