Android build

From OpenMW Wiki
Jump to navigation Jump to search

Android build OpenMW

Preparation of building environment

Before you start building OpenMW on Android you have to do few steps of preparation:

  1. Download Crystax NDK
  2. Download and install Google Android SDK
  3. Download Cmake for Android (it will be used for OpenMW and its dependencies compilation)
  4. Download java
  5. Download all OpenMW dependencies, ie:

Compilation of OpenMW dependencies

Then you should add PATH for crystax ndk and google sdk.

Building Ogre3D

Next you must build ogre from source. I build ogre 1.9 with this tutorial . http://www.ogre3d.org/tikiwiki/tiki-index.php?page=CMake+Quick+Start+Guide&tikiversion=Android You must add it

if((opt = miscParams->find("externalSurface")) != end)
{
   mSurface = (EGLSurface*)(Ogre::StringConverter::parseInt(opt->second));
}

and it

if (!mEglConfig)
{
  _createInternalResources(mWindow, config);
  mHwGamma = false;
}
        
mEglDisplay = mGLSupport->getGLDisplay();

to /sinbad-ogre-7c776867621e/RenderSystems/GLES2/src/EGL/Android/OgreAndroidEGLWindow.cpp ogre otherwise not be able to work with sdl2 ,because android can have only one active window . Also in Ogre 1.9 forgot to add this line to cmake file

if(ANDROID)
  set(CMAKE_FIND_ROOT_PATH ${OGRE_DEPENDENCIES_DIR} "${CMAKE_FIND_ROOT_PATH}")
endif()

Building MyGUI

Then you must build mygui with 1 rendering system

Building Bullet

Then you should build bullet2. You can use cmake android toolchain for it

Building OpenAL

Then you must build openal . http://repo.or.cz/w/openal-soft/android.git

Building Qt (optional)

Note: Qt is only used by the launcher and OpenMW-CS, and can be skipped. To build Qt 4.8 for android: http://necessitas.kde.org/ I used this tutorial for building: https://community.kde.org/Necessitas/CompileQtFramework

Building FFmpeg

Then you must build ffmpeg . Important! You must use ffmpeg 1.26: http://www.roman10.net/how-to-build-ffmpeg-with-ndk-r9/

my script for build

./configure \
    --prefix=$(pwd)/android/$CPU  \
    --enable-static \
    --disable-doc \
    --disable-ffmpeg \
    --disable-ffplay \
    --disable-ffprobe \
    --disable-ffserver \
    --disable-doc \
    --disable-symver \
    --cross-prefix=/home/sylar/android-ndk-r9d/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86/bin/arm-linux-androideabi- \
    --target-os=linux \
    --arch=arm \
    --enable-asm \
    --enable-cross-compile \
    --sysroot=/home/sylar/android-ndk-r9d/platforms/android-19/arch-arm \
    --extra-cflags="-Os -fpic $ADDI_CFLAGS" \
    --extra-ldflags="$ADDI_LDFLAGS"

Building SDL2

Then you must build SDL2: https://www.libsdl.org/hg.php I used SDL2 mercurial latest source.

Building OpenMW

then I started to build OpenMW. At first you must remove all lines associated with x server in FindOGRE.cmake and add GLES2 instead GLES . For example

ogre_find_plugin(RenderSystem_GLES2 OgreGLES2RenderSystem.h RenderSystems/GLES2/include)

next I add this to main cmake file:

set(CMAKE_FIND_ROOT_PATH ${OPENMW_DEPENDENCIES_DIR} "${CMAKE_FIND_ROOT_PATH}")

And now I can build OpenMW with it

 cmake /home/sylar/openmw -DCMAKE_TOOLCHAIN_FILE=/home/sylar/android-cmake-master/android.toolchain.cmake -DOPENMW_DEPENDENCIES_DIR=/home/sylar/AndroidDependencies -DANDROID_NATIVE_API_LEVEL=14

next I remove line from main cmake file:

add_static_ogre_plugin(RenderSystem_GL)

and add it

add_static_ogre_plugin(RenderSystem_GLES2)

Next I add I remove line

add_library(openmw executable
    ${OPENMW_LIBS} ${OPENMW_LIBS_HEADER}
    ${OPENMW_FILES}
    ${GAME} ${GAME_HEADER}
    ${APPLE_BUNDLE_RESOURCES}
)
in /openmw/apps/openmw/Cmakelists.txt

