NativeScript / NativeScript/android

Implementing native android .aar file or .aidl in Nativescript throws native calss object without access to methods

Open
#1,535 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
563
Forks
144
Avg merge
10h 46m
Merged PRs (30d)
14

Description

Environment
Provide version numbers for the following components (information can be retrieved by running tns info in your project folder or by inspecting the package.json of the project):

  • CLI:
  • Cross-platform modules:
  • Android Runtime:
  • iOS Runtime:
  • Plugin(s):
    Android
    Describe the bug

I have an Android SDk done with java whic I already converted to .aar file. I created a plugin and placed the aar file in App_Resources/Android/libs directory. In my index.js file, I have this

var intent = new android.content.Intent(application.android.foregroundActivity, com.iposprinter.printertestdemo.IPosPrinterTestDemo.class)
intent.setFlags(android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
application.android.foregroundActivity.startActivity(intent);

This cause the sdk to display.

Doing this

var iposprinter=new com.iposprinter.printertestdemo.IPosPrinterTestDemo()
console.log(iposprinter) //outputs com.iposprinter.printertestdemo.IPosPrinterTestDemo@682890e
while this `console.log(iposprinter.printerInit) outputs undefined`

while this

`console.log(iposprinter.printerInit) outputs undefined`
console.log(iposprinter.printerInit()) outputs undefined
TypeError: iposprinter.printerInit is not a function


How do I call methods from this package?
To Reproduce

Expected behavior

Sample project

Additional context

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the plugin's index.js and the .aar placement under App_Resources/Android/libs, then reproduce the native object and printerInit logs from the issue. Check how the Android runtime exposes the packaged Java class; done means the SDK methods are available and can be called without the TypeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.