Integrating SDKs

Right now I had to integrate several SDKs into my Project. My choice is:
1.Integrate each SDK in one native extension, so if I have 10 sdk to integrate, I have to write 10 native extension.
2.Integrate all SDK into one native extension.
Each SDK has its own java,oc,lua,jar,c++ to manage, but, between these SDK, one thing is common:
Lua code will call java/oc. So I want to write commonly used code to achieve this. Just like luaj/luaoc in
cocos2dx.But if I Integrate each SDK in one native extension(choice 1), luaj/luaoc will turn up in every native extension.
I want to write one code, and use in every native extension.
I notice the Enhance project, but the services it provide not so suitable for my project.

We have plans for making certain extensions “base-extensions”, so that other extensions can be built on top of that. ETA unknown. (DEF-3348)

As an (ugly) workaround, for the common code, you can have one extension for that, and in your other extensions use “extern” to use that code from another extension. It’s not pretty, but should get you going.

2 Likes

How to use “extern”?Write extern in extension’s .manifest file?

I think what Mathias is referring to is the extern keyword in C that defines a function as being defined elsewhere.

Yes. Like so:

extern int AnotherLibLuaFunction(lua_State* L); // Defined in another lib

int ThisLibLuaFunction(lua_State* L)
{
    int r = AnotherLibLuaFunction(L);
    // ... other stuff
    return r;
}
2 Likes

OK. I’ll try it out.Thanks.

And what about if I have java in my common code?Can I use common java code from another native extension?

C++ code can be reused between native extensions using extern, but how about java code?

Hmm, not sure but maybe if you create a singleton?

Hi, @britzl
Did you mean putting all the java code (including the common code and the other) into one native extension?

What I was thinking was to put all of your shared code in a native extension. The shared C code would be accessed through other extensions using the extern keyword and the Java code could be instantiated in a singleton in the shared code and accessed through other extensions using JNI.

I haven’t tried any of this, it’s just an idea.

Right now, I have shared java code in one extension, and several other extensions, every one has its own java code, and will use that shared java code in java, not using JNI