Navigation Menu

Skip to content

Commit

Permalink
Fixed several issues
Browse files Browse the repository at this point in the history
- Cmake errored out due to the ANDROID_NDK_* variables being used before being set/detected for the first time.
- Fixed one warning regarding one string replace in CMake.
- Fixed warnings when compiling SFML-Activity.
  • Loading branch information
MarioLiebisch authored and intjelic committed Apr 20, 2014
1 parent 75ddae7 commit 84bd8c6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 33 deletions.
54 changes: 27 additions & 27 deletions cmake/toolchains/android.toolchain.cmake
Expand Up @@ -367,32 +367,6 @@ if( ANDROID_FORBID_SYGWIN )
endif()
endif()

# detect current host platform
set( ANDROID_NDK_HOST_SYSTEM_ARCH "x86" )
set( TOOL_OS_SUFFIX "" )
if( CMAKE_HOST_APPLE )
set( ANDROID_NDK_HOST_SYSTEM_NAME "darwin-x86" )
if(NOT EXISTS "${ANDROID_NDK}/toolchains/arm-linux-androideabi-4.6/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME}")
set( ANDROID_NDK_HOST_SYSTEM_NAME "darwin-x86_64" )
set( ANDROID_NDK_HOST_SYSTEM_ARCH "x64" )
endif()
elseif( CMAKE_HOST_WIN32 )
set( ANDROID_NDK_HOST_SYSTEM_NAME "windows" )
set( TOOL_OS_SUFFIX ".exe" )
if(NOT EXISTS "${ANDROID_NDK}/toolchains/arm-linux-androideabi-4.6/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME}")
set( ANDROID_NDK_HOST_SYSTEM_NAME "windows-x86_64" )
set( ANDROID_NDK_HOST_SYSTEM_ARCH "x64" )
endif()
elseif( CMAKE_HOST_UNIX )
set( ANDROID_NDK_HOST_SYSTEM_NAME "linux-x86" )
if(NOT EXISTS "${ANDROID_NDK}/toolchains/arm-linux-androideabi-4.6/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME}")
set( ANDROID_NDK_HOST_SYSTEM_NAME "linux-x86_64" )
set( ANDROID_NDK_HOST_SYSTEM_ARCH "x64" )
endif()
else()
message( FATAL_ERROR "Cross-compilation on your platform is not supported by this cmake toolchain" )
endif()

# see if we have path to Android NDK
__INIT_VARIABLE( ANDROID_NDK PATH ENV_ANDROID_NDK )
if( NOT ANDROID_NDK )
Expand Down Expand Up @@ -466,6 +440,32 @@ else()
sudo ln -s ~/my-android-toolchain ${ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH}" )
endif()

# detect current host platform
set( ANDROID_NDK_HOST_SYSTEM_ARCH "x86" )
set( TOOL_OS_SUFFIX "" )
if( CMAKE_HOST_APPLE )
set( ANDROID_NDK_HOST_SYSTEM_NAME "darwin-x86" )
if(NOT EXISTS "${ANDROID_NDK}/toolchains/arm-linux-androideabi-4.6/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME}")
set( ANDROID_NDK_HOST_SYSTEM_NAME "darwin-x86_64" )
set( ANDROID_NDK_HOST_SYSTEM_ARCH "x64" )
endif()
elseif( CMAKE_HOST_WIN32 )
set( ANDROID_NDK_HOST_SYSTEM_NAME "windows" )
set( TOOL_OS_SUFFIX ".exe" )
if(NOT EXISTS "${ANDROID_NDK}/toolchains/arm-linux-androideabi-4.6/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME}")
set( ANDROID_NDK_HOST_SYSTEM_NAME "windows-x86_64" )
set( ANDROID_NDK_HOST_SYSTEM_ARCH "x64" )
endif()
elseif( CMAKE_HOST_UNIX )
set( ANDROID_NDK_HOST_SYSTEM_NAME "linux-x86" )
if(NOT EXISTS "${ANDROID_NDK}/toolchains/arm-linux-androideabi-4.6/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME}")
set( ANDROID_NDK_HOST_SYSTEM_NAME "linux-x86_64" )
set( ANDROID_NDK_HOST_SYSTEM_ARCH "x64" )
endif()
else()
message( FATAL_ERROR "Cross-compilation on your platform is not supported by this cmake toolchain" )
endif()

