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

Author Topic: Errors building SFML for Android  (Read 5609 times)

0 Members and 2 Guests are viewing this topic.

LunaRebirth

  • Newbie
  • *
  • Posts: 9
    • View Profile
Errors building SFML for Android
« on: October 09, 2017, 08:46:41 pm »
Following https://github.com/SFML/SFML/wiki/Tutorial:-Building-SFML-for-Android, I was successfully able to use the cmake command.

When I use mingw-32 make, I receive these errors:
Code: [Select]
C:\NVPACK\android-ndk-r9c\platforms\android-9\arch-arm\usr\include/GLES2/gl2ext.h:439:1: error: 'GL_APICALL' does not name a type
 GL_APICALL void GL_APIENTRY glProgramBinaryOES (GLuint program, GLenum binaryFormat, const GLvoid *binary, GLint length);
 ^
C:\NVPACK\android-ndk-r9c\platforms\android-9\arch-arm\usr\include/GLES2/gl2ext.h:487:1: error: 'GL_APICALL' does not name a type
 GL_APICALL void GL_APIENTRY glTexImage3DOES (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels);
 ^
C:\NVPACK\android-ndk-r9c\platforms\android-9\arch-arm\usr\include/GLES2/gl2ext.h:488:1: error: 'GL_APICALL' does not name a type
 GL_APICALL void GL_APIENTRY glTexSubImage3DOES (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid* pixels);
 ^
C:\NVPACK\android-ndk-r9c\platforms\android-9\arch-arm\usr\include/GLES2/gl2ext.h:489:1: error: 'GL_APICALL' does not name a type
 GL_APICALL void GL_APIENTRY glCopyTexSubImage3DOES (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height);
 ^
C:\NVPACK\android-ndk-r9c\platforms\android-9\arch-arm\usr\include/GLES2/gl2ext.h:490:1: error: 'GL_APICALL' does not name a type
 GL_APICALL void GL_APIENTRY glCompressedTexImage3DOES (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data);
 ^
C:\NVPACK\android-ndk-r9c\platforms\android-9\arch-arm\usr\include/GLES2/gl2ext.h:491:1: error: 'GL_APICALL' does not name a type
 GL_APICALL void GL_APIENTRY glCompressedTexSubImage3DOES (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid* data);
 ^
C:\NVPACK\android-ndk-r9c\platforms\android-9\arch-arm\usr\include/GLES2/gl2ext.h:492:1: error: 'GL_APICALL' does not name a type
 GL_APICALL void GL_APIENTRY glFramebufferTexture3DOES (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset);
 ^
C:\NVPACK\android-ndk-r9c\platforms\android-9\arch-arm\usr\include/GLES2/gl2ext.h:575:1: error: 'GL_APICALL' does not name a type
 GL_APICALL void GL_APIENTRY glGetPerfMonitorGroupsAMD (GLint *numGroups, GLsizei groupsSize, GLuint *groups);
 ^
C:\NVPACK\android-ndk-r9c\platforms\android-9\arch-arm\usr\include/GLES2/gl2ext.h:576:1: error: 'GL_APICALL' does not name a type
 GL_APICALL void GL_APIENTRY glGetPerfMonitorCountersAMD (GLuint group, GLint *numCounters, GLint *maxActiveCounters, GLsizei counterSize, GLuint *counters);
 ^
C:\NVPACK\android-ndk-r9c\platforms\android-9\arch-arm\usr\include/GLES2/gl2ext.h:577:1: error: 'GL_APICALL' does not name a type
 GL_APICALL void GL_APIENTRY glGetPerfMonitorGroupStringAMD (GLuint group, GLsizei bufSize, GLsizei *length, GLchar *groupString);
 ^
C:\NVPACK\android-ndk-r9c\platforms\android-9\arch-arm\usr\include/GLES2/gl2ext.h:578:1: error: 'GL_APICALL' does not name a type
 GL_APICALL void GL_APIENTRY glGetPerfMonitorCounterStringAMD (GLuint group, GLuint counter, GLsizei bufSize, GLsizei *length, GLchar *counterString);
 ^
C:\NVPACK\android-ndk-r9c\platforms\android-9\arch-arm\usr\include/GLES2/gl2ext.h:579:1: error: 'GL_APICALL' does not name a type
 GL_APICALL void GL_APIENTRY glGetPerfMonitorCounterInfoAMD (GLuint group, GLuint counter, GLenum pname, GLvoid *data);
 ^
C:\NVPACK\android-ndk-r9c\platforms\android-9\arch-arm\usr\include/GLES2/gl2ext.h:580:1: error: 'GL_APICALL' does not name a type
 GL_APICALL void GL_APIENTRY glGenPerfMonitorsAMD (GLsizei n, GLuint *monitors);
 ^
