Android build: Difference between revisions

From OpenMW Wiki
Jump to navigation Jump to search
No edit summary
 
(19 intermediate revisions by 2 users not shown)
Line 3: Line 3:
Before you start building OpenMW on Android you have to do few steps of preparation:
Before you start building OpenMW on Android you have to do few steps of preparation:
# Download  [https://www.crystax.net/ Crystax NDK]
# Download  [https://www.crystax.net/ Crystax NDK]
# Download and install [http://developer.android.com/sdk/index.html Google Android SDK]
Openmw building without errors only on crystax ndk 10.1.0 version.
# Download [https://github.com/taka-no-me/android-cmake Cmake for Android] (it will be used for OpenMW and its dependencies compilation)
# Download [https://github.com/taka-no-me/android-cmake Cmake for Android] (it will be used for OpenMW and its dependencies compilation)
# Download [http://www.oracle.com/technetwork/java/javase/downloads/index-jsp-138363.html java ]
# Download [http://www.oracle.com/technetwork/java/javase/downloads/index-jsp-138363.html java ]
Line 15: Line 15:
#*  [https://github.com/MyGUI/mygui mygui]
#*  [https://github.com/MyGUI/mygui mygui]
#* zlib integrated in android
#* zlib integrated in android
Prebuilt openmw dependencies for armv7 arch
https://drive.google.com/file/d/0B5mOME9qjLFuckRrSWd6ZTMtZGM/view?usp=sharing
Prebuilt openmw dependencies for armv8 arch
https://drive.google.com/file/d/0B5mOME9qjLFuVkpRc2FWb3h1SW8/view?usp=sharing


=== Compilation of OpenMW dependencies ===
=== Compilation of OpenMW dependencies ===
Line 20: Line 26:
Then you should add PATH for crystax ndk and google sdk.
Then you should add PATH for crystax ndk and google sdk.


==== Building Ogre3D ====
==== Building OSG ====
Next you must build ogre from source. I build ogre 1.9 with this tutorial .
Next you must build OSG from source. I build osg with this tutorials .  
http://www.ogre3d.org/tikiwiki/tiki-index.php?page=CMake+Quick+Start+Guide&tikiversion=Android
 
You must add it
http://www.openscenegraph.org/index.php/documentation/platform-specifics/android/43-building-openscenegraph-for-android-3-0-2
<syntaxhighlight lang="cpp">
 
if((opt = miscParams->find("externalSurface")) != end)
http://www.openscenegraph.org/index.php/documentation/platform-specifics/android/178-building-openscenegraph-for-android-3-4
{
 
  mSurface = (EGLSurface*)(Ogre::StringConverter::parseInt(opt->second));
You must build osg with osgdb_dds osgdb_bmp, osgdb_tga ,osgdb_gif ,osgdb_jpeg, osgdb_png plugins and GLES1 profile !
}
</syntaxhighlight>
and it
<syntaxhighlight lang="cpp">
if (!mEglConfig)
{
  _createInternalResources(mWindow, config);
  mHwGamma = false;
}
       
mEglDisplay = mGLSupport->getGLDisplay();
</syntaxhighlight>
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
<syntaxhighlight lang="cmake">
if(ANDROID)
  set(CMAKE_FIND_ROOT_PATH ${OGRE_DEPENDENCIES_DIR} "${CMAKE_FIND_ROOT_PATH}")
endif()
</syntaxhighlight>


==== Building MyGUI ====
==== Building MyGUI ====
Then you must build mygui for ogre
Then you must build mygui with 1 rendering system
http://mygui.info/
And you should remove this line from cmake file
<syntaxhighlight lang="cmake">
add_definitions(-msse)
</syntaxhighlight>


==== Building Bullet ====
==== Building Bullet ====
Line 78: Line 58:
./configure \
./configure \
     --prefix=$(pwd)/android/$CPU  \
     --prefix=$(pwd)/android/$CPU  \
     --enable-shared \
     --enable-static \
    --disable-static \
     --disable-doc \
     --disable-doc \
     --disable-ffmpeg \
     --disable-ffmpeg \
Line 102: Line 81:


=== Building OpenMW ===
=== Building OpenMW ===
then I started to build OpenMW. At first you must remove all lines associated with x server in FindOGRE.cmake
Then I started to build OpenMW.  
and add GLES2 instead GLES .
I copied all  libraries  in one folder . For example AndroidDependencies, and build openmw like this
For example
<syntaxhighlight lang="cmake">
ogre_find_plugin(RenderSystem_GLES2 OgreGLES2RenderSystem.h RenderSystems/GLES2/include)
</syntaxhighlight>
next I add this to main cmake file:
<syntaxhighlight lang="cmake">
set(CMAKE_FIND_ROOT_PATH ${OPENMW_DEPENDENCIES_DIR} "${CMAKE_FIND_ROOT_PATH}")
</syntaxhighlight>


