|
|
Development for AndroidFrom Linderdaum Engine
Development for AndroidPlease read Establishing build process before proceeding. This tutorial will explain to you how to build Linderdaum Engine for Android operating system.
PrerequisitesTo build Linderdaum Engine for Android you will require: - Android SDK r16 - Android NDK r7c (refer to http://developer.android.com) - Python 3.1+ (the scripts are written in 3.0 version, but they work fine in 2.6/2.7 also) - Cygwin (Windows only) - Apache Ant - Java SE Development Kit 6 - a device with Android 2.2 to run the activity In Debian/Ubuntu only the Android SDK/NDK must be downloaded and installed separately. Follow the instructions from the official Android site. Everything else is easily installed using the Apt package manager. Configuring environment- set JAVA_HOME environment variable to your JDK folder (on Ubuntu with OpenJDK it is usually /usr/lib/kvm/default-java) - set NDK_ROOT environment variable to your Android NDK folder - add path to your Android SDK to 'trunk/Apps/*/local.properties' as 'sdk.dir=' BuildingUnder Windows: - Start Cygwin Bash Shell and change directory to 'trunk/BuildAndroid'
- Create libLinderdaumEngineCore.a using the following command:
ndk-build -j4
Under Linux: - Simply create libLinderdaumEngineCore.a using the following command in the 'trunk/BuildAndroid' directory:
ndk-build -j4
After this a static library will be created that can be used in your applications. Developing applicationsPorting your app written using Linderdaum Engine to Android is easy and straightforward. Basically, if you are following a few guidelines you can compile the very same source code both for Win32/64 and Android. Your game data also can be shared. Linux users must use the '/' slashes in all of the paths mentioned below. Windows users striving for portability should also opt to using these separators. Let's take a look at the minimalistic example: #include "Linderdaum.h" sEnvironment* Env = NULL; void Event_DRAWOVERLAY( LEvent Event, const LEventArgs& Args ) { Env->Renderer->GetCanvas()->TextStrFreeType( LRect(0.0f, 0.3f), "Hello Android", 0.07f, LC_Red, NULL, TextAlign_Center ); } APPLICATION_ENTRY_POINT { Env = new sEnvironment(); Env->SetLogLevel( L_LOG ); Env->DeployDefaultEnvironment( "", "../../CommonMedia" ); Env->Viewport->SetViewportTitle( "Android Application" ); Env->Connect( L_EVENT_DRAWOVERLAY, Utils::Bind( &Event_DRAWOVERLAY ) ); Env->RunApplication( DEFAULT_CONSOLE_AUTOEXEC ); APPLICATION_EXIT_POINT(Env); } APPLICATION_SHUTDOWN { // do custom deinitialization here, Env will be autodestoyed } Now to make it run let's create two folders Apps\MyAndroidApp, Apps\MyAndroidApp\Data and Apps\MyAndroidApp\Src and put this code into Apps\MyAndroidApp\Src\MyAndroidApp.cpp. You will also need some files in Apps\MyAndroidApp for Android build system, so here they are:
source.dir=..\\..\\BuildAndroid\\src default.properties target=android-8 local.properties sdk.dir=<path to your Android SDK, like D:\\android-sdk-windows> res\values\strings.xml <?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">MyAndroidApp</string>
</resources>
jni\Application.mk APP_OPTIM := release APP_PLATFORM := android-7 APP_STL := gnustl_static APP_CPPFLAGS += -frtti APP_CPPFLAGS += -fexceptions APP_CPPFLAGS += -DANDROID APP_ABI := armeabi-v7a makeconfig.py - should be empty (will be autogenerated) Now from the root Linderdaum SDK run Solution\regenerateconfigs.py script and afterwards makeconfig.py script. You will have Apps\MyAndroidApp\makeconfig.py and Apps\MyAndroidApp\Src\Android.mk files regenerated. Preparing manifestIn order to run different Android tools you need to create a manifest for your project. Here it is: AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.linderdaum.engine.myfirstandroidapp" android:versionCode="1" android:versionName="0.6.00" android:installLocation="auto"> <!--require Android 2.1 and higher--> <uses-sdk android:minSdkVersion="7" /> <uses-sdk android:targetSdkVersion="9" /> <supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:anyDensity="true" /> <uses-feature android:glEsVersion="0x00020000"/> <uses-feature android:name="android.hardware.telephony" android:required="false" /> <uses-permission android:name="com.android.vending.CHECK_LICENSE"/> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <application android:label="@string/app_name" android:installLocation="preferExternal" android:debuggable="false"> <activity android:name="com.linderdaum.engine.LinderdaumEngineActivity" android:launchMode="singleTask" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:screenOrientation="portrait" android:configChanges="orientation|keyboardHidden" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> The line package="com.linderdaum.engine.myfirstandroidapp" will be the name of your package. Change it for different applications. Please refer to Android SDK documentation for details on manifest file. BuildingGo to Apps\MyAndroidApp\Src and run ndk-build from the cygwin shell command line. You should see something like this: $ ndk-build -j4 Compile++ thumb : LinderdaumEngine <= MyAndroidApp.cpp Compile++ thumb : LinderdaumEngine <= LAndroid.cpp Prebuilt : libLinderdaumEngineCore.a <= jni/../../../BuildAndroid/obj/local/armeabi-v7a/ Prebuilt : libFreeImage.a <= jni/../../../BuildAndroid/jni/ Prebuilt : libFreeType.a <= jni/../../../BuildAndroid/jni/ Prebuilt : libVorbis.a <= jni/../../../BuildAndroid/jni/ Prebuilt : libOGG.a <= jni/../../../BuildAndroid/jni/ Prebuilt : libOpenAL.a <= jni/../../../BuildAndroid/jni/ Prebuilt : libstdc++.a <= <NDK>/sources/cxx-stl/gnu-libstdc++/libs/armeabi-v7a/ SharedLibrary : libLinderdaumEngine.so Install : libLinderdaumEngine.so => libs/armeabi-v7a/libLinderdaumEngine.so You have compiled the C++ part of your project. Now you should compile the Java part and build an .apk file. You will need a build.xml to do it.
<?xml version="1.0" encoding="UTF-8"?>
<project name="LinderdaumEngineActivity" default="help">
<property file="local.properties" />
<property file="build.properties" />
<property file="default.properties" />
<path id="android.antlibs">
<pathelement path="${sdk.dir}/tools/lib/anttasks.jar" />
<pathelement path="${sdk.dir}/tools/lib/sdklib.jar" />
<pathelement path="${sdk.dir}/tools/lib/androidprefs.jar" />
</path>
<taskdef name="setup"
classname="com.android.ant.SetupTask"
classpathref="android.antlibs" />
<setup />
</project>
Run ant debug to build an .apk file. A file named bin\LinderdaumEngineActivity-debug.apk will be created. Now you can install your app on a device using the adb command: adb install LinderdaumEngineActivity-debug.apk and uninstall it via: adb uninstall com.linderdaum.engine.myfirstandroidapp |