C:\NVPACK\android-ndk-r9c\platforms\android-9\arch-arm\usr\include/GLES2/gl2ext.h:581:1: error: 'GL_APICALL' does not name a type
 GL_APICALL void GL_APIENTRY glDeletePerfMonitorsAMD (GLsizei n, GLuint *monitors);
 ^
C:\NVPACK\android-ndk-r9c\platforms\android-9\arch-arm\usr\include/GLES2/gl2ext.h:582:1: error: 'GL_APICALL' does not name a type
 GL_APICALL void GL_APIENTRY glSelectPerfMonitorCountersAMD (GLuint monitor, GLboolean enable, GLuint group, GLint numCounters, GLuint *countersList);
 ^
C:\NVPACK\android-ndk-r9c\platforms\android-9\arch-arm\usr\include/GLES2/gl2ext.h:583:1: error: 'GL_APICALL' does not name a type
 GL_APICALL void GL_APIENTRY glBeginPerfMonitorAMD (GLuint monitor);
 ^
C:\NVPACK\android-ndk-r9c\platforms\android-9\arch-arm\usr\include/GLES2/gl2ext.h:584:1: error: 'GL_APICALL' does not name a type
 GL_APICALL void GL_APIENTRY glEndPerfMonitorAMD (GLuint monitor);
 ^
C:\NVPACK\android-ndk-r9c\platforms\android-9\arch-arm\usr\include/GLES2/gl2ext.h:585:1: error: 'GL_APICALL' does not name a type
 GL_APICALL void GL_APIENTRY glGetPerfMonitorCounterDataAMD (GLuint monitor, GLenum pname, GLsizei dataSize, GLuint *data, GLint *bytesWritten);
 ^
C:\NVPACK\android-ndk-r9c\platforms\android-9\arch-arm\usr\include/GLES2/gl2ext.h:722:1: error: 'GL_APICALL' does not name a type
 GL_APICALL void GL_APIENTRY glCoverageMaskNV (GLboolean mask);
 ^
C:\NVPACK\android-ndk-r9c\platforms\android-9\arch-arm\usr\include/GLES2/gl2ext.h:723:1: error: 'GL_APICALL' does not name a type
 GL_APICALL void GL_APIENTRY glCoverageOperationNV (GLenum operation);
 ^
src\SFML\System\CMakeFiles\sfml-system.dir\build.make:445: recipe for target 'src/SFML/System/CMakeFiles/sfml-system.dir/Android/Activity.cpp.o' failed
mingw32-make[2]: *** [src/SFML/System/CMakeFiles/sfml-system.dir/Android/Activity.cpp.o] Error 1
CMakeFiles\Makefile2:117: recipe for target 'src/SFML/System/CMakeFiles/sfml-system.dir/all' failed
mingw32-make[1]: *** [src/SFML/System/CMakeFiles/sfml-system.dir/all] Error 2
Makefile:128: recipe for target 'all' failed
mingw32-make: *** [all] Error 2

How can I fix this?

NOTE:
Using make instead of mingw32-make gives the same result.

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: Errors building SFML for Android
« Reply #1 on: October 09, 2017, 09:16:28 pm »
Are you using the newest NDK?

If so you have to add "#include <GLES2/gl2platform.h>" before the gl2ext.h in SFML/include/OpenGL.hpp. Also you cannot use libc++ with the newsest NDK.

P.S.
You can also use this PR which fixes the build issues and supports libc++ (read the description of the PR, the build process is a tiny bit different)


AlexAUT

LunaRebirth

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Errors building SFML for Android
« Reply #2 on: October 10, 2017, 07:26:20 am »
No I'm using ndk r9c. Am I able to fix this without changing versions? My Android project uses it, and I'm just trying to add SFML's audio library.

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: Errors building SFML for Android
« Reply #3 on: October 10, 2017, 09:12:03 am »
Have you tried to include gl2platform before gl2ext as I said above? Maybe it is also a problem with older NDK version.


AlexAUT

LunaRebirth

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Errors building SFML for Android
« Reply #4 on: October 11, 2017, 03:07:15 am »
Wow, thanks. That fixed it.

Appreciate your help.

LunaRebirth

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Errors building SFML for Android
« Reply #5 on: October 11, 2017, 05:32:12 am »
New errors.

I can build SFML with

Code: [Select]
cmake -DANDROID_ABI=armeabi -DCMAKE_TOOLCHAIN_FILE=../../cmake/toolchains/android.toolchain.cmake ../.. -G "MinGW Makefiles" -DANDROID_STL=stlport_shared
which works fine, but then when I compile the android example, I get a bunch of errors like:

