If you have worked through Compiling orx and the Android demo and all compiled and deployed fine, then you are right to continue with this tutorial.
That means your own application should be able to work under Android. There are pitfalls along the way and I'll do my best to guide you through. You don't have to know Java or Android to make use of this guide.
Depending how you structure your own project, (especially if you use the init script to create your projects) it is likely that you have a folder layout something like this:
bin build windows codelite mac xcode data include lib src
Perhaps you are targeting more than one operating system and IDE. You'll want to add the Android demo project to the build folder where it can be customised to work with your project. So copy the whole
orx/code/demo/android folder to your build folder so it becomes:
bin build android <------- here app/ gradle/ build.bat build.gradle build.sh gradle.properties gradlew gradlew.bat settings.gradle windows mac data include lib src
The Application ID notation is used to make Android applications (and their ownership) unique from all other applications that are available.
This notation is peppered through many files in the demo project and we'll need to change all of them to make the project your own. The notation used in the demo is:
org.orxproject.orxtestportion is called the Package Name and also the Application ID.
OrxDemoportion is the Class Name.
org.orxproject.orxtest.OrxDemois the Activity.
To make this demo easier to follow, let's come up with a fantasy application name and company.
Imagine you owned the domain name:
And your game was
Rocket Boy. Then a good identifier might be:
net.rabbitgames.rocketboywould be your Package Name and Application ID.
RocketBoyGamewould be the Class Name.
net.rabbitgames.rocketboy.RocketBoyGamewould be the Activity.
These names do not represent anything visual in your game itself, title, or icon, etc. Those are defined elsewhere.
We will apply this notation though the files coming up.
Read more about this at: https://developer.android.com/studio/build/application-id
If you don't know what an APK is, it is like an installer package for Android, similar to a setup.exe for Windows.
The string you choose will become the name of the APK, for example:
Similar to the naming we discussed earlier, let's call the app:
build/android/settings.gradle file and change from:
This is also known as the project name.
rootProject.name = "Orx Demo"
rootProject.name = "Rocket Boy"
Now you need to rename the folder
build/android/app folder to match. So it becomes:
Edit the meta data in the
<meta-data android:name="android.app.lib_name" android:value="orxDemo" />
<meta-data android:name=“android.app.lib_name” android:value=“RocketBoyGame” />
An activity is a screen, or drawable area. An Android application can have multiple activities, one stacked on another, and each removed using the back button on a device.
An activity can also show or hide a title, Android nav bar, or onscreen keyboard.
Read more about Activities and Manifests at: https://developer.android.com/reference/android/app/Activity and https://developer.android.com/guide/topics/manifest/manifest-intro
Edit the following at
Change all manifestPlaceholders from:
manifestPlaceholders = [ gameArguments: 'orxDemo' ] manifestPlaceholders = [ gameArguments: 'orxDemoDebug' ] manifestPlaceholders = [ gameArguments: 'orxDemoProfile' ]
manifestPlaceholders = [ gameArguments: 'RocketBoyGame' ] manifestPlaceholders = [ gameArguments: 'RocketBoyGameDebug' ] manifestPlaceholders = [ gameArguments: 'RocketBoyGameProfile' ]
To read more about the importance of your application id: https://developer.android.com/studio/build/application-id and http://developer.android.com/guide/topics/manifest/manifest-element.html#package
This is how to set the title text for your application icon when loaded on your device.
The App name is located at:
<string name="app_name">Rocket Boy</string>
Your application must also be given a module name. You set this name in three places. The module name must match:
LOCAL_MODULE := RocketBoyGame
Next file to change is:
APP_MODULES = RocketBoyGame
All your source files, *.cpp and *.h can be copied into the
build/android/rocket-boy/src/main/jni folder. However if your prefer, you can source them from your existing project with a relative path.
To ensure your C/C++ files are compiled, each source file (but not header files) will need to be listed in the
build/android/rocket-boy/src/main/jni/Android.mk. If you copied your source files to the
assets folder, you can just specify the files like this:
LOCAL_SRC_FILES := file01.cpp file02.cpp file03.cpp file04.cpp file05.cpp
Or to access them relatively:
LOCAL_SRC_FILES := ../../../../../../src/file01.cpp ../../../../../../src/file02.cpp
Note that if you followed the same file structure in this tutorial, the six parent levels to get to your source files would be correct.
You can delete the unused
orxDemo.cpp on disk.
The files need to be laid out on the same line due to CR/LF issues in the file, causing errors like
"*** commands commence before first target. Stop.".
Listing on one line makes the problem go away.
Orx will load its startup ini file from the
Because of the
manifestPlaceholders configured earlier, Orx will try to load
RocketBoyGameDebug.ini when in debug mode, or
RocketBoyGame.ini for release mode. (Debug or release APKs are covered later).
From these initial ini files, you can load your other project application files. But please note that your Android application will not be able reach back into a parent path for assets. These all need to live in your
build/android/rocket-boy/src/main/assets folder. Therefore it will be useful for you to consider creating a publishing script to regularly copy all your Orx assets from the project into this
?? Not sure which mode you are compiling for? Have a look in the
build/android/rocket-boy/src/main/jni/Android.mk file. The “LOCAL_STATIC_LIBRARIES := orxd” line tells it is
orxd (debug). In this case, load
To learn more about bootstrapping different ini files at: changing the default ini file here.
All your PNGs and OGGs and whatever else need to be copied into the
build/android/rocket-boy/src/main/assets folder, just like the INI files.
Consider a publishing script to periodically copy them from your project
data folder to Android
Open a terminal and go to:
build.bat (for Windows or) build.sh (Linux / Mac)
Locate your APK files in:
You are done!
There are three ways to test your application:
Run > Run 'RocketBoyGame'to send to the phone. You can track application progress and logs via Android Studio's output pane.
Run > Run 'RocketBoyGame'to send to the Android Emulator. This also has good logging.
Please note that this section is not complete or tested. New content will replace this very soon.
Before you can generate a release APK, you will need to sign it. You don't need to do this for debug APKs. You can do this by:
1. Right clicking on the "rocket-boy" project. 2. Click "Open Module Settings" 3. Click the "Signing" tab. 4. Click the + sign.
Continue on, by visiting the following link: http://developer.android.com/tools/publishing/app-signing.html and scroll down to the section titled “Signing Your App in Android Studio”.