How to initialize static libraries for Android?

Discussion of issues specific to mobile platforms such as iOS, Android, Symbian and Meego.
Post Reply
fernnando
Gnoblar
Posts: 5
Joined: Mon Mar 27, 2017 1:57 pm

How to initialize static libraries for Android?

Post by fernnando » Mon Mar 27, 2017 3:09 pm

Hi everyone!

I'm working in Qt for Android and I followed this tutorial to implement OGRE: http://www.ogre3d.org/tikiwiki/tiki-ind ... e+into+QT5

I have OgreMain.so, OgreOverlay.so, OgreRTShaderSystem.so, RenderSystem_GL.so, Plugin_PCZSceneManager.so, Plugin_ParticleFX.so, Plugin_OctreeZone.so, Plugin_OctreeSceneManager.so and Plugin_BSPSceneManager.so. All of them are working fine for Linux and with the previous tutorial I could create a window with a sphere.

To compile OGRE for Android, I followed this tutorial (http://www.ogre3d.org/forums/viewtopic.php?f=2&t=80802) and everything went well. The only issue is that I wanted my libraries as dynamic link libraries and I could not achieve that :/

These lines work for all the plugins but not for my render system. When I try to build I receive almost 40 errors.

Code: Select all

    Ogre::GLES2Plugin* mGLES2Plugin = new Ogre::GLES2Plugin();
    m_ogreRoot->getSingleton().installPlugin(mGLES2Plugin);
I left an image with the errors

From the compiler's output I think that this library (libRenderSystem_GLES2Static.a) is not correctly compiled. That seems rare to me. I followed a tutorial to compile the libaries and Ogre Browser Sample worked perfectly, even better that the apk that you can find in PlayStore.

Could you help me with this problem? Is it possible to compile the libraries as dynamic link libraries for Android? Why is it forced to static in CmakeList? Where could I find precompiled binaries for Android? Do they even exist?

Thanks!

Fer
Attachments
ogre_errors.png
0 x

AndrAlekseevV
Gnoblar
Posts: 6
Joined: Thu Jan 26, 2017 1:15 pm

Re: How to initialize static libraries for Android?

Post by AndrAlekseevV » Mon Mar 27, 2017 3:32 pm

You need to link the library to your program. You don't need 100500 shared libraries, you need to have one shared library and link it with all static libraries.
If you use cmake build system:To the end of your cmake file just write something like this:

Code: Select all

target_link_libraries(_the_program_name_  RenderSystem_GLES2Static)
_the_program_name_ is a name of your final shared library that was created with

Code: Select all

 add_executable(_the_program_name_    soruce_files) 
or

Code: Select all

add_library(_the_program_name_    soruce_files) 
For more info google: cmake target_link_libraries


if you use Android.mk build system, just add the follow lines to Android.mk file:

Code: Select all

# RenderSystem_GLES2Static
	include $(CLEAR_VARS)
	LOCAL_MODULE    := RenderSystem_GLES2Static
	LOCAL_SRC_FILES :=/path/to/libRenderSystem_GLES2Static.a
	include $(PREBUILT_STATIC_LIBRARY)
and

Code: Select all

LOCAL_STATIC_LIBRARIES +=  RenderSystem_GLES2Static 
And you need to know: order is link is very important! That's my order:
OgreRTShaderSystemStatic Plugin_OctreeSceneManagerStatic Plugin_ParticleFXStatic OgreOverlayStatic RenderSystem_GLES2Static OgreMainStatic
If the order will be wron, i'll get link error.
0 x

fernnando
Gnoblar
Posts: 5
Joined: Mon Mar 27, 2017 1:57 pm

Re: How to initialize static libraries for Android?

Post by fernnando » Mon Mar 27, 2017 5:30 pm

AndrAlekseevV wrote:You need to link the library to your program. You don't need 100500 shared libraries, you need to have one shared library and link it with all static libraries.
If you use cmake build system:To the end of your cmake file just write something like this:

Code: Select all

target_link_libraries(_the_program_name_  RenderSystem_GLES2Static)
_the_program_name_ is a name of your final shared library that was created with

Code: Select all

 add_executable(_the_program_name_    soruce_files) 
or

Code: Select all

add_library(_the_program_name_    soruce_files) 
For more info google: cmake target_link_libraries


if you use Android.mk build system, just add the follow lines to Android.mk file:

Code: Select all

# RenderSystem_GLES2Static
	include $(CLEAR_VARS)
	LOCAL_MODULE    := RenderSystem_GLES2Static
	LOCAL_SRC_FILES :=/path/to/libRenderSystem_GLES2Static.a
	include $(PREBUILT_STATIC_LIBRARY)
and

Code: Select all

LOCAL_STATIC_LIBRARIES +=  RenderSystem_GLES2Static 
And you need to know: order is link is very important! That's my order:
OgreRTShaderSystemStatic Plugin_OctreeSceneManagerStatic Plugin_ParticleFXStatic OgreOverlayStatic RenderSystem_GLES2Static OgreMainStatic
If the order will be wron, i'll get link error.
The problem is not about static vs shared. Is about the initialization of static libraries in Android. I cannot understand if my problems come because a bad compilation or if it's something else going on.
0 x

AndrAlekseevV
Gnoblar
Posts: 6
Joined: Thu Jan 26, 2017 1:15 pm

Re: How to initialize static libraries for Android?

Post by AndrAlekseevV » Mon Mar 27, 2017 6:49 pm

You can't initialize static library on run time. You need to link it on build time, or compile libs as shared library:
Change this line =

Code: Select all

277: set(OGRE_STATIC TRUE CACHE BOOL "Forcing static build for Android" FORCE) 
in main cmake file in section

Code: Select all

265:elseif (ANDROID)
code line in bitbucket repo:https://bitbucket.org/sinbad/ogre/src/b ... ts.txt-277
0 x

fernnando
Gnoblar
Posts: 5
Joined: Mon Mar 27, 2017 1:57 pm

Re: How to initialize static libraries for Android?

Post by fernnando » Wed Mar 29, 2017 4:37 pm

Oks, I could solve the problems. First, OgreMainStatic must be linked after GLES2RenderSystem library. Second, Qt wasn't linking libandroid from NDK.

Now my problem is that when I run this line, I received a segmentation fault

Code: Select all

    m_ogreWindow = m_ogreRoot->createRenderWindow("QT Window",
        this->width(),
        this->height(),
        false,
        &parameters);
Output message:

Code: Select all

I/OGRE    (10354): GLES2RenderSystem::_createRenderWindow "QT Window", 540x850 windowed  miscParams: currentGLContext=false externalWindowHandle=1 parentWindowHandle=1
Any ideas about what's going on?
0 x

Post Reply