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

Author Topic: SFML in Android Studio Example  (Read 20874 times)

0 Members and 2 Guests are viewing this topic.

Alia5

  • Newbie
  • *
  • Posts: 34
    • View Profile
SFML in Android Studio Example
« on: August 30, 2017, 07:30:51 pm »
Hi there,

somewhere around here floats a template to get SFML to work in AndroidStudio.
However, it is quite old, uses the experimental android gradle plugin and uses a dirty hack for SFMLActivity / SFML-Main

I just tried SFML on Android and pushed a new example project, using recent AndroidBuild tools with the newest ndk and AndroidStudio and the stable version of the Android Gradle plugin.

https://github.com/Alia5/SFML_AndroidStudio

I've also encountered a crash when the activity gets sent to the background using the home button, that I've also circumvented without modifying SFML at all.

It also shows how to combine Android-Java code with native-SFML code for things like google-play services etc.

It's still quite ugly and ways to go for a proper "example" project, it should serve as a starting-point, though.
I just wanted to share, I'm sure you can figure it out ;)

KRMisha

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: SFML in Android Studio Example
« Reply #1 on: August 31, 2017, 06:09:10 pm »
Looks great! Thanks!

madcat

  • Newbie
  • *
  • Posts: 21
  • Creator of TacWars
    • View Profile
    • TacWars
Re: SFML in Android Studio Example - Android on OSX
« Reply #2 on: September 03, 2017, 12:59:09 pm »
Well Done!

I've actually just released a template + Method for SFML for Android (With Android Studio) developing on OSX!

I tried to simplify the process to the core. Give it a check.
I had problems with link_directories it seems to be rather restrictive on OSX.
so I defined each and every external lib like the google dudes do in the Hello-libs example. Works nicely.

check out https://github.com/MoVoDesign/SFML_Template

and this is what I'm going to port to Android Now!!! http://www.movo-design.com

;) Lio
« Last Edit: September 03, 2017, 02:57:41 pm by madcat »

madcat

  • Newbie
  • *
  • Posts: 21
  • Creator of TacWars
    • View Profile
    • TacWars
Android / stlport_shared and C++11 unique_ptr<>
« Reply #3 on: September 04, 2017, 05:16:52 pm »
...Hello again.

Now that I've got SFML working, I realise that the android C++11 STL support is rather shoddynamely:
here is the trouble: unique_ptr

this is the minimal example I've been working on.
Can't compile this while linking with SFML.

#include <memory>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>

int main(int argc, char *argv[]) {

  std::unique_ptr<sf::RenderWindow> upW(new sf::RenderWindow(sf::VideoMode::getDesktopMode(), "OMG!!!"));
  sf::RenderWindow& window = *upW;

  sf::View view = window.getDefaultView();

  while (window.isOpen())
  {
    window.clear(sf::Color::Black);
    window.display();
  }
}
 

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:externalNativeBuildDebug'.
> Build command failed.
  Error while executing process /Users/lio/Library/Android/sdk/cmake/3.6.4111459/bin/cmake with arguments {--build /Users/lio/StudioProjects/SFML_Template/app/.externalNativeBuild/cmake/debug/armeabi --target my-app}
  [1/2] Building CXX object CMakeFiles/my-app.dir/main.cpp.o
  FAILED: /Users/lio/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++  --target=armv5te-none-linux-androideabi --gcc-toolchain=/Users/lio/Library/Android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64 --sysroot=/Users/lio/Library/Android/sdk/ndk-bundle/sysroot  -Dmy_app_EXPORTS -I/Users/lio/StudioProjects/SFML_Template/app/src/main/cpp/../../../../sfml/include -isystem /Users/lio/Library/Android/sdk/ndk-bundle/sources/cxx-stl/stlport/stlport -isystem /Users/lio/Library/Android/sdk/ndk-bundle/sources/cxx-stl/gabi++/include -isystem /Users/lio/Library/Android/sdk/ndk-bundle/sysroot/usr/include/arm-linux-androideabi -D__ANDROID_API__=15 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -march=armv5te -mtune=xscale -msoft-float -fno-integrated-as -mthumb -Wa,--noexecstack -Wformat -Werror=format-security  -std=c++11 -fexceptions -frtti -O0 -fno-limit-debug-info  -fPIC -MD -MT CMakeFiles/my-app.dir/main.cpp.o -MF CMakeFiles/my-app.dir/main.cpp.o.d -o CMakeFiles/my-app.dir/main.cpp.o -c /Users/lio/StudioProjects/SFML_Template/app/src/main/cpp/main.cpp
  /Users/lio/StudioProjects/SFML_Template/app/src/main/cpp/main.cpp:18:8: error: no member named 'unique_ptr' in namespace 'std'
    std::unique_ptr<sf::RenderWindow> upW(new sf::RenderWindow(sf::VideoMode::getDesktopMode(), "OMG!!!"));
    ~~~~~^
 

any idea?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: SFML in Android Studio Example
« Reply #4 on: September 04, 2017, 06:25:46 pm »
Did you include the header <memory>?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

madcat

  • Newbie
  • *
  • Posts: 21
  • Creator of TacWars
    • View Profile
    • TacWars
Re: SFML in Android Studio Example
« Reply #5 on: September 04, 2017, 08:40:26 pm »
good one, I did, you'll find it at the top of my code

Meanwhile it hit me as I chatted with a friend about the absurdity of so many STL implementations:

STLPORT is from 2008... so NO smart pointers:o

I rebuilt SFML with GNUSTL instead

cmake -DANDROID_ABI=x86 -DCMAKE_TOOLCHAIN_FILE=$SFML/cmake/toolchains/android.toolchain.cmake -DCMAKE_FIND_FRAMEWORK="NEVER" -DANDROID_STL=gnustl_shared $SFML
 

and defined it in build.gradle (module: app) as well
defaultConfig {
  externalNativeBuild {
    cmake {
      cppFlags "-std=c++11 -fexceptions -frtti"
      arguments '-DANDROID_STL=gnustl_shared'
    }
  }
}
 

and TADA!  ;D

now back to TacWars
« Last Edit: September 04, 2017, 08:46:10 pm by madcat »

Alia5

  • Newbie
  • *
  • Posts: 34
    • View Profile
Re: SFML in Android Studio Example
« Reply #6 on: September 04, 2017, 09:06:23 pm »
Use clangs libc++_shared for full c++11 support!!!
you can also use this to build sfml, just use ndk-r12b for building SFML only ;)

madcat

  • Newbie
  • *
  • Posts: 21
  • Creator of TacWars
    • View Profile
    • TacWars
Re: SFML in Android Studio Example
« Reply #7 on: September 04, 2017, 09:14:49 pm »
All right! We are getting there! Thanks Alia5!!!  ;D

Just modified Template + HowTo (SFML + Android + OSX)
including building SFML for Android with c++_shared STL and ndk-r12b

you can find it here: https://github.com/MoVoDesign/SFML_Template

Added: use of symbolic links in HowTo, to avoid copying libs all over the place.
« Last Edit: September 08, 2017, 05:34:01 pm by madcat »

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: SFML in Android Studio Example
« Reply #8 on: September 18, 2017, 06:18:18 pm »
Hey,

nice template and thanks for the work! I just submitted a pull request which adds support for finding SFML automatically inside your NDK folder (where make install will install SFML). I also added support for multiple ABIs.

Maybe the SFML team should think about adding this template to the examples in the SFML repository, because it is working out of the box now. (I will submit a SFML pull request today which fixes the build system for NDK r >12)


P.S. I'm the creator of the old ugly template  :P

AlexAUT

 

anything