0

I have created .a static library (tested in Xcode for native ios project and Its working fine) Now I am following this https://github.com/NativeScript/nativescript-plugin-seed to create nativescript plugin using .a static framework.

Plugin structure enter image description here

module.modulemap file is created by me and it's look like this

module libstaticlibrary {
    umbrella header "staticlibrary.h"
    export *
}

staticlibrary.h

#import <Foundation/Foundation.h>

@interface staticlibrary : NSObject
+ (NSString *)sayHello;
@end

libstaticlibrary.d.ts also created by me

declare class staticlibrary extends NSObject {

    static sayHello():string;

}

Then in helloplugin.common.ts I am trying to access staticlibrary.sayHello() method.

export class Utils {
  public static SUCCESS_MSG(): string {
    // let msg = `Your plugin is working on ${app.android ? 'Android' : 'iOS'}.`;
    let msg = staticlibrary.sayHello();

    setTimeout(() => {
      dialogs.alert(`${msg} For real. It's really working :)`).then(() => console.log(`Dialog closed.`));
    }, 2000);

    return msg;
  }

I am getting following error.

node_modules/nativescript-helloplugin/helloplugin.common.ts(21,15): error TS2304: Cannot find name 'staticlibrary'.

What is I am doing wrong here?

1 Answer 1

2

It's just the TypeScript compiler error, you have to generate typings for your static library (refer docs to know how) or just add this line at top of your file.

declare var staticlibrary: any

I see that you do have a declaration file in your code snippet, if you want to use it you have to include it to your references.d.ts file.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the answer. I have run the TNS_TYPESCRIPT_DECLARATIONS_PATH="$(pwd)/typings" tns build ios --for-device command and include the staticlibrary.d.ts path in reference.d.ts. I am getting "no such file or directory, scandir '/Users/.../nativescript-helloplugin/demo/node_modules/nativescript-helloplugin/platforms/ios/include/libstaticlibrary'. Obviously I dont have such a file.
Rename the libstaticlibrary.a to staticlibrary.a worked for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.