Android: Updated the toolchain file and CMake scripts
* Replaced the toolchain file with a new version based on [zuhowei's fork](https://github.com/zhuowei/android-cmake), which enables x64 builds as well as support for the latest NDK. This breaks compatibility with old build directories. * Removed the STL dependency from **sfml-activity** rather than relying on *some* implementation implicitly linked by default. * Deleted *project.properties*, which wasn't supposed to be part of the repository code. You have to use the Android SDK to recreate it (`android update project --path to/your/example --target 1 --name SFML-Example`). * Made it possible to select a STL implementation to be used (default: `c++_shared`). Keep in mind that not all available configurations are necessarily compatible with SFML. * Fixed linker flags to be compatible with Nvidia's Nsight Tegra for Visual Studio. * It is now possible to compile the Android version using Nvidia's Nsight Tegra for Visual Studio (requires up-to-date CMake and `CMAKE_SFML_SYSTEM` to be set to `Android`; keep in mind that this is still experimental and requires further CMake updates). * Updated and renamed some Android specific CMake variables. * Made `armeabi-v7a` the default ABI for Android builds.
This commit is contained in:
parent
1de7644277
commit
34692d5a39
11 changed files with 1307 additions and 677 deletions
|
@ -56,7 +56,7 @@ include_directories(${OPENAL_INCLUDE_DIR} ${SNDFILE_INCLUDE_DIR})
|
|||
|
||||
# build the list of external libraries to link
|
||||
if(SFML_OS_ANDROID)
|
||||
list(APPEND AUDIO_EXT_LIBS -landroid -lOpenSLES)
|
||||
list(APPEND AUDIO_EXT_LIBS android OpenSLES)
|
||||
endif()
|
||||
list(APPEND AUDIO_EXT_LIBS ${OPENAL_LIBRARY} ${SNDFILE_LIBRARY})
|
||||
|
||||
|
|
|
@ -138,7 +138,7 @@ endif()
|
|||
if(SFML_OS_IOS)
|
||||
list(APPEND GRAPHICS_EXT_LIBS "-framework OpenGLES")
|
||||
elseif(SFML_OS_ANDROID)
|
||||
list(APPEND GRAPHICS_EXT_LIBS -lz)
|
||||
list(APPEND GRAPHICS_EXT_LIBS z)
|
||||
endif()
|
||||
list(APPEND GRAPHICS_EXT_LIBS ${FREETYPE_LIBRARY} ${JPEG_LIBRARY})
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include <SFML/Config.hpp>
|
||||
#include <string>
|
||||
#include <android/native_activity.h>
|
||||
#include <android/log.h>
|
||||
#include <dlfcn.h>
|
||||
|
@ -37,13 +36,14 @@ namespace {
|
|||
typedef void (*activityOnCreatePointer)(ANativeActivity*, void*, size_t);
|
||||
}
|
||||
|
||||
std::string getLibraryName(JNIEnv* lJNIEnv, jobject& objectActivityInfo)
|
||||
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");
|
||||
|
@ -58,7 +58,7 @@ std::string getLibraryName(JNIEnv* lJNIEnv, jobject& objectActivityInfo)
|
|||
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 abord and inform the user
|
||||
// No meta-data "sfml.app.lib_name" was found so we abort and inform the user
|
||||
if (valueString == NULL)
|
||||
{
|
||||
LOGE("No meta-data 'sfml.app.lib_name' found in AndroidManifest.xml file");
|
||||
|
@ -68,10 +68,18 @@ std::string getLibraryName(JNIEnv* lJNIEnv, jobject& objectActivityInfo)
|
|||
// Convert the application name to a C++ string and return it
|
||||
const jsize applicationNameLength = lJNIEnv->GetStringUTFLength(valueString);
|
||||
const char* applicationName = lJNIEnv->GetStringUTFChars(valueString, NULL);
|
||||
std::string ret(applicationName, applicationNameLength);
|
||||
|
||||
if (applicationNameLength >= 256)
|
||||
{
|
||||
LOGE("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 ret;
|
||||
return name;
|
||||
}
|
||||
|
||||
void* loadLibrary(const char* libraryName, JNIEnv* lJNIEnv, jobject& ObjectActivityInfo)
|
||||
|
@ -159,7 +167,13 @@ void ANativeActivity_onCreate(ANativeActivity* activity, void* savedState, size_
|
|||
jobject ObjectActivityInfo = lJNIEnv->CallObjectMethod(ObjectPackageManager, MethodGetActivityInfo, ObjectComponentName, GET_META_DATA);
|
||||
|
||||
// Load our libraries in reverse order
|
||||
loadLibrary("c++_shared", lJNIEnv, ObjectActivityInfo);
|
||||
#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("sndfile", lJNIEnv, ObjectActivityInfo);
|
||||
loadLibrary("openal", lJNIEnv, ObjectActivityInfo);
|
||||
|
||||
|
@ -177,8 +191,7 @@ void ANativeActivity_onCreate(ANativeActivity* activity, void* savedState, size_
|
|||
loadLibrary("sfml-network-d", lJNIEnv, ObjectActivityInfo);
|
||||
#endif
|
||||
|
||||
std::string libName = getLibraryName(lJNIEnv, ObjectActivityInfo);
|
||||
void* handle = loadLibrary(libName.c_str(), lJNIEnv, ObjectActivityInfo);
|
||||
void* handle = loadLibrary(getLibraryName(lJNIEnv, ObjectActivityInfo), lJNIEnv, ObjectActivityInfo);
|
||||
|
||||
// Call the original ANativeActivity_onCreate function
|
||||
activityOnCreatePointer ANativeActivity_onCreate = (activityOnCreatePointer)dlsym(handle, "ANativeActivity_onCreate");
|
||||
|
|
|
@ -227,7 +227,7 @@ elseif(SFML_OS_MACOSX)
|
|||
elseif(SFML_OS_IOS)
|
||||
list(APPEND WINDOW_EXT_LIBS "-framework Foundation -framework UIKit -framework CoreGraphics -framework QuartzCore -framework CoreMotion")
|
||||
elseif(SFML_OS_ANDROID)
|
||||
list(APPEND WINDOW_EXT_LIBS "-landroid")
|
||||
list(APPEND WINDOW_EXT_LIBS android)
|
||||
endif()
|
||||
if(SFML_OPENGL_ES)
|
||||
if(SFML_OS_LINUX)
|
||||
|
@ -235,7 +235,7 @@ if(SFML_OPENGL_ES)
|
|||
elseif(SFML_OS_IOS)
|
||||
list(APPEND WINDOW_EXT_LIBS "-framework OpenGLES")
|
||||
elseif(SFML_OS_ANDROID)
|
||||
list(APPEND WINDOW_EXT_LIBS "-lEGL -lGLESv1_CM")
|
||||
list(APPEND WINDOW_EXT_LIBS EGL GLESv1_CM)
|
||||
endif()
|
||||
else()
|
||||
list(APPEND WINDOW_EXT_LIBS ${OPENGL_gl_LIBRARY})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue