SDL: renamed libcrypto and libssl to avoid clashing with system libraries, fixed crashes in SD card Java code

This commit is contained in:
Sergii Pylypenko
2016-06-10 19:43:32 +03:00
parent 90cc2821a6
commit cbd8374185
11 changed files with 56 additions and 20 deletions

View File

@@ -32,6 +32,7 @@ class Globals
public static String ApplicationName = "CommanderGenius";
public static String AppLibraries[] = { "sdl-1.2", };
public static String AppMainLibraries[] = { "application", "sdl_main" };
public static String LibraryNamesMap[][] = { { "crypto", "crypto.so.sdl.0" }, { "ssl", "ssl.so.sdl.0" }, { "curl", "curl-sdl" } }; // Because some libraries are named differently to not clash with system libs
public static final boolean Using_SDL_1_3 = false;
public static final boolean Using_SDL_2_0 = false;
public static String[] DataDownloadUrl = { "Data files are 2 Mb|https://sourceforge.net/projects/libsdl-android/files/CommanderGenius/commandergenius-data.zip/download", "High-quality GFX and music - 40 Mb|https://sourceforge.net/projects/libsdl-android/files/CommanderGenius/commandergenius-hqp.zip/download" };

View File

@@ -1241,8 +1241,9 @@ public class MainActivity extends Activity
// Load all libraries
try
{
for(String l : Globals.AppLibraries)
for(String l_unmapped : Globals.AppLibraries)
{
String l = GetMappedLibraryName(l_unmapped);
try
{
String libname = System.mapLibraryName(l);
@@ -1342,8 +1343,9 @@ public class MainActivity extends Activity
out.close();
}
for(String l : Globals.AppLibraries)
for(String l_unmapped : Globals.AppLibraries)
{
String l = GetMappedLibraryName(l_unmapped);
String libname = System.mapLibraryName(l);
File libpath = new File(libDir, libname);
Log.i("SDL", "libSDL: loading lib " + libpath.getPath());
@@ -1467,10 +1469,20 @@ public class MainActivity extends Activity
}
};
public static String GetMappedLibraryName(final String s)
{
for (int i = 0; i < Globals.LibraryNamesMap.length; i++)
{
if( Globals.LibraryNamesMap[i][0].equals(s) )
return Globals.LibraryNamesMap[i][1];
}
return s;
}
public static void LoadApplicationLibrary(final Context context)
{
Settings.nativeChdir(Globals.DataDir);
for(String l : Globals.AppMainLibraries)
for(String l: Globals.AppMainLibraries)
{
try
{

View File

@@ -773,6 +773,12 @@ class Settings
@Override
public String path(final Context p)
{
if( p.getExternalFilesDir(null) == null )
{
if( Environment.getExternalStorageDirectory() == null )
return "/sdcard/Android/data/" + p.getPackageName() + "/files";
return Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/" + p.getPackageName() + "/files";
}
return p.getExternalFilesDir(null).getAbsolutePath();
}
@Override
@@ -807,8 +813,11 @@ class Settings
{
if( path == null )
continue;
StatFs stat = new StatFs(path.getPath());
long size = (long)stat.getAvailableBlocks() * stat.getBlockSize() / 1024 / 1024;
long size = -1;
try {
StatFs stat = new StatFs(path.getPath());
size = (long)stat.getAvailableBlocks() * stat.getBlockSize() / 1024 / 1024;
} catch (Exception ee) {} // Can throw an exception if we cannot read from SD card
try {
path.mkdirs();

View File

@@ -91,10 +91,10 @@ class SettingsMenuMisc extends SettingsMenu
long freePhone = 0;
try
{
StatFs sdcard = new StatFs(Settings.SdcardAppPath.get().bestPath(p));
StatFs phone = new StatFs(p.getFilesDir().getAbsolutePath());
freeSdcard = (long)sdcard.getAvailableBlocks() * sdcard.getBlockSize() / 1024 / 1024;
freePhone = (long)phone.getAvailableBlocks() * phone.getBlockSize() / 1024 / 1024;
StatFs sdcard = new StatFs(Settings.SdcardAppPath.get().bestPath(p));
freeSdcard = (long)sdcard.getAvailableBlocks() * sdcard.getBlockSize() / 1024 / 1024;
}
catch(Exception e) {}

View File

@@ -9,7 +9,7 @@ ICONV := $(foreach ARCH, $(ARCHES32), iconv/lib/$(ARCH)/libiconv.so iconv/lib/$(
ICU_LIBS := data i18n io le lx test tu uc
ICU := $(foreach ARCH, $(ARCHES32), $(foreach NAME, $(ICU_LIBS), icuuc/lib/$(ARCH)/libicu$(NAME).a))
OPENSSL := $(foreach ARCH, $(ARCHES32), openssl/lib-$(ARCH)/libcrypto.so openssl/lib-$(ARCH)/libssl.so)
OPENSSL := $(foreach ARCH, $(ARCHES32), openssl/lib-$(ARCH)/libcrypto.so.sdl.0.so openssl/lib-$(ARCH)/libssl.so.sdl.0.so)
LIBS := $(ICONV) $(ICU) $(OPENSSL)

View File

@@ -63,6 +63,11 @@ SDL_APP_LIB_DEPENDS-$(TARGET_ARCH_ABI) := $(LOCAL_PATH)/src/AndroidBuild.sh $(LO
SDL_APP_LIB_DEPENDS-$(TARGET_ARCH_ABI) += $(foreach LIB, $(LOCAL_SHARED_LIBRARIES), obj/local/$(TARGET_ARCH_ABI)/lib$(LIB).so)
SDL_APP_LIB_DEPENDS-$(TARGET_ARCH_ABI) += $(foreach LIB, $(LOCAL_STATIC_LIBRARIES), obj/local/$(TARGET_ARCH_ABI)/lib$(LIB).a)
.PHONY: obj/local/$(TARGET_ARCH_ABI)/libcrypto.so obj/local/$(TARGET_ARCH_ABI)/libssl.so obj/local/$(TARGET_ARCH_ABI)/libcurl.so
obj/local/$(TARGET_ARCH_ABI)/libcrypto.so: obj/local/$(TARGET_ARCH_ABI)/libcrypto.so.sdl.0.so
obj/local/$(TARGET_ARCH_ABI)/libssl.so: obj/local/$(TARGET_ARCH_ABI)/libssl.so.sdl.0.so
obj/local/$(TARGET_ARCH_ABI)/libcurl.so: obj/local/$(TARGET_ARCH_ABI)/libcurl-sdl.so
include $(BUILD_SHARED_LIBRARY)
ifneq ($(APPLICATION_CUSTOM_BUILD_SCRIPT),)
@@ -119,4 +124,10 @@ $(LOCAL_PATH)/src/libapplication-arm64-v8a.so: $(SDL_APP_LIB_DEPENDS-arm64-v8a)
cd $(LOCAL_PATH_SDL_APPLICATION)/src && $(PARALLEL_LOCK) && \
./AndroidBuild.sh arm64-v8a aarch64-linux-android && $(PARALLEL_UNLOCK)
obj/local/x86_64/libapplication.so: $(LOCAL_PATH)/src/libapplication-x86_64.so
$(LOCAL_PATH)/src/libapplication-x86_64.so: $(SDL_APP_LIB_DEPENDS-x86_64) OVERRIDE_CUSTOM_LIB
cd $(LOCAL_PATH_SDL_APPLICATION)/src && $(PARALLEL_LOCK) && \
./AndroidBuild.sh x86_64 x86_64-linux-android && $(PARALLEL_UNLOCK)
endif # $(APPLICATION_CUSTOM_BUILD_SCRIPT)

View File

@@ -7,10 +7,10 @@ AppName="OpenArena"
AppFullName=ws.openarena.sdl
# Application version code (integer)
AppVersionCode=08834
AppVersionCode=08835
# Application user-visible version name (string)
AppVersionName="0.8.8.34"
AppVersionName="0.8.8.35"
# Specify path to download application data in zip archive in the form 'Description|URL|MirrorURL^Description2|URL2|MirrorURL2^...'
# If you'll start Description with '!' symbol it will be enabled by default, other downloads should be selected by user from startup config menu

View File

@@ -72,12 +72,11 @@ LOCAL_SRC_FILES := $(addprefix lib/,$(CSOURCES))
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include $(LOCAL_PATH)/include/curl $(LOCAL_PATH)/lib $(LOCAL_PATH)/../openssl/include
LOCAL_CFLAGS += $(common_CFLAGS)
LOCAL_MODULE:= libcurl
LOCAL_MODULE := curl
LOCAL_MODULE_FILENAME := libcurl-sdl # It clashes with system libcurl in Android 4.3 and older
LOCAL_SHARED_LIBRARIES := ssl crypto
#LOCAL_STATIC_LIBRARIES := ssl crypto
LOCAL_LDLIBS := -lz
include $(BUILD_SHARED_LIBRARY)

View File

@@ -3,16 +3,18 @@ LOCAL_PATH:=$(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := $(notdir $(LOCAL_PATH))
LOCAL_MODULE_FILENAME := lib$(notdir $(LOCAL_PATH)).so.sdl.0 # It clashes with system libcrypto and libssl in Android 4.3 and older
ifneq (openssl,$(LOCAL_MODULE))
ifneq ($(filter arm mips x86, $(TARGET_ARCH)),)
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_SRC_FILES := lib-$(TARGET_ARCH_ABI)/lib$(LOCAL_MODULE).so
LOCAL_SRC_FILES := lib-$(TARGET_ARCH_ABI)/lib$(LOCAL_MODULE).so.sdl.0.so
LOCAL_BUILT_MODULE := # This fixes a bug in NDK r10d
# NDK is buggy meh
obj/local/$(TARGET_ARCH_ABI)/lib$(LOCAL_MODULE).so: $(LOCAL_PATH)/$(LOCAL_SRC_FILES)
obj/local/$(TARGET_ARCH_ABI)/lib$(LOCAL_MODULE).so.sdl.0.so: $(LOCAL_PATH)/$(LOCAL_SRC_FILES)
cp -f $< $@
include $(PREBUILT_SHARED_LIBRARY)

View File

@@ -1,6 +1,6 @@
#!/bin/sh
ARCH_LIST="x86 mips armeabi-v7a armeabi" # armv5 is so outdated
ARCH_LIST="x86 mips armeabi-v7a armeabi"
mkdir -p build
@@ -20,16 +20,18 @@ build() {
cd build/$ARCH
tar -x -v -z -f ../../openssl-1.0.2h.tar.gz --strip=1
#sed -i.old 's/-Wl,-soname=[$][$]SHLIB[$][$]SHLIB_SOVER[$][$]SHLIB_SUFFIX//g' Makefile.shared
../../setCrossEnvironment-$ARCH.sh ./Configure shared zlib --prefix=`pwd`/dist $CONFIGURE_ARCH -fPIC || exit 1
# OpenSSL build system disables parallel compilation, -j4 won't do anything
../../setCrossEnvironment-$ARCH.sh make CALC_VERSIONS="SHLIB_COMPAT=; SHLIB_SOVER=" || exit 1
../../setCrossEnvironment-$ARCH.sh make CALC_VERSIONS='SHLIB_COMPAT=; SHLIB_SOVER=.sdl.0.so'
cd ../..
rm -rf lib-$ARCH
mkdir -p lib-$ARCH
cp build/$ARCH/libcrypto.so lib-${ARCH}/libcrypto.so || exit 1
cp build/$ARCH/libssl.so lib-${ARCH}/libssl.so || exit 1
cp build/$ARCH/libcrypto.so.sdl.0.so lib-${ARCH}/libcrypto.so.sdl.0.so || exit 1
cp build/$ARCH/libssl.so.sdl.0.so lib-${ARCH}/libssl.so.sdl.0.so || exit 1
}
PIDS=""