And now I can build OpenMW with it
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
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
cmake /home/sandstranger/Android/openmw -DCMAKE_TOOLCHAIN_FILE=/home/sandstranger/Android/android-cmake-master/android.toolchain.cmake -DANDROID_TOOLCHAIN_NAME=aarch64-linux-android-4.9 -DANDROID_NATIVE_API_LEVEL=android-21 -DANDROID_NDK=/home/sandstranger/Android/crystax-ndk-10.1.0/ -DANDROID_ABI=arm64-v8a -DOPENMW_DEPENDENCIES_DIR=/home/sandstranger/Android/AndroidDependenciesARMV8 -DOSG_PLUGINS_DIR=/home/sandstranger/Android/AndroidDependenciesARMV8/lib/osgPlugins-3.5.1 -DBUILD_BSATOOL=OFF -DBUILD_ESMTOOL=OFF -DBUILD_LAUNCHER=OFF -DBUILD_MWINIIMPORTER=OFF -DBUILD_ESSIMPORTER=OFF -DBUILD_OPENCS=OFF -DBUILD_WIZARD=OFF -DBUILD_MYGUI_PLUGIN=OFF -DMYGUI_STATIC=ON -DBOOST_STATIC=ON
</syntaxhighlight>
</syntaxhighlight>
next I remove line from main cmake file:
<syntaxhighlight lang="cmake">
add_static_ogre_plugin(RenderSystem_GL)
</syntaxhighlight>
and add it
<syntaxhighlight lang="cmake">
add_static_ogre_plugin(RenderSystem_GLES2)
</syntaxhighlight>
Next I add I remove line
<syntaxhighlight lang="cmake">
add_library(openmw executable
    ${OPENMW_LIBS} ${OPENMW_LIBS_HEADER}
    ${OPENMW_FILES}
    ${GAME} ${GAME_HEADER}
    ${APPLE_BUNDLE_RESOURCES}
)
</syntaxhighlight>
in /openmw/apps/openmw/Cmakelists.txt
and add it
<syntaxhighlight lang="cmake">
add_library(main SHARED
    ${OPENMW_LIBS} ${OPENMW_LIBS_HEADER}
    ${OPENMW_FILES}
    ${GAME} ${GAME_HEADER}
    ${APPLE_BUNDLE_RESOURCES}
)
</syntaxhighlight>
also I add it
<syntaxhighlight lang="cmake">
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}
-O2 or -Os optimal optimizations flags for building . Without this flags fps will be very low
#RenderSystem_GLES2Static
#//Plugin_OctreeSceneManagerStatic
#//Plugin_ParticleFXStatic
#  ${OGRE_Plugin_OctreeSceneManager_LIBRARY_REL} 
# ${OGRE_Plugin_ParticleFX_LIBRARY_REL}   
#${OGRE_RenderSystem_GLES2_LIBRARY_REL} 
)


After builing openmw library, you must copy all the libraries to libs folder in the  java project folder