Code: [Select]
jni/main.cpp:79: error: undefined reference to 'sf::String::String(char const*, std::__1::locale const&)'
jni/main.cpp:82: error: undefined reference to 'sf::Texture::loadFromFile(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, sf::Rect<int> const&)'
jni/main.cpp:90: error: undefined reference to 'sf::Music::openFromFile(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)'
C:/NVPACK/android-ndk-r9c/sources/sfml/lib/armeabi/libsfml-main.a(MainAndroid.cpp.o):MainAndroid.cpp:function std::basic_streambuf<char, std::char_traits<char> >::~basic_streambuf(): error: undefined reference to 'std::locale::~locale()'
C:/NVPACK/android-ndk-r9c/sources/sfml/lib/armeabi/libsfml-main.a(MainAndroid.cpp.o):MainAndroid.cpp:function std::basic_streambuf<char, std::char_traits<char> >::~basic_streambuf(): error: undefined reference to 'std::locale::~locale()'
C:/NVPACK/android-ndk-r9c/sources/sfml/lib/armeabi/libsfml-main.a(MainAndroid.cpp.o):MainAndroid.cpp:function std::priv::_Rb_tree<int, std::less<int>, std::pair<int const, sf::Vector2<int> >, std::priv::_Select1st<std::pair<int const, sf::Vector2<int> > >, std::priv::_MapTraitsT<std::pair<int const, sf::Vector2<int> > >, std::allocator<std::pair<int const, sf::Vector2<int> > > >::_M_erase(std::priv::_Rb_tree_node_base*): error: undefined reference to 'std::__node_alloc::_M_deallocate(void*, unsigned int)'
C:/NVPACK/android-ndk-r9c/sources/sfml/lib/armeabi/libsfml-main.a(MainAndroid.cpp.o):MainAndroid.cpp:function std::priv::_Rb_tree<int, std::less<int>, std::pair<int const, sf::Vector2<int> >, std::priv::_Select1st<std::pair<int const, sf::Vector2<int> > >, std::priv::_MapTraitsT<std::pair<int const, sf::Vector2<int> > >, std::allocator<std::pair<int const, sf::Vector2<int> > > >::_M_erase(std::priv::_Rb_tree_node_base*): error: undefined reference to 'std::__node_alloc::_M_deallocate(void*, unsigned int)'
C:/NVPACK/android-ndk-r9c/sources/sfml/lib/armeabi/libsfml-main.a(MainAndroid.cpp.o):MainAndroid.cpp:function std::priv::_Rb_tree<int, std::less<int>, std::pair<int const, sf::Vector2<int> >, std::priv::_Select1st<std::pair<int const, sf::Vector2<int> > >, std::priv::_MapTraitsT<std::pair<int const, sf::Vector2<int> > >, std::allocator<std::pair<int const, sf::Vector2<int> > > >::_M_erase(std::priv::_Rb_tree_node_base*): error: undefined reference to 'std::__node_alloc::_M_deallocate(void*, unsigned int)'
C:/NVPACK/android-ndk-r9c/sources/sfml/lib/armeabi/libsfml-main.a(MainAndroid.cpp.o):MainAndroid.cpp:function std::priv::_Rb_tree<int, std::less<int>, std::pair<int const, sf::Vector2<int> >, std::priv::_Select1st<std::pair<int const, sf::Vector2<int> > >, std::priv::_MapTraitsT<std::pair<int const, sf::Vector2<int> > >, std::allocator<std::pair<int const, sf::Vector2<int> > > >::_M_erase(std::priv::_Rb_tree_node_base*): error: undefined reference to 'std::__node_alloc::_M_deallocate(void*, unsigned int)'
C:/NVPACK/android-ndk-r9c/sources/sfml/lib/armeabi/libsfml-main.a(MainAndroid.cpp.o):MainAndroid.cpp:function onDestroy(ANativeActivity*): error: undefined reference to 'std::locale::~locale()'
C:/NVPACK/android-ndk-r9c/sources/sfml/lib/armeabi/libsfml-main.a(MainAndroid.cpp.o):MainAndroid.cpp:function onDestroy(ANativeActivity*): error: undefined reference to 'std::locale::~locale()'
collect2.exe: error: ld returned 1 exit status
make.exe: *** [obj/local/armeabi/libsfml-example.so] Error 1

I read at https://github.com/SFML/SFML/wiki/Tutorial:-Building-SFML-for-Android that in order to fix these errors, I should instead use cmake with the command

Code: [Select]
cmake -DANDROID_ABI=armeabi -DCMAKE_TOOLCHAIN_FILE=../../cmake/toolchains/android.toolchain.cmake ../.. -G "MinGW Makefiles" -DANDROID_STL=c++_shared
However, when using -DANDROID_STL=c++_shared, I can't even build SFML due to these errors:

