Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Tutorial: Building SFML for Android on Windows  (Read 44157 times)

0 Members and 4 Guests are viewing this topic.

Turbine

  • Full Member
  • ***
  • Posts: 100
    • View Profile
Tutorial: Building SFML for Android on Windows
« on: February 19, 2017, 02:51:45 am »
I've created a new tutorial for those who were having trouble compiling SFML for Android on Windows.

> https://github.com/SFML/SFML/wiki/Tutorial:-Building-SFML-for-Android-on-Windows

JayhawkZombie

  • Jr. Member
  • **
  • Posts: 76
    • View Profile
Re: Tutorial: Building SFML for Android on Windows
« Reply #1 on: February 19, 2017, 03:52:15 am »
I'm curious, do you know if this worked for running the builds on a simulated device?  I know they run a lot slower, but it's better than nothing.  I don't actually have an android, but my team members do.  I'm one of the engine writers, but it's hard to test w/out an android.

Alternatively, I could get a cheap android to test it on.  Don't want to switch from iOS, since I intend to port to iOS eventually.

Turbine

  • Full Member
  • ***
  • Posts: 100
    • View Profile
Re: Tutorial: Building SFML for Android on Windows
« Reply #2 on: February 19, 2017, 05:39:04 am »
While I'm also curious, there's nothing stopping you making a native Windows PC release of your project before building the Android version. It'd be quicker to compile and run - than over an emulator. But make sure you handle mouse input as well as touch input events, as they're separate. It's in the standard Android example.

I'm not sure if this may help you out:
https://github.com/AlexAUT/SFML-AndroidStudio-Template
« Last Edit: February 19, 2017, 05:48:32 am by Turbine »

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: Tutorial: Building SFML for Android on Windows
« Reply #3 on: February 19, 2017, 09:27:31 am »
What exactly were the problems with the existing wiki entry? We've now got duplicated topics with just little differences.

