Building Android under Windows
These are my notes on setting up Urho3D to target Android. Since I'm just getting started with Urho, I'm sure there is a more streamlined way to do this. I know little about programming Android (and like it even less) so I'll leave it to others to edit these notes who actually know Urho3D/Android details better (please). This is just about getting the basics working.
This example is using... - Windows 8.1 Pro running in VMware Player (6.0.4) (VM GPU issues w/simulators, etc.) - Urho3D (1.5 release) + CMake (3.3.2) - MinGW (5.2.0) 32 bit + CodeBlocks (15.12) (building Urho tool chain stuff) - Oracle JDK (v7) - Android SDK / NDK - Eclipse Mars Java (4.5.1) with C++, ADT addons.
Get Urho3D Build environment setup and working under Windows. Just a simple “Hello World” will do. http://urho3d.wikia.com/wiki/Building_Urho_1.5_(Windows_10,_MinGW/GCC)
Here's a couple of links with example/detail of setting up Android / Eclipse / ADT. A little bit dated, so some of the details / sequences may be a little different. http://techblogon.com/install-eclipse-android-sdk-adt-pluin/ http://www.codeproject.com/Articles/802626/Writing-Games-with-Cplusplus-for-Android-on-a-PC-S
1. Android setup – Need SDK + NDK minimum. I picked them up with a VS 2015 Community install, but you can get them from Google directly. The AVD simulators don't work under my Virtual Machine environment, but should if you are native (painfully slow). - SDK – include API-19 (Urho default) and any others you want to target. Think you have to include the newest default stuff to get all the build tools. - NDK (r10e)
After installing, you need to add/confirm that your path includes the SDK and NDK. I added them to my User Variables rather than System, but I have my permissions opened up well. In my case they are: C:\ProgramData\Microsoft\AndroidNDK\android-ndk-r10e\prebuilt\windows\bin;C:\Program Files (x86)\Android\android-sdk\tools
Also need an NDK variable setup pointing to it's location: ANDROID_NDK = C:\ProgramData\Microsoft\AndroidNDK\android-ndk-r10e
2. Install the JDK. Add a variable pointing to it (your locations may be different): JAVA_HOME = C:\Program Files (x86)\Java\jdk1.7.0_55
3. Install Eclipse. I did not use the installer, but just picked the java version, then added the IDE for C++ and the ADT tools. The techblogon.com site above goes through it well, but you can't add the NDK path until after you install the ADT. When I first started Eclipse it complained about “no java” so I installed the JRE (probably not needed). It started OK, but had compile errors, so found I was missing the JAVA_HOME variable setting pointing to the JDK (so don't forget that!).
--> Should now have all the tools we need, so onto Urho3D stuff......................
1. Create a Urho Android build tree. Goto your Urho distribution directory with a shell cmd window and run this line. (I put these things into a .bat file so I can remember what flags I ran with for the various tree's I've created and can change them easily) I am only interested in C++ environment so set some flags accordingly. Change the directory target or flags to your liking: cmake_eclipse.bat C:\Dev\Urho3D\v1.5-Android -DANDROID=1 -DURHO3D_SAMPLES=0 -DURHO3D_ANGELSCRIPT=0 -DURHO3D_LUA=0
Goto the target build directory with a cmd window and run this to match the API-19 we just created (change the 't 3' if targeting a different API): android update project -p . -t 3
Open Eclipse and import build project from build directory via menus: File/Import... Android/Existing Code – Browse to C:\Dev\Urho3D\v1.5-Android and it should select/populate what Cmake produced - Finish (indexer takes a bit of time so give it 5 min. or so). Create a build configuration in Eclipse via menus: - Run/Run Configurations... (double click)Android Application. New_configuration will pop up... --> Android-tab: browse, select project name (v1.5-Android in my example) and it should find Urho Project. Apply and Run (or Run it from menu after it has the configuration selected). Wait while it builds with a few warnings but no errors (15 – 30 min.).
Setup / change a system variable to point to your new build (if you haven’t by now): URHO3D_HOME = C:\Dev\Urho3D\v1.5-Android
2. Create Project Scaffolding. For Android we need to do more manual copy stuff. First create a new project with some simple “Hello Word”.cpp file to display some text (that you've tested under Windows, could also just add to that project but we won't here). For this create an 'Atest' project folder: C:\src\Urho3d\ATest
Copy in from the Urho3d original distribution directory the CMake directory.
Also, copy these .bat files to your project root from the Urho3d distribution directory so Cmake is easy... cmake_eclipse.bat, cmake_generic.bat.
Copy over from your windows tests: CMakeLists.txt file, your .cpp file.
Create your project Android build target directory. So you have something like: C:\src\Urho3d\ATest\BuildAndroid
Copy to 'BuildAndroid' the entire contents of the 'Android' directory from original Urho3d distribution. 3 folders and 4 files in my case (i.e. so we have BuildAndroid/assets/CoreData/, etc.).
ALSO: Copy the Data and CoreData directories directly. The distribution is using links (shortcuts) for those, so THEY GET MISSED with a basic windows copy/past on the assets directory. Just make sure they are there and populated in the BuildAndroid/assets directory like the source. Include any extra data stuff your project is using if you have any addons (don't for this test) (you can delete things you will never use for your project also, if you want to make it smaller, etc.).
3. Build it ---------------->
Now we have enough to run Cmake from the Atest directory (not sure if the script flags are really needed, but it generally helps to match our build tree). It will pop a warning about Eclipse not supporting subdirectories from source, resulting in the .cpp file not being visible within Eclipse by default. I don't plan on doing any source editing from there, so I just ignored it. Run: cmake_eclipse.bat .\BuildAndroid -DANDROID=1 -DURHO3D_ANGELSCRIPT=0 -DURHO3D_LUA=0
Goto the BuildAndroid directory and update android project like you did in the v1.5-Android build tree directory above. If you wanted to change the AndroidManifest.xml (and a few other things to customize), now would be the time before running this, but are not doing that here. Run: android update project -p . -t 3
Open Eclipse and import project from ./BuildAndroid as we did with the Urho build tree (you can close / delete previous projects if you are done with those). Config and run (build) as before.
Check Console and Problems tabs for errors (warnings OK). If all worked, it will try and load the app to the simulator. (On my machine the simulator is so slow it fails to load unless it was already running)
Even though My simulator won't work right (GPU issues within the VM environment), it can be useful to check LogCat for issues (of course... What could possibly go Wrong!). Probably a way to config Eclipse to just load to a real phone and it would be worth doing if you did much of this.
You should find your .APK file in BuildAndroid/Bin directory (around 13.7M with the default data). I just copy it to my phone, run it to install, and check that it runs (Yea!).
This will build using default Urho3D player stuff (i.e. called 'Urho3D' and com.github.urho3d.SampleLauncher, etc.)
(might add some notes on personalizing AndroidManifest.xml and a few other files, but I'm just hacking with it at this point so no time soon. Perhaps someone can clean up my notes and add info on such things. Also, no idea what issues will probably show up dealing with resource overload, User Interface, touch screen, etc. on a real app)
(some other references that may be useful)