and add it

add_library(main SHARED
    ${OPENMW_LIBS} ${OPENMW_LIBS_HEADER}
    ${OPENMW_FILES}
    ${GAME} ${GAME_HEADER}
    ${APPLE_BUNDLE_RESOURCES}
)

also I add it

set(GAME
    main.cpp
    SDL_android_main.c
    engine.cpp
)
#//if(NOT WIN32)
 # //  set(GAME ${GAME} crashcatcher.cpp)
#endif()

# Main executable
set(BOOST_COMPONENTS system filesystem program_options thread wave atomic)
target_link_libraries(main

${OGRE_STATIC_PLUGINS}
#RenderSystem_GLES2Static
#//Plugin_OctreeSceneManagerStatic
#//Plugin_ParticleFXStatic
#   ${OGRE_Plugin_OctreeSceneManager_LIBRARY_REL}   
 # ${OGRE_Plugin_ParticleFX_LIBRARY_REL}    
 #${OGRE_RenderSystem_GLES2_LIBRARY_REL}   
)


target_link_libraries(main
EGL
android
log
dl

#   ${OGRE_Plugin_OctreeSceneManager_LIBRARY_REL}   
 # ${OGRE_Plugin_ParticleFX_LIBRARY_REL}    
 #${OGRE_RenderSystem_GLES2_LIBRARY_REL}   
)
target_link_libraries(main
boost_atomic
boost_chrono
boost_date_time
boost_filesystem
boost_program_options
boost_system
boost_thread
boost_wave
#   ${OGRE_Plugin_OctreeSceneManager_LIBRARY_REL}   
 # ${OGRE_Plugin_ParticleFX_LIBRARY_REL}    
 #${OGRE_RenderSystem_GLES2_LIBRARY_REL}   
)
target_link_libraries(main
FreeImage
freetype
#   ${OGRE_Plugin_OctreeSceneManager_LIBRARY_REL}   
 # ${OGRE_Plugin_ParticleFX_LIBRARY_REL}    
 #${OGRE_RenderSystem_GLES2_LIBRARY_REL}   
)

target_link_libraries(main
OgreMainStatic
#   ${OGRE_Plugin_OctreeSceneManager_LIBRARY_REL}   
 # ${OGRE_Plugin_ParticleFX_LIBRARY_REL}    
 #${OGRE_RenderSystem_GLES2_LIBRARY_REL}   
)

target_link_libraries(main
MyGUI.OgrePlatform
MyGUIEngineStatic
Plugin_StrangeButtonStatic
cpufeatures
#   ${OGRE_Plugin_OctreeSceneManager_LIBRARY_REL}   
 # ${OGRE_Plugin_ParticleFX_LIBRARY_REL}    
 #${OGRE_RenderSystem_GLES2_LIBRARY_REL}   
)

Next I changed paths in: /openmw/components/files/linuxpath.cpp for example

 return getEnv("XDG_DATA_HOME", "/sdcard/morrowind/share") / mName;

Next I add patch in ogreinit.cpp and ogreinit.hpp I comment it

// Set up logging first
   //     new Ogre::LogManager;
     //   Ogre::Log *log = Ogre::LogManager::getSingleton().createLog(logPath);

   // #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
        // Use custom listener only on Windows
       // log->addListener(new LogListener(logPath));
 //   #endif

        // Disable logging to cout/cerr
       // log->setDebugOutputEnabled(false);

and change plugin gl on gles2

#ifdef ENABLE_PLUGIN_GLES2
# include "OgreGLES2Plugin.h"
#endif

#ifdef ENABLE_PLUGIN_GLES2
        Ogre::GLES2Plugin* mGLES2Plugin;
#endif

Next you must add it to

 opt["externalWindowHandle"] = Ogre::StringConverter::toString((int) wmInfo.info.android.window );
 opt["externalSurface"] = Ogre::StringConverter::toString((int) wmInfo.info.android.surface );
 /openmw/extern/sdl4ogre/sdlwindowhelper.cpp

Next I add this file to OpenMW SDL_android_main.c With it, I calle native c code from java wtih help jni . I rename main function in main.cpp to SDL_main .

Now you can build openmw lib

Next for eclipse project I use android-project example from SDL and use README-android.txt tutorial from sdl

Disable mipmaps

Add this line to all textures_units

filtering linear linear none