Also just out of curiosity – not trying to nitpick:
  • Why do you install MinGW?The Android NDK provides complete GCC/Clang environments for all supported targets (including "make", which can be invoked using "cmake --build path". Nothing from MinGW should be used during the build.
  • Why do you install Android Studio? You only need the Android SDK, which standalone is smaller (300MB vs. 1.7GB) and without overhead (you're not creating an Android Studio project after all).

Turbine

  • Full Member
  • ***
  • Posts: 100
    • View Profile
Re: Tutorial: Building SFML for Android on Windows
« Reply #4 on: February 19, 2017, 09:57:45 am »
What exactly were the problems with the existing wiki entry? We've now got duplicated topics with just little differences.
When was the last time you followed that documentation from scratch? There's too many issues and a lack of information for any beginner.

Quote
Why do you install MinGW?The Android NDK provides complete GCC/Clang environments for all supported targets (including "make", which can be invoked using "cmake --build path". Nothing from MinGW should be used during the build.
It's good to know this, I figured as you were using Linux - the make utility was system supplied.

Quote
Why do you install Android Studio? You only need the Android SDK, which standalone is smaller (300MB vs. 1.7GB) and without overhead (you're not creating an Android Studio project after all).
Gotcha, I see how they now bundle them. Thank you.

I merely wanted to post a guide for others who can't find a straightforward working method of getting SFML compiled with the example. There was no information on that wiki about the NDK version supported (12b). Upon failing at certain points, there was no clean method provided for a subsequent attempt.

I wanted to be able to compile and get a working example up swiftly, not the hours of assumptions & failure. :) I hope you can understand.
« Last Edit: February 20, 2017, 02:12:26 am by Turbine »

JayhawkZombie

  • Jr. Member
  • **
  • Posts: 76
    • View Profile
Re: Tutorial: Building SFML for Android on Windows
« Reply #5 on: February 20, 2017, 01:58:03 am »
there's nothing stopping you making a native Windows PC release of your project before building the Android version. It'd be quicker to compile and run - than over an emulator.

We are/working on simulating it.  The editor has a special view for simulating a mobile device and translating events (ie translating a mouse press to a finger down, mouse up to finger up, etc).  I will let you know how it works out.  Err, the current plan is to have it generate code for an android build if that option is selected, otherwise it'll build for PC.

Turbine

  • Full Member
  • ***
  • Posts: 100
    • View Profile
Re: Tutorial: Building SFML for Android on Windows
« Reply #6 on: February 21, 2017, 01:50:21 am »
there's nothing stopping you making a native Windows PC release of your project before building the Android version. It'd be quicker to compile and run - than over an emulator.

We are/working on simulating it.  The editor has a special view for simulating a mobile device and translating events (ie translating a mouse press to a finger down, mouse up to finger up, etc).  I will let you know how it works out.  Err, the current plan is to have it generate code for an android build if that option is selected, otherwise it'll build for PC.

I've found a way to use the emulator. Just be sure to compile "x86" Android SFML libraries and the example with Android "x86". (As opposed to "armeabi-v7a")

  • Install Intel haxm.
  • Open "SDK Manager.exe" provided by the Android SDK, ensure you have an x86 image installed for your API version.
  • Then open "AVD Manager.exe", create a new device, select the target to your API version and the CPU/ABI to x86.
  • After selecting okay, you can start the emulator. It might take a few minutes to start.
  • Type "adb devices" in a CMD window, if it fails to find the command: Open a CMD window at "sdk\platform-tools"
  • Copy your Apk to the "sdk\platform-tools" directory.
  • adb install -r "NAME_OF_FILE.apk"


DeathRay2K

  • Newbie
  • *
  • Posts: 24
    • View Profile
    • Email
Re: Tutorial: Building SFML for Android on Windows
« Reply #7 on: March 09, 2017, 09:53:43 pm »
I was pretty excited to see this for a second, before I realised I still couldn't compile for Android from a single codebase like I can for Mac, Windows, and Linux. :P

Turbine

  • Full Member
  • ***
  • Posts: 100
    • View Profile
Re: Tutorial: Building SFML for Android on Windows
« Reply #8 on: March 09, 2017, 10:47:06 pm »
Well actually.. it is possible. I wrote a simple script which generates entries into the Android makefile from a Codeblocks project. Thus simplifying the source includes, include directories, library includes, defines, compiler flags and so on.

My biggest issue at the moment is the GCC version provided in the NDK is 4.9 - they now consider it deprecated. I've not dealt with the Clang/llvm tools on Windows, which is their default compiler for the NDK.

SteelGiant

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Tutorial: Building SFML for Android on Windows
« Reply #9 on: April 25, 2018, 12:51:34 am »
Having failed to get the most recent version of the SFML example that uses gradle to build, I just went through the Windows tutorial using all the old toolchain.

It was absolutely miserable to get it to go in the end, as many steps have been obsoleted and are hard to get hold of. Just in case anyone else is going through the same nightmare between now and when the gradle version "just works" I thought I would share my notes here:

Get a version of the SFML repo from when the tutorial was written - I don't know if this is strictly necessary, but after days fighting with the latest build, I was taking no chances
Code: [Select]
git checkout ffd9c94381ad4739ce56428f10dda3daba376f30
Downgrade SDK tools to 25.2.5 or lower, because the build commands in the tutorial have been removed since then
You'll probably have to delete the tools and build-tools folders in the sdk dir because of course it won't have cleaned them out even after unchecking all the sdk tools
Make extra sure that there aren't newer tools checked in any menu in Android studio if you're using it - there are separate checkboxes for the latest ones well away from all the others. Just delete the folders in the SDK dir, Android studio can't be trusted.
Even the url to get the required version of the tools is hidden: http://dl-ssl.google.com/android/repository/tools_r25.2.5-windows.zip
Have to manually put the tools folder inside the zip in the sdk dir as "tools"
https://stackoverflow.com/questions/9555337/how-to-downgrade-my-sdk-version/11514698#11514698
Then the "android update ..." command will work

Of course despite having the JDK installed, it tried to look at the JRE for some reason. Fixed with (replace path as appropriate) at the console where you're trying to build:
Code: [Select]
set "JAVA_HOME=C:\Program Files\Java\jdk1.8.0_172"
Then ant fails because platform-tools aren't installed
In the SDK/tools folder run (with extreme care) and make sure it only has the box for the specific platform tools you need checked (it tried to stick 12 other packages in by default for me, many of which would have broken everything else)
Code: [Select]
android update sdkOnly option apparently is to install SDK platform tools 27.0.1, this seems to work

Despite having my phone in developer mode and plugged in "ant debug install" failed, but the apk was created successfully

Actually builds:
Code: [Select]
ant debug
Presumably replacing debug with release above would build a release version

Transfer the apk file manually

It finally works

SteelGiant

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Tutorial: Building SFML for Android on Windows
« Reply #10 on: April 25, 2018, 09:43:44 pm »
And one more thing: in order to get my own test to build for android, as I was using c++11 features, I had to add

Code: [Select]
LOCAL_CPPFLAGS := -std=c++1y
Then I had to manually edit one of the include files in the old android NDK
Code: [Select]
path\to\android-ndk-r12b\sources\cxx-stl\llvm-libc++\libcxx\include\tupleto comment out two lines (291 and 357- the const versions) that were apparently incompatible with c++11

Aside from that it built fairly painlessly.

Shaders unfortunately didn't work, and I haven't had a chance to look at why.