Code: [Select]
[  1%] Building CXX object src/SFML/System/CMakeFiles/sfml-system.dir/Err.cpp.o
In file included from C:\NVPACK\android-ndk-r9c\sources\cxx-stl\llvm-libc++\libcxx\include/algorithm:627:0,
                 from C:\NVPACK\android-ndk-r9c\sources\cxx-stl\llvm-libc++\libcxx\include/string:434,
                 from C:\NVPACK\android-ndk-r9c\sources\cxx-stl\llvm-libc++\libcxx\include/__locale:15,
                 from C:\NVPACK\android-ndk-r9c\sources\cxx-stl\llvm-libc++\libcxx\include/ios:216,
                 from C:\NVPACK\android-ndk-r9c\sources\cxx-stl\llvm-libc++\libcxx\include/ostream:130,
                 from C:\Users\Treyten\Desktop\WorldofHello\SFML-android\include/SFML/System/Err.hpp:32,
                 from C:\Users\Treyten\Desktop\WorldofHello\SFML-android\src\SFML\System\Err.cpp:28:
C:\NVPACK\android-ndk-r9c\sources\cxx-stl\llvm-libc++\libcxx\include/memory:3835:37: error: default template arguments may not be used in function templates without -std=c++11 or -std=gnu++11
         explicit shared_ptr(_Yp* __p);
                                     ^
C:\NVPACK\android-ndk-r9c\sources\cxx-stl\llvm-libc++\libcxx\include/memory:3842:37: error: default template arguments may not be used in function templates without -std=c++11 or -std=gnu++11
         shared_ptr(_Yp* __p, _Dp __d);
                                     ^
C:\NVPACK\android-ndk-r9c\sources\cxx-stl\llvm-libc++\libcxx\include/memory:3849:49: error: default template arguments may not be used in function templates without -std=c++11 or -std=gnu++11
         shared_ptr(_Yp* __p, _Dp __d, _Alloc __a);
                                                 ^
C:\NVPACK\android-ndk-r9c\sources\cxx-stl\llvm-libc++\libcxx\include/memory:3881:37: error: default template arguments may not be used in function templates without -std=c++11 or -std=gnu++11
         shared_ptr(auto_ptr<_Yp> __r);
                                     ^
C:\NVPACK\android-ndk-r9c\sources\cxx-stl\llvm-libc++\libcxx\include/memory:3910:83: error: default template arguments may not be used in function templates without -std=c++11 or -std=gnu++11
        typename enable_if<!is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
                                                                                   ^
C:\NVPACK\android-ndk-r9c\sources\cxx-stl\llvm-libc++\libcxx\include/memory:3919:82: error: default template arguments may not be used in function templates without -std=c++11 or -std=gnu++11
        typename enable_if<is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
                                                                                  ^
In file included from C:\NVPACK\android-ndk-r9c\sources\cxx-stl\llvm-libc++\libcxx\include/ostream:130:0,
                 from C:\Users\Treyten\Desktop\WorldofHello\SFML-android\include/SFML/System/Err.hpp:32,
                 from C:\Users\Treyten\Desktop\WorldofHello\SFML-android\src\SFML\System\Err.cpp:28:
C:\NVPACK\android-ndk-r9c\sources\cxx-stl\llvm-libc++\libcxx\include/ios:411:68: error: 'io_errc' is not a class or namespace
     explicit failure(const string& __msg, const error_code& __ec = io_errc::stream);
                                                                    ^
C:\NVPACK\android-ndk-r9c\sources\cxx-stl\llvm-libc++\libcxx\include/ios:412:66: error: 'io_errc' is not a class or namespace
     explicit failure(const char* __msg, const error_code& __ec = io_errc::stream);
                                                                  ^
make[2]: *** [src/SFML/System/CMakeFiles/sfml-system.dir/Err.cpp.o] Error 1
make[1]: *** [src/SFML/System/CMakeFiles/sfml-system.dir/all] Error 2

Ideas would be helpful.

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: Errors building SFML for Android
« Reply #6 on: October 11, 2017, 06:34:20 pm »
You can upgrade your ndk to r12 to use libc++ with sfml master. Or use the latest ndk Version and the PR from above.

It shouldn't affect your code at all.

Ndk r9 is very old i am not sure if libc++ was somewhere complete and stable at the time. You could also try gnustl (but look at the license) which may work in r9 with a descent STL support


AlexAUT

LunaRebirth

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Errors building SFML for Android
« Reply #7 on: October 12, 2017, 02:42:55 pm »
Awesome.

Lastly, the example project builds and runs on my phone just fine.
But when I try to use just SFML's audio in my project, I get a crash right as sf::Music::openFromFile is called.