target_link_libraries(main
For example :  /eclipse-project/app/src/main/jniLibs/armeabi-v7a
EGL
android
log
dl


#  ${OGRE_Plugin_OctreeSceneManager_LIBRARY_REL} 
Then you must import this [https://github.com/OpenMW/eclipse-project java project] in android-studio , which included with the android sdk.
# ${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
Also you need to import the configuration files from desktop openmw version.
OgreMainStatic
#  ${OGRE_Plugin_OctreeSceneManager_LIBRARY_REL} 
# ${OGRE_Plugin_ParticleFX_LIBRARY_REL}   
#${OGRE_RenderSystem_GLES2_LIBRARY_REL} 
)


target_link_libraries(main
=== Building Gotchas ===
MyGUI.OgrePlatform
MyGUIEngineStatic
Plugin_StrangeButtonStatic
cpufeatures
#  ${OGRE_Plugin_OctreeSceneManager_LIBRARY_REL} 
# ${OGRE_Plugin_ParticleFX_LIBRARY_REL}   
#${OGRE_RenderSystem_GLES2_LIBRARY_REL} 
)
</syntaxhighlight>
Next I changed paths in: /openmw/components/files/linuxpath.cpp
for example
<syntaxhighlight lang="cpp">
return getEnv("XDG_DATA_HOME", "/sdcard/morrowind/share") / mName;
</syntaxhighlight>
Next I add patch in ogreinit.cpp and ogreinit.hpp
I comment it
<syntaxhighlight lang="cpp">
// Set up logging first
  //    new Ogre::LogManager;
    //  Ogre::Log *log = Ogre::LogManager::getSingleton().createLog(logPath);


  // #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
<pre>
        // Use custom listener only on Windows
CMake Error at /home/bcurtis/workspace/OpenMW/android/android-cmake/android.toolchain.cmake:429 (math):
      // log->addListener(new LogListener(logPath));
  math cannot parse the expression: "+0": syntax error, unexpected exp_PLUS,
//  #endif
  expecting exp_OPENPARENT or exp_NUMBER (1)
Call Stack (most recent call first):
  /home/bcurtis/workspace/OpenMW/android/build/CMakeFiles/3.2.2/CMakeSystem.cmake:6 (include)
   CMakeLists.txt:1 (project)
</pre>


        // Disable logging to cout/cerr
Don't panic, this can be worked around with the removal (or comment '#') of the non-critical line in the file android-cmake/android.toolchain.cmake on line 429.
      // log->setDebugOutputEnabled(false);
</syntaxhighlight>
and change plugin gl on gles2
<syntaxhighlight lang="cpp">
#ifdef ENABLE_PLUGIN_GLES2
# include "OgreGLES2Plugin.h"
#endif
 
#ifdef ENABLE_PLUGIN_GLES2
        Ogre::GLES2Plugin* mGLES2Plugin;
#endif
</syntaxhighlight>
Next you must add it to
<syntaxhighlight lang="cpp">
opt["externalWindowHandle"] = Ogre::StringConverter::toString((int) wmInfo.info.android.window );
opt["externalSurface"] = Ogre::StringConverter::toString((int) wmInfo.info.android.surface );
</syntaxhighlight>
  /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
<syntaxhighlight lang="cpp">
filtering linear linear none
</syntaxhighlight>

Latest revision as of 11:12, 30 December 2015

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

Openmw building without errors only on crystax ndk 10.1.0 version.

  1. Download Cmake for Android (it will be used for OpenMW and its dependencies compilation)
  2. Download java
  3. Download all OpenMW dependencies, ie:

Prebuilt openmw dependencies for armv7 arch https://drive.google.com/file/d/0B5mOME9qjLFuckRrSWd6ZTMtZGM/view?usp=sharing

Prebuilt openmw dependencies for armv8 arch https://drive.google.com/file/d/0B5mOME9qjLFuVkpRc2FWb3h1SW8/view?usp=sharing

Compilation of OpenMW dependencies

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

Building OSG

Next you must build OSG from source. I build osg with this tutorials .

http://www.openscenegraph.org/index.php/documentation/platform-specifics/android/43-building-openscenegraph-for-android-3-0-2

http://www.openscenegraph.org/index.php/documentation/platform-specifics/android/178-building-openscenegraph-for-android-3-4

You must build osg with osgdb_dds osgdb_bmp, osgdb_tga ,osgdb_gif ,osgdb_jpeg, osgdb_png plugins and GLES1 profile !

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. I copied all libraries in one folder . For example AndroidDependencies, and build openmw like this

cmake /home/sandstranger/Android/openmw -DCMAKE_TOOLCHAIN_FILE=/home/sandstranger/Android/android-cmake-master/android.toolchain.cmake -DANDROID_TOOLCHAIN_NAME=aarch64-linux-android-4.9 -DANDROID_NATIVE_API_LEVEL=android-21 -DANDROID_NDK=/home/sandstranger/Android/crystax-ndk-10.1.0/ -DANDROID_ABI=arm64-v8a -DOPENMW_DEPENDENCIES_DIR=/home/sandstranger/Android/AndroidDependenciesARMV8 -DOSG_PLUGINS_DIR=/home/sandstranger/Android/AndroidDependenciesARMV8/lib/osgPlugins-3.5.1 -DBUILD_BSATOOL=OFF -DBUILD_ESMTOOL=OFF -DBUILD_LAUNCHER=OFF -DBUILD_MWINIIMPORTER=OFF -DBUILD_ESSIMPORTER=OFF -DBUILD_OPENCS=OFF -DBUILD_WIZARD=OFF -DBUILD_MYGUI_PLUGIN=OFF -DMYGUI_STATIC=ON -DBOOST_STATIC=ON

-O2 or -Os optimal optimizations flags for building . Without this flags fps will be very low

After builing openmw library, you must copy all the libraries to libs folder in the java project folder

For example : /eclipse-project/app/src/main/jniLibs/armeabi-v7a

Then you must import this java project in android-studio , which included with the android sdk.

Also you need to import the configuration files from desktop openmw version.

Building Gotchas

CMake Error at /home/bcurtis/workspace/OpenMW/android/android-cmake/android.toolchain.cmake:429 (math):
  math cannot parse the expression: "+0": syntax error, unexpected exp_PLUS,
  expecting exp_OPENPARENT or exp_NUMBER (1)
Call Stack (most recent call first):
  /home/bcurtis/workspace/OpenMW/android/build/CMakeFiles/3.2.2/CMakeSystem.cmake:6 (include)
  CMakeLists.txt:1 (project)

Don't panic, this can be worked around with the removal (or comment '#') of the non-critical line in the file android-cmake/android.toolchain.cmake on line 429.