This discussion is archived
4 Replies Latest reply: Jul 25, 2011 4:18 PM by jschellSomeoneStoleMyAlias RSS

Creating a multipurpose native library

877580 Newbie
Currently Being Moderated
Hello. I have ported my iPhone game engine to Android, and everything is working fine, with the exception of allowing my native library to be used in a fairly multipurpose way (IE by creating multiple Java apps, one per game, which then link to the native game engine). I have done a great deal of searching and cannot find a solution.
The problem is native function names seem to require the entire package name for them to be properly resolved when the library is loaded (Java_com_mycompany_mygame_myclass_FunctionName). Is this the case? Do C functions really have to be renamed and recompiled for every different Java package that will use them?

Thanks
  • 1. Re: Creating a multipurpose native library
    EJP Guru
    Currently Being Moderated
    Yes. The real question is why are you copying source code into different packages? That's poor engineering. You should be sharing this code between projects as binaries.
  • 2. Re: Creating a multipurpose native library
    877580 Newbie
    Currently Being Moderated
    That's what I'm trying to do - distribute only the binary native library to those using the game engine. They in turn build, package and distribute the high-level application that links to my game engine in binary form. The problem I'm finding is my C code cannot be written generically / independent of the java code, in that the C function names must reflect package, class name, etc that calls into it. So how do I do what you suggest, which is distributing a generic native binary which is java package / class agnostic?
  • 3. Re: Creating a multipurpose native library
    EJP Guru
    Currently Being Moderated
    The problem I'm finding is my C code cannot be written generically / independent of the java code, in that the C function names must reflect package, class name, etc that calls into it.
    Which are in a Java class with native method declarations that you should also be providing. Your third party developers call methods in your Java class. There's no reason to keep changing its package name. As a matter of fact and good engineering, they should be calling Java methods in that class, which in turn call your own native methods, which should be private: that way you can decouple your interface from your implementation.
    So how do I do what you suggest, which is distributing a generic native binary which is java package / class agnostic?
    Just stop changing the package name.
  • 4. Re: Creating a multipurpose native library
    jschellSomeoneStoleMyAlias Expert
    Currently Being Moderated
    874577 wrote:
    That's what I'm trying to do - distribute only the binary native library to those using the game engine.
    That isn't possible.

    I can't think of any solutions that do not involve the following.
    1. You distribute some C/C++ source (not necessarily your library code) and the customers are responsbile for building a library.
    2. You distribute java code (as per the other suggestion) which provide the Java API for it.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points