Writing Plugin for Android View



For our new project we need to include a native library for iOS and Android. After some troubles with iOS I got it to work as the library provides a ViewController I was able to open it. On the Android side the same SDK does only provide a view component which they usually include in their XML Layouts.

Is there a common way to wrap a native (android) view component into a plugin? (I want to provide the same API as for the iOS version which opens a UIViewController)

I’ve tried to create an activity that wraps the android native view, but for some reason the view will never appear?

import {setActivityCallbacks, AndroidActivityCallbacks} from "tns-core-modules/ui/frame";
class Activity extends android.app.Activity {
    private _callbacks: AndroidActivityCallbacks;

    protected onCreate(savedInstanceState: android.os.Bundle): void {
        if (!this._callbacks) {
        //adding this line here produces a RuntimeException 
        // java.lang.RuntimeException: Unable to resume activity {org.nativescript.demo/com.plugin.Activity}: android.content.res.Resources$NotFoundException: Unable to find resource ID #0x2
        // this._callbacks.onCreate(this, savedInstanceState, super.onCreate);

        this.setContentView(this.getResources().getIdentifier("plugin_activity", "layout", this.getPackageName()));
        this._callbacks.onCreate(this, savedInstanceState, super.onCreate);


I can see that an activity is launched but it shows the exact same view as the one that was displayed before. (The view of the main activity)