# get all the details about standalone toolchain
if( BUILD_WITH_STANDALONE_TOOLCHAIN )
__DETECT_NATIVE_API_LEVEL( ANDROID_SUPPORTED_NATIVE_API_LEVELS "${ANDROID_STANDALONE_TOOLCHAIN}/sysroot/usr/include/android/api-level.h" )
Expand Down Expand Up @@ -538,7 +538,7 @@ __INIT_VARIABLE( ANDROID_ABI OBSOLETE_ARM_TARGET OBSOLETE_ARM_TARGETS VALUES ${A
# verify that target ABI is supported
list( FIND ANDROID_SUPPORTED_ABIS "${ANDROID_ABI}" __androidAbiIdx )
if( __androidAbiIdx EQUAL -1 )
string( REPLACE ";" "\", \"", PRINTABLE_ANDROID_SUPPORTED_ABIS "${ANDROID_SUPPORTED_ABIS}" )
string( REPLACE ";" "\", \"" PRINTABLE_ANDROID_SUPPORTED_ABIS "${ANDROID_SUPPORTED_ABIS}" )
message( FATAL_ERROR "Specified ANDROID_ABI = \"${ANDROID_ABI}\" is not supported by this cmake toolchain or your NDK/toolchain.
Supported values are: \"${PRINTABLE_ANDROID_SUPPORTED_ABIS}\"
" )
Expand Down
17 changes: 11 additions & 6 deletions src/SFML/Main/SFMLActivity.cpp
Expand Up @@ -32,6 +32,10 @@

#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_INFO, "sfml-activity", __VA_ARGS__))

namespace {
typedef void (*activityOnCreatePointer)(ANativeActivity*, void*, size_t);
}

std::string getLibraryName(JNIEnv* lJNIEnv, jobject& objectActivityInfo)
{
// This function reads the value of meta-data "sfml.app.lib_name"
Expand All @@ -51,19 +55,20 @@ std::string getLibraryName(JNIEnv* lJNIEnv, jobject& objectActivityInfo)
// 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;");
jobject objectValue = lJNIEnv->CallObjectMethod(objectMetaData, methodGetString, objectName);
jstring valueString = (jstring)lJNIEnv->CallObjectMethod(objectMetaData, methodGetString, objectName);

// No meta-data "sfml.app.lib_name" was found so we abord and inform the user
if (objectValue == NULL)
if (valueString == NULL)
{
LOGE("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 char* applicationName = lJNIEnv->GetStringUTFChars(objectValue, NULL);
std::string ret(applicationName);
lJNIEnv->ReleaseStringUTFChars(objectValue, applicationName);
const jsize applicationNameLength = lJNIEnv->GetStringUTFLength(valueString);
const char* applicationName = lJNIEnv->GetStringUTFChars(valueString, NULL);
std::string ret(applicationName, applicationNameLength);
lJNIEnv->ReleaseStringUTFChars(valueString, applicationName);

return ret;
}
Expand Down Expand Up @@ -187,7 +192,7 @@ void ANativeActivity_onCreate(ANativeActivity* activity, void* savedState, size_
// crashes (lJavaVM->DetachCurrentThread();)

// Call the original ANativeActivity_onCreate function
void (*ANativeActivity_onCreate)(ANativeActivity*, void*, size_t) = dlsym(handle, "ANativeActivity_onCreate");
activityOnCreatePointer ANativeActivity_onCreate = (activityOnCreatePointer)dlsym(handle, "ANativeActivity_onCreate");

if (!ANativeActivity_onCreate)
{
Expand Down

0 comments on commit 84bd8c6

Please sign in to comment.