Here is my trace:
Code: [Select]
10-12 07:37:43.388   651   651 F DEBUG   :     #00 pc 00005f22  /data/app/com.Project-1/lib/arm/libsfml-system.so (_ZN2sf5Mutex4lockEv+1)
10-12 07:37:43.389   651   651 F DEBUG   :     #01 pc 00005ecd  /data/app/com.Project-1/lib/arm/libsfml-system.so (_ZN2sf4LockC2ERNS_5MutexE+8)
10-12 07:37:43.389   651   651 F DEBUG   :     #02 pc 000092a9  /data/app/com.Project-1/lib/arm/libsfml-system.so (_ZN2sf4priv14ResourceStreamC1ERKNSt6__nd k112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEE+40)
10-12 07:37:43.389   651   651 F DEBUG   :     #03 pc 0000879d  /data/app/com.Project-1/lib/arm/libsfml-system.so (_ZN2sf15FileInputStream4openERKNSt6__ndk 112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE+28)
10-12 07:37:43.389   651   651 F DEBUG   :     #04 pc 0001c515  /data/app/com.Project-1/lib/arm/libsfml-audio.so (_ZN2sf16SoundFileFactory24createReaderFro mFilenameERKNSt6__ndk112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE+ 40)
10-12 07:37:43.389   651   651 F DEBUG   :     #05 pc 0001a2f3  /data/app/com.Project-1/lib/arm/libsfml-audio.so (_ZN2sf14InputSoundFile12openFromFileERKNS t6__ndk112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE+14)
10-12 07:37:43.389   651   651 F DEBUG   :     #06 pc 00018425  /data/app/com.Project-1/lib/arm/libsfml-audio.so (_ZN2sf5Music12openFromFileERKNSt6__ndk112 basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE+16)

I only added to my Android.mk file:
Code: [Select]
# ...
LOCAL_SHARED_LIBRARIES += sfml-audio
# ...
$(call import-module,sfml)
# ...

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: Errors building SFML for Android
« Reply #8 on: October 12, 2017, 07:05:28 pm »
The example project does include audio, and if this works something in your mk file is wrong. But we cannot tell without seeing it ;)


AlexAUT

LunaRebirth

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Errors building SFML for Android
« Reply #9 on: October 13, 2017, 12:33:16 am »
Sure, here it is. Using Irrlicht:

Code: [Select]
LOCAL_PATH := $(call my-dir)/..
IRRLICHT_PROJECT_PATH := $(LOCAL_PATH)

include $(CLEAR_VARS)
LOCAL_MODULE := Irrlicht
LOCAL_SRC_FILES := ../irrlicht-code-5543-branches-ogl-es/lib/Android/libIrrlicht.a
LOCAL_STATIC_LIBRARIES := src/liblua.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE := Project
APP_ALLOW_MISSING_DEPS := true

LOCAL_CFLAGS := -D_IRR_ANDROID_PLATFORM_ -pipe -fexceptions -fno-exceptions -fno-rtti -fstrict-aliasing -DLUA_ANSI -DLUA_USE_APICHECK

ifndef NDEBUG
LOCAL_CFLAGS += -g -D_DEBUG
else
LOCAL_CFLAGS += -fexpensive-optimizations -O3
endif

ifeq ($(TARGET_ARCH_ABI),x86)
LOCAL_CFLAGS += -fno-stack-protector
endif

LOCAL_C_INCLUDES := include ../irrlicht-code-5543-branches-ogl-es/include src/Lua ../SFML-android/include

