TRON Posted April 6, 2016 Share Posted April 6, 2016 This guide is a work in progress and was quickly wrote in order to get something documented on how to use Android Studio to compile and run Torque 2D for Android platform.Clarifications on 'click the link' statements in this document, the link being the blue underlined part of aforementioned text or message in some parts of the Android Studio IDE. I've updated this post to colorize and underline the talked about links, but leaving the former statement in case I missed one or two.1) Requirements:1.1) You'll need Java Development Kit (JDK) in order to use Android Studio. As for which one to download, choose the x86 if you have a 32bit operating system, or x64 if you have a 64bit operating system.Note: The Java Runtime Environment (JRE) already comes with the JDK and even though you might already have latest JRE installed let it install it anyway, via Public JRE option, else it will uninstall the existing JRE and therefore Java programs won't run on your system until you install the JRE again. I've made this mistake before by unchecking JRE during JDK install.1.2) Next thing to download and install is Android Studio. Also, you must have JDK installed first before you can install Android Studio.1.3) And finally you'll of course need the most recent Torque 2D source code. v3.3 was just released of which has the necessary Android Studio fixes to successfully build under it.2) Android Studio Setup:2.1) Now you may run Android Studio and on first run it'll display a "Complete Installation" dialog prompt asking you if you want to import a previous Android Studio version's configuration. If you haven't used it before or don't care to import old settings then you can just press OK with the default option to .. "I do not want to import my settings" to move on to starting the Integrated Development Environment (IDE).2.1.1) Note that Android Studio does take some time to start initially, and you might get a prompt asking whether or not to allow it to access the private network on Windows. I generally Allow it due the IDE having the Android Debug Bridge (ADB) integrated into it of which has networking capabilities such as debugging over LAN and Wifi to target Android devices.It'll also initially have the Android SDK Manager perform updates of which is what the "Downloading Components" dialog is about.2.1.2) Also during this procedure on Windows you'll run into the dreaded "The following SDK component was not installed" and in the log window it'll say something about "A folder failed to be moved". No need to worry, just click on Cancel in the prompt and then click on Finish in the Android Studio Setup Wizard.Then to resolve the problem while in the "Welcome to Android Studio" landing dialog click on Configure option then SDK Manager. Then you'll see "Android SDK Location:" label in Red color. Press the Edit link on the opposite side of the textbox of which will bring up a "SDK Components Setup" wizard. Let it install the already chosen components and later you can install the older Android SDK platform versions if necessary for your target device.It should then complete successfully this time and you'll be back at the Android SDK page of Default Settings. From here you can choose older Android SDK platforms to install in case you need to target much older devices of which generally you do. Such as in my case I use "Android 5.1.1" API 22 to support my Amazon Fire tablet platform. After you've selected the Android SDK platforms you're wanting to work with click on Apply to download and install them.3) Load Torque 2D Android Project3.1) In the "Welcome to Android Studio" landing dialog click on Open an existing Android Studio project, and navigate to and select the /engine/compilers/android-studio directory, and click OK to open the project. The IDE will take a while to load the first time so give it a minute. Close the tip of the day dialog tool window.You'll notice that it'll fail to build with various errors. First of which might be lack of build tools, click the red link message to install the SDK build tools in the message window and let it install it. If not then that's alright. Now follow the next section:3.2) Install NDK:You'll need the Native Development Kit (NDK) for Android in order to build Torque 2D as it is a C/C++ engine. We'll just let Android Studio take care of that for us considering it's troublesome to get it right when installing the NDK manually. Click on File menu then Project Structure... and in SDK Location page you'll see an empty textbox field for "Android NDK Location:" simply click on Download link in "Download Android NDK" label. Will take a while for "Installing Requested Components" to complete. Once done click on Finish.3.3) Check Android platform settings:While still in the Project Structure dialog click on app page under Modules category and make sure that the appropriate "Compile Sdk Version" is selected for your target Android device that you're wanting to support. Now you may close the dialog by pressing OK.4) Compile Torque 2D project:4.1) Click on Build menu then Make Project. In the Gradle Console, located in bottom right as a tab in the IDE window, you should see a bunch of "[armeabi-v7a] Compile++ arm : torque2d <= filename" messages indicating that it is compiling the project. It is normal to see the occasional compiler warning as some code still in need of fixing to avoid those warning messages.It should compile completely with "BUILD SUCCESSFUL" indicating that it did so without error.5) Run Torque 2D on an Android device:5.1) Press the Green Play button, or press Shift + F10, or Run menu then Run 'app', in order to initiate the procedures to select a target device to run on, or emulator if you wish to, of which then it'll upload the program to, and then run T2D on the target device.5.2) Alternatively press the Green bug button, or press Shift + F9, or Run menu then Debug 'app', in order to run a debug session instead of just doing a normal program run on Android.5.3) Anyway when attempting to run or debug T2D you'll be presented with a Device Chooser and here you either select your already connected target Android device, or you may select/launch an available emulator image. Once you've done so by pressing OK there will be some Gradle operations performed just before uploading Torque 2D to the device/emulator and then eventually you'll see a Torque logo and then the monster truck toy will play.Have fun.6) ToDo:6.1) Various things aren't documented at all in this guide such as how to configure the IDE to use Torque 2D's include paths to resolve all the warnings and errors that only the code editor is reporting when viewing engine source files. I've yet to figure that out myself as I haven't had time to investigate. Quote Link to comment Share on other sites More sharing options...
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.