C++ for Android, Static Library Use


  • I have been trying to extend a framework that uses openGL to android native apps. (by native I mean C/C++ compiled stuff with a thinnest layer of xml and java necessary).

    I've run into an unexpected issue, the templates provided work fine; but the only example of having more than one native library is for the (currently) openGLES2 template which shows shared->static->dynamic->packaging.

    Where the shared is .so and the static is .a output files.

    What I want to do is have a dynamic library which glues the framework to the android message loop, and a static library that has only the application specific code as this framework is for more than one app deployment.

    I can't figure out how to do that. Everything I have tried has resulted in "unfortunately APPNAME has stopped working" on the emulator. No break points are hit, and I have to switch to the emulator from the android SDK since the logcat works. The error message that I think matters is always the same.

    Failed to load library. (illegal argument exception). This happens even when I just switch a perfectly functional .so project to .a in the project properties.

    Obviously there is, somewhere, steps or configuration that needs to be done in order to get this to build and deploy correctly but it is not simply adding a reference in Visual Studio as I had hoped.

    If anyone has learned how to work with these android native libraries in the 'advanced' ways I need/want to. I would really appreciate some pointers.

    P.S. I know about the <meta> tag in the manifest. I know it is supposed to refer to a library, I just don't know anything more. i.e. whether that is just for the entry point, whether it is just for .so and not .a etc

    Friday, December 18, 2015 8:43 AM


  • Hi Trygve Skogsholm,

    Do you mean you want to use Static Library in your extension created with OpenGL or in your android native apps? Please provided a screenshot about your project structure to help us understanding your problem.

    In my opinion, we often add Static Library in C++ project with below steps. Hope that can help you.

    1. Right-click the Reference node in your project which you want to reference the Static Library.
    2. Choose Add Reference -> Projects -> Solution -> the Static Library that you want to add.
    3. Right-click the project to open Properties window of your project.
    4. Expend the C/C++ node under Configuration Properties.
    5. Next to Additional Include Directories, specify the path of the Static Library directory.
    6. Click OK button to save your configuration.

    Best Regards,

    Monday, December 21, 2015 7:35 AM