FILE_LIST := $(wildcard $(LOCAL_PATH)/src/*.cpp)
LUA_FILE_LIST := $(wildcard $(LOCAL_PATH)/include/Lua/*.c*)
LOCAL_SRC_FILES := main.cpp $(FILE_LIST:$(LOCAL_PATH)/%=%) $(LUA_FILE_LIST:$(LOCAL_PATH)/%=%)

LOCAL_LDLIBS := -lEGL -llog -lGLESv1_CM -lGLESv2 -lz -landroid -lm

LOCAL_STATIC_LIBRARIES := sfml-main Irrlicht android_native_app_glue
LOCAL_SHARED_LIBRARIES += libandroid
LOCAL_SHARED_LIBRARIES += sfml-system sfml-window sfml-graphics sfml-audio sfml-network
include $(BUILD_SHARED_LIBRARY)

$(call import-module,android/native_app_glue)
$(call import-module,sfml)

# copy Irrlicht data to assets

$(shell mkdir -p $(IRRLICHT_PROJECT_PATH)/assets)
$(shell mkdir -p $(IRRLICHT_PROJECT_PATH)/assets/media)
$(shell mkdir -p $(IRRLICHT_PROJECT_PATH)/assets/media/Shaders)
$(shell cp $(IRRLICHT_PROJECT_PATH)/media/Shaders/*.* $(IRRLICHT_PROJECT_PATH)/assets/media/Shaders/)
$(shell mkdir -p $(IRRLICHT_PROJECT_PATH)/assets/assets)
$(shell mkdir -p $(IRRLICHT_PROJECT_PATH)/assets/assets/media)
$(shell mkdir -p $(IRRLICHT_PROJECT_PATH)/assets/assets/media/Shaders)
$(shell cp $(IRRLICHT_PROJECT_PATH)/media/Shaders/*.* $(IRRLICHT_PROJECT_PATH)/assets/assets/media/Shaders/)

Ideally I'd use only sfml-audio. Either way, the program still crashes at the same spot.

I tried making sfml-main in LOCAL_WHOLE_STATIC_LIBRARIES, but then got a conflict error:
Code: [Select]
C:/NVPACK/android-ndk-r12b/build//../toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld.exe: error: ./obj/local/armeabi/libandroid_native_app_glue.a(android_native_app_glue.o): multiple definition of 'ANativeActivity_onCreate'
C:/NVPACK/android-ndk-r12b/build//../toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld.exe: C:/NVPACK/android-ndk-r12b/build//../sources/sfml/lib/armeabi/libsfml-main.a(MainAndroid.cpp.o): previous definition here
« Last Edit: October 13, 2017, 12:35:22 am by LunaRebirth »

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: Errors building SFML for Android
« Reply #10 on: October 13, 2017, 09:05:45 am »
Sadly you cannot use sfml-audio only out of the box. But have a look at sfmlActivity under src/main/. If you call this function yourself
loadLibrary("openal", lJNIEnv, ObjectActivityInfo);
you might be able to use sfml-audio as standalone. But I am not sure if this will work.

Another option could be loading openal  in your Java Activity, sadly I don't have the time to try it out and test it.
System.loadLibrary('openal')

AlexAUT
« Last Edit: October 13, 2017, 09:09:06 am by AlexAUT »

LunaRebirth

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Errors building SFML for Android
« Reply #11 on: October 14, 2017, 04:15:10 am »
Unfortunately it doesn't seem to work too well with Irrlicht and I'm getting a little frustrated that this is such a big process for audio.

Thanks for your help.

I copied a lot of that sfmlActivity file like so:
Code: [Select]
#ifdef _IRR_ANDROID_PLATFORM_
namespace {
    typedef void (*activityOnCreatePointer)(ANativeActivity*, void*, size_t);
}

const char *getLibraryName(JNIEnv* lJNIEnv, jobject& objectActivityInfo)
{
    // This function reads the value of meta-data "sfml.app.lib_name"
    // found in the Android Manifest file and returns it. It performs the
    // following Java code using the JNI interface:
    //
    // ai.metaData.getString("sfml.app.lib_name");
    static char name[256];

    // Get metaData instance from the ActivityInfo object
    jclass classActivityInfo = lJNIEnv->FindClass("android/content/pm/ActivityInfo");
    jfieldID fieldMetaData = lJNIEnv->GetFieldID(classActivityInfo, "metaData", "Landroid/os/Bundle;");
    jobject objectMetaData = lJNIEnv->GetObjectField(objectActivityInfo, fieldMetaData);

    // Create a java string object containing "sfml.app.lib_name"
    jobject objectName = lJNIEnv->NewStringUTF("sfml.app.lib_name");

    // Get the value of meta-data named "sfml.app.lib_name"
    jclass classBundle = lJNIEnv->FindClass("android/os/Bundle");
    jmethodID methodGetString = lJNIEnv->GetMethodID(classBundle, "getString", "(Ljava/lang/String;)Ljava/lang/String;");
    jstring valueString = (jstring)lJNIEnv->CallObjectMethod(objectMetaData, methodGetString, objectName);

    // No meta-data "sfml.app.lib_name" was found so we abort and inform the user
    if (valueString == NULL)
    {
        Game::log("No meta-data 'sfml.app.lib_name' found in AndroidManifest.xml file");
        exit(1);
    }

    // Convert the application name to a C++ string and return it
    const jsize applicationNameLength = lJNIEnv->GetStringUTFLength(valueString);
    const char* applicationName = lJNIEnv->GetStringUTFChars(valueString, NULL);

    if (applicationNameLength >= 256)
    {
        Game::log("The value of 'sfml.app.lib_name' must not be longer than 255 characters.");
        exit(1);
    }

    strncpy(name, applicationName, applicationNameLength);
    name[applicationNameLength] = '\0';
    lJNIEnv->ReleaseStringUTFChars(valueString, applicationName);

    return name;
}

void* loadLibrary (const char* libraryName, JNIEnv* lJNIEnv, jobject& ObjectActivityInfo)
{
    // Find out the absolute path of the library
    jclass ClassActivityInfo = lJNIEnv->FindClass("android/content/pm/ActivityInfo");
    jfieldID FieldApplicationInfo = lJNIEnv->GetFieldID(ClassActivityInfo, "applicationInfo", "Landroid/content/pm/ApplicationInfo;");
    jobject ObjectApplicationInfo = lJNIEnv->GetObjectField(ObjectActivityInfo, FieldApplicationInfo);

    jclass ClassApplicationInfo = lJNIEnv->FindClass("android/content/pm/ApplicationInfo");
    jfieldID FieldNativeLibraryDir = lJNIEnv->GetFieldID(ClassApplicationInfo, "nativeLibraryDir", "Ljava/lang/String;");

    jobject ObjectDirPath = lJNIEnv->GetObjectField(ObjectApplicationInfo, FieldNativeLibraryDir);

    jclass ClassSystem = lJNIEnv->FindClass("java/lang/System");
    jmethodID StaticMethodMapLibraryName = lJNIEnv->GetStaticMethodID(ClassSystem, "mapLibraryName", "(Ljava/lang/String;)Ljava/lang/String;");

    jstring LibNameObject = lJNIEnv->NewStringUTF(libraryName);
    jobject ObjectName = lJNIEnv->CallStaticObjectMethod(ClassSystem, StaticMethodMapLibraryName, LibNameObject);

    jclass ClassFile = lJNIEnv->FindClass("java/io/File");
    jmethodID FileConstructor = lJNIEnv->GetMethodID(ClassFile, "<init>", "(Ljava/lang/String;Ljava/lang/String;)V");
    jobject ObjectFile = lJNIEnv->NewObject(ClassFile, FileConstructor, ObjectDirPath, ObjectName);

    // Get the library absolute path and convert it
    jmethodID MethodGetPath = lJNIEnv->GetMethodID(ClassFile, "getPath", "()Ljava/lang/String;");
    jstring javaLibraryPath = static_cast<jstring>(lJNIEnv->CallObjectMethod(ObjectFile, MethodGetPath));
    const char* libraryPath = lJNIEnv->GetStringUTFChars(javaLibraryPath, NULL);

    // Manually load the library
    void * handle = dlopen(libraryPath, RTLD_NOW | RTLD_GLOBAL);
    if (!handle)
    {
        Game::log("dlopen(" + (std::string)libraryPath + "): " + (std::string)dlerror());
        exit(1);
    }

    // Release the Java string
    lJNIEnv->ReleaseStringUTFChars(javaLibraryPath, libraryPath);

    return handle;
}

void createSFML()
{
    JavaVM* lJavaVM = Game::state->activity->vm;
    JNIEnv* lJNIEnv = Game::state->activity->env;

    // Retrieve the NativeActivity
    jobject ObjectNativeActivity = Game::state->activity->clazz;
    jclass ClassNativeActivity = lJNIEnv->GetObjectClass(ObjectNativeActivity);

    // Retrieve the ActivityInfo
    jmethodID MethodGetPackageManager = lJNIEnv->GetMethodID(ClassNativeActivity, "getPackageManager", "()Landroid/content/pm/PackageManager;");
    jobject ObjectPackageManager = lJNIEnv->CallObjectMethod(ObjectNativeActivity, MethodGetPackageManager);

    jmethodID MethodGetIndent = lJNIEnv->GetMethodID(ClassNativeActivity, "getIntent", "()Landroid/content/Intent;");
    jobject ObjectIntent = lJNIEnv->CallObjectMethod(ObjectNativeActivity, MethodGetIndent);

    jclass ClassIntent = lJNIEnv->FindClass("android/content/Intent");
    jmethodID MethodGetComponent = lJNIEnv->GetMethodID(ClassIntent, "getComponent", "()Landroid/content/ComponentName;");

    jobject ObjectComponentName = lJNIEnv->CallObjectMethod(ObjectIntent, MethodGetComponent);

    jclass ClassPackageManager = lJNIEnv->FindClass("android/content/pm/PackageManager");

    jfieldID FieldGET_META_DATA = lJNIEnv->GetStaticFieldID(ClassPackageManager, "GET_META_DATA", "I");
    jint GET_META_DATA = lJNIEnv->GetStaticIntField(ClassPackageManager, FieldGET_META_DATA);

    jmethodID MethodGetActivityInfo = lJNIEnv->GetMethodID(ClassPackageManager, "getActivityInfo", "(Landroid/content/ComponentName;I)Landroid/content/pm/ActivityInfo;");
    jobject ObjectActivityInfo = lJNIEnv->CallObjectMethod(ObjectPackageManager, MethodGetActivityInfo, ObjectComponentName, GET_META_DATA);

    // Load our libraries in reverse order
#if defined(STL_LIBRARY)
#define _SFML_QS(s) _SFML_S(s)
#define _SFML_S(s) #s
    loadLibrary(_SFML_QS(STL_LIBRARY), lJNIEnv, ObjectActivityInfo);
#undef _SFML_S
#undef _SFML_QS
#endif
    loadLibrary("openal", lJNIEnv, ObjectActivityInfo);

#if !defined(SFML_DEBUG)
    loadLibrary("sfml-system", lJNIEnv, ObjectActivityInfo);
    loadLibrary("sfml-window", lJNIEnv, ObjectActivityInfo);
    loadLibrary("sfml-graphics", lJNIEnv, ObjectActivityInfo);
    loadLibrary("sfml-audio", lJNIEnv, ObjectActivityInfo);
    loadLibrary("sfml-network", lJNIEnv, ObjectActivityInfo);
#else
    loadLibrary("sfml-system-d", lJNIEnv, ObjectActivityInfo);
    loadLibrary("sfml-window-d", lJNIEnv, ObjectActivityInfo);
    loadLibrary("sfml-graphics-d", lJNIEnv, ObjectActivityInfo);
    loadLibrary("sfml-audio-d", lJNIEnv, ObjectActivityInfo);
    loadLibrary("sfml-network-d", lJNIEnv, ObjectActivityInfo);
#endif

    void* handle = loadLibrary(getLibraryName(lJNIEnv, ObjectActivityInfo), lJNIEnv, ObjectActivityInfo);

    // Call the original ANativeActivity_onCreate function
    activityOnCreatePointer ANativeActivity_onCreate = (activityOnCreatePointer)dlsym(handle, "ANativeActivity_onCreate");

    if (!ANativeActivity_onCreate)
    {
        Game::log("sfml-activity: Undefined symbol ANativeActivity_onCreate");
        exit(1);
    }
}

/* Main application code. */
void android_main(android_app* app)
{
// Make sure glue isn't stripped.
app_dummy();

SIrrlichtCreationParameters param;
//param.DriverType = EDT_OGLES1; // android:glEsVersion in AndroidManifest.xml should be "0x00010000" (requesting 0x00020000 will also guarantee that ES1 works)
param.DriverType = EDT_OGLES2; // android:glEsVersion in AndroidManifest.xml should be "0x00020000"
param.WindowSize = dimension2d<u32>(0,0); // using 0,0 it will automatically set it to the maximal size
param.PrivateData = app;
param.Bits = 24;
param.ZBufferBits = 16;
param.AntiAlias  = 0;
param. EventReceiver = &Game::receiver;

#ifndef _DEBUG
param.LoggingLevel = ELL_NONE;
#endif

IrrlichtDevice *device = createDeviceEx(param);
if (device == 0)
             return;

        Game::device = device;
Game::driver = device->getVideoDriver();
Game::smgr = device->getSceneManager();
Game::guienv = device->getGUIEnvironment();
Game::logger = device->getLogger();
Game::fs = device->getFileSystem();

ANativeWindow* nativeWindow = static_cast<ANativeWindow*>(Game::driver->getExposedVideoData().OGLESAndroid.Window);
int32_t windowWidth = ANativeWindow_getWidth(app->window);
int32_t windowHeight = ANativeWindow_getHeight(app->window);

        Game::state = app;

    createSFML();

        //...

From this I am getting the crash trace:
Code: [Select]
10-13 21:06:04.078  8084  8084 F DEBUG   : backtrace:
10-13 21:06:04.078  8084  8084 F DEBUG   :     #00 pc 002387fc  /system/lib/libart.so (_ZN3art9JavaVMExt8JniAbortEPKcS2_+47)
10-13 21:06:04.078  8084  8084 F DEBUG   :     #01 pc 0023903f  /system/lib/libart.so (_ZN3art9JavaVMExt9JniAbortVEPKcS2_St9__va_list+58)
10-13 21:06:04.078  8084  8084 F DEBUG   :     #02 pc 000ca31b  /system/lib/libart.so (_ZN3art11ScopedCheck6AbortFEPKcz+46)
10-13 21:06:04.078  8084  8084 F DEBUG   :     #03 pc 000c9e37  /system/lib/libart.so (_ZN3art11ScopedCheck11CheckThreadEP7_JNIEnv+154)
10-13 21:06:04.078  8084  8084 F DEBUG   :     #04 pc 000c8f1f  /system/lib/libart.so (_ZN3art11ScopedCheck22CheckPossibleHeapValueERNS_18ScopedObjectAccessEcNS_12JniValueTypeE+26)
10-13 21:06:04.078  8084  8084 F DEBUG   :     #05 pc 000c83fb  /system/lib/libart.so (_ZN3art11ScopedCheck5CheckERNS_18ScopedObjectAccessEbPKcPNS_12JniValueTypeE+802)
10-13 21:06:04.078  8084  8084 F DEBUG   :     #06 pc 000c0f75  /system/lib/libart.so (_ZN3art8CheckJNI14GetObjectClassEP7_JNIEnvP8_jobject+444)
10-13 21:06:04.078  8084  8084 F DEBUG   :     #07 pc 0014a9b1  /data/app/com.Project-1/lib/arm/libProject.so (_Z10createSFMLv+36)
10-13 21:06:04.078  8084  8084 F DEBUG   :     #08 pc 0014ad1d  /data/app/com.Project-1/lib/arm/libProject.so (android_main+448)
10-13 21:06:04.078  8084  8084 F DEBUG   :     #09 pc 002bf8ff  /data/app/com.Project-1/lib/arm/libProject.so
10-13 21:06:04.078  8084  8084 F DEBUG   :     #10 pc 00046eb3  /system/lib/libc.so (_ZL15__pthread_startPv+22)
10-13 21:06:04.078  8084  8084 F DEBUG   :     #11 pc 00019acd  /system/lib/libc.so (__start_thread+6)