% tns info
✔ Getting NativeScript components versions information...
✔ Component nativescript has 8.1.5 version and is up to date.
✔ Component @nativescript/core has 8.1.5 version and is up to date.
✖ Component @nativescript/ios is not installed.
✔ Component @nativescript/android has 8.1.1 version and is up to date.
Describe the bug
When running my project, I get an TypeError: theProblem.run is not a function but it exists.
The problem seems to occur because the underlying native code uses a factory pattern and the returned instance is built from a package protected class.
package mypackage;
import android.util.Log;
class PackageProtectedClass implements Runnable {
@Override
public void run() {
Log.d("JS", String.format("Run: I am %s %s", this.getClass(), this));
}
}
public class PublicClass {
public PackageProtectedClass getIt() {
return new PackageProtectedClass();
}
}
The getIt() method returns an object that implements the Runnable interface but the run()method cannot be called from NativeScript.
Environment
Describe the bug When running my project, I get an
TypeError: theProblem.run is not a function
but it exists. The problem seems to occur because the underlying native code uses a factory pattern and the returned instance is built from a package protected class.App_Resources/Android/src/main/java/mypackage/PublicClass.java
The
getIt()
method returns an object that implements theRunnable
interface but therun()
method cannot be called from NativeScript.To Reproduce Clone my project:
Enter the project and run it on android:
Expected behavior The
run()
method should be found and called.Sample project You can find a project reproducing the problem here: https://github.com/NCenerar/nativescript-issue-01.git
Additional context
./types/references.d.ts
Script part of
./app/Components/Home.vue
The output: