From 3cf64d3947a309cab41a828d12c152a958cbf097 Mon Sep 17 00:00:00 2001 From: MoNTE48 Date: Tue, 26 Jun 2018 01:58:52 +0200 Subject: [PATCH] Android: fix resolution, upd. irrlicht compile flags, add recommended ARMv7a and x86 flags, Android resolution fix by @sfan5 SRP fix by @red-001 (https://github.com/minetest/minetest/pull/7484) --- build/android/Makefile | 8 ++-- build/android/README.md | 14 +++--- build/android/jni/Android.mk | 44 ++++++++----------- build/android/jni/Application.mk | 2 +- build/android/jni/Deps.mk | 2 +- build/android/jni/Irrlicht.mk | 2 +- .../patches/irrlicht-optimization.patch | 20 ++++----- build/android/src/main/AndroidManifest.xml | 2 +- .../java/mobi/MultiCraft/GameActivity.java | 4 +- src/client/clientlauncher.cpp | 6 +++ src/porting_android.cpp | 5 +-- src/util/srp.cpp | 2 +- 12 files changed, 54 insertions(+), 57 deletions(-) diff --git a/build/android/Makefile b/build/android/Makefile index 14863fe6a..f7d541937 100644 --- a/build/android/Makefile +++ b/build/android/Makefile @@ -29,7 +29,7 @@ VERSION_PATCH := $(shell cat $(PROJ_ROOT)/CMakeLists.txt | \ TARGET_HOST = arm-linux TARGET_ABI = armeabi-v7a TARGET_TOOLCHAIN = arm-linux-androideabi -TARGET_CFLAGS_ADDON = -mfpu=vfpv3-d16 -march=armv7-a -Ofast -fdata-sections -ffunction-sections -fvisibility=hidden -flto -D__ANDROID_API__=$(API) +TARGET_CFLAGS_ADDON = -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb -Ofast -fdata-sections -ffunction-sections -fvisibility=hidden -flto -D__ANDROID_API__=$(API) TARGET_CXXFLAGS_ADDON = $(TARGET_CFLAGS_ADDON) TARGET_LDFLAGS_ADDON = -Wl,--no-warn-mismatch,--gc-sections,--icf=safe CROSS_PREFIX = arm-linux-androideabi @@ -41,7 +41,7 @@ CROSS_PREFIX = arm-linux-androideabi # TARGET_HOST = x86-linux # TARGET_ABI = x86 # TARGET_TOOLCHAIN = x86 -# TARGET_CFLAGS_ADDON = -Ofast -fdata-sections -ffunction-sections -fvisibility=hidden -flto -D__ANDROID_API__=$(API) +# TARGET_CFLAGS_ADDON = -march=i686 -mtune=intel -mssse3 -mfpmath=sse -m32 -Ofast -funroll-loops -fdata-sections -ffunction-sections -fvisibility=hidden -flto -D__ANDROID_API__=$(API) # TARGET_CXXFLAGS_ADDON = $(TARGET_CFLAGS_ADDON) # TARGET_LDFLAGS_ADDON = -Wl,--no-warn-mismatch,--gc-sections,--icf=safe # CROSS_PREFIX = i686-linux-android @@ -98,7 +98,7 @@ ICONV_URL_HTTP = https://ftp.gnu.org/pub/gnu/libiconv/libiconv-$(ICONV_VERSION). INTL_DIR = $(ANDR_ROOT)/deps/libintl INTL_URL_GIT = https://github.com/j-jorge/libintl-lite.git -SQLITE3_VERSION = 3230100 +SQLITE3_VERSION = 3240000 SQLITE3_DIR = $(ANDR_ROOT)/deps/sqlite SQLITE3_URL = https://www.sqlite.org/2018/sqlite-amalgamation-$(SQLITE3_VERSION).zip @@ -234,7 +234,7 @@ $(VORBIS_LIB): $(VORBIS_TIMESTAMP) if [ $$REFRESH -ne 0 ] ; then \ echo "changed timestamp for vorbis detected building..."; \ cd ${VORBIS_DIR}; \ - ${ANDROID_NDK}/ndk-build NDEBUG=${NDEBUG} \ + ${ANDROID_NDK}/ndk-build NDEBUG=${NDEBUG} TARGET_ABI=${TARGET_ABI} \ NDK_APPLICATION_MK=${ANDR_ROOT}/jni/Deps.mk || exit 1; \ touch ${VORBIS_TIMESTAMP}; \ touch ${VORBIS_TIMESTAMP_INT}; \ diff --git a/build/android/README.md b/build/android/README.md index 5b6f3967f..76b0afe8b 100644 --- a/build/android/README.md +++ b/build/android/README.md @@ -33,7 +33,7 @@ When a menu or inventory is displayed: Special settings ---------------- There are some settings especially useful for Android users. MultiCraft's config -file can usually be found at /sdcard/Android/data/mobi.MultiCraft. +file can usually be found at /sdcard/Android/data/mobi.MultiCraft/files. * gui_scaling: this is a user-specified scaling factor for the GUI- In case main menu is too big or small on your device, try changing this @@ -61,8 +61,8 @@ following software packages. The version number in parenthesis denotes the version that was tested at the time this README was drafted; newer/older versions may or may not work. -* android SDK (26.1.1) -* android NDK (r16b) +* android SDK (27+) +* android NDK (r17b) * wget * g++-multilib * m4 @@ -91,7 +91,7 @@ Release build: * Once your keystore is setup, enter build/android subdirectory and create a new file "ant.properties" there. Add following lines to that file: - + > key.store= > key.alias=MultiCraft @@ -104,10 +104,10 @@ Other things that may be nice to know ------------ * The environment for Android development tools is saved within Android build build folder. If you want direct access to it do: - + > make envpaths > . and_env - + After you've done this you'll have your path and path variables set correct to use adb and all other Android development tools @@ -122,7 +122,7 @@ Other things that may be nice to know > make clean_irrlicht -After compiling you need to archive files in assets into three zips - Files.zip, games.zip and worlds.zip. +After compiling you need to archive files in assets into three zips - Files.zip, games.zip and worlds.zip. games.zip must contain "games" folder. worlds.zip must contain "worlds" folder and "multicraf.conf" text file. Finally, remaining files must be packed into Files.zip. diff --git a/build/android/jni/Android.mk b/build/android/jni/Android.mk index 3b2dcddcc..de0b44669 100644 --- a/build/android/jni/Android.mk +++ b/build/android/jni/Android.mk @@ -38,13 +38,13 @@ LOCAL_SRC_FILES := deps/luajit/src/libluajit.a include $(PREBUILT_STATIC_LIBRARY) include $(CLEAR_VARS) -LOCAL_MODULE := multicraft +LOCAL_MODULE := MultiCraft ifdef GPROF GPROF_DEF=-DGPROF endif -LOCAL_CFLAGS := -D_IRR_ANDROID_PLATFORM_ \ +LOCAL_CFLAGS := \ -DJSONCPP_NO_LOCALE_SUPPORT \ -DHAVE_TOUCHSCREENGUI \ -DUSE_CURL=1 \ @@ -55,33 +55,27 @@ LOCAL_CFLAGS := -D_IRR_ANDROID_PLATFORM_ \ $(GPROF_DEF) \ -pipe -ifndef NDEBUG -LOCAL_CFLAGS += -g -D_DEBUG -O0 -fno-omit-frame-pointer -else - ifeq ($(TARGET_ABI),armeabi-v7a) -LOCAL_CFLAGS += \ --mfpu=vfpv3-d16 -march=armv7-a -Ofast \ --fdata-sections -ffunction-sections -fvisibility=hidden -flto -LOCAL_CXXFLAGS += $(LOCAL_CFLAGS) -LOCAL_LDFLAGS = -Wl,--no-warn-mismatch,--gc-sections,--icf=safe -endif - -endif - -ifdef GPROF -PROFILER_LIBS := android-ndk-profiler -LOCAL_CFLAGS += -pg +LOCAL_CFLAGS += -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb endif ifeq ($(TARGET_ABI),x86) -LOCAL_CFLAGS += \ --fno-stack-protector -Ofast \ --fdata-sections -ffunction-sections -fvisibility=hidden -flto -LOCAL_CXXFLAGS += $(LOCAL_CFLAGS) -LOCAL_LDFLAGS = -Wl,--no-warn-mismatch,--gc-sections,--icf=safe +LOCAL_CFLAGS += -march=i686 -mtune=intel -mssse3 -mfpmath=sse -m32 -funroll-loops endif +ifndef NDEBUG +LOCAL_CFLAGS := -g -D_DEBUG -O0 -fno-omit-frame-pointer +endif + +ifdef GPROF + PROFILER_LIBS := android-ndk-profiler + LOCAL_CFLAGS += -pg +endif + +LOCAL_CFLAGS += -Ofast -fdata-sections -ffunction-sections -fvisibility=hidden -flto +LOCAL_CXXFLAGS := $(LOCAL_CFLAGS) +LOCAL_LDFLAGS := -Wl,--no-warn-mismatch,--gc-sections,--icf=safe + LOCAL_C_INCLUDES := \ jni/src \ jni/src/script \ @@ -318,13 +312,13 @@ LOCAL_SRC_FILES += \ LOCAL_SRC_FILES += jni/lib/jsoncpp/jsoncpp.cpp # libiconv -LOCAL_CFLAGS += -Wno-multichar -D_ANDROID -DLIBDIR -DBUILDING_LIBICONV +LOCAL_CFLAGS += -D_ANDROID -DLIBDIR -DBUILDING_LIBICONV LOCAL_C_INCLUDES += \ deps/libiconv/include \ deps/libiconv/lib \ deps/libiconv/libcharset/include - + LOCAL_SRC_FILES += \ deps/libiconv/lib/iconv.c \ deps/libiconv/libcharset/lib/localcharset.c diff --git a/build/android/jni/Application.mk b/build/android/jni/Application.mk index 07c0c6008..d184f0774 100644 --- a/build/android/jni/Application.mk +++ b/build/android/jni/Application.mk @@ -3,6 +3,6 @@ APP_ABI := ${TARGET_ABI} APP_STL := gnustl_static NDK_TOOLCHAIN_VERSION := 4.9 APP_DEPRECATED_HEADERS := true -APP_MODULES := multicraft +APP_MODULES := MultiCraft APP_CPPFLAGS += -fexceptions -frtti diff --git a/build/android/jni/Deps.mk b/build/android/jni/Deps.mk index 21c9d46f2..3056fbe5e 100644 --- a/build/android/jni/Deps.mk +++ b/build/android/jni/Deps.mk @@ -5,5 +5,5 @@ NDK_TOOLCHAIN_VERSION := 4.9 APP_DEPRECATED_HEADERS := true APP_CLAFGS += ${TARGET_CFLAGS_ADDON} -APP_CPPFLAGS += ${TARGET_CXXFLAGS_ADDON} -fexceptions +APP_CPPFLAGS += ${TARGET_CXXFLAGS_ADDON} -fexceptions -frtti APP_LDFLAGS += ${TARGET_LDFLAGS_ADDON} diff --git a/build/android/jni/Irrlicht.mk b/build/android/jni/Irrlicht.mk index b40db5620..5690efcdb 100644 --- a/build/android/jni/Irrlicht.mk +++ b/build/android/jni/Irrlicht.mk @@ -5,4 +5,4 @@ NDK_TOOLCHAIN_VERSION := 4.9 APP_DEPRECATED_HEADERS := true APP_MODULES := Irrlicht -APP_CPPFLAGS += -fexceptions +APP_CPPFLAGS += -fexceptions -frtti diff --git a/build/android/patches/irrlicht-optimization.patch b/build/android/patches/irrlicht-optimization.patch index 27734f97b..e6401806f 100644 --- a/build/android/patches/irrlicht-optimization.patch +++ b/build/android/patches/irrlicht-optimization.patch @@ -1,21 +1,19 @@ --- irrlicht/source/Irrlicht/Android/jni/Android.mk.orig 2016-02-15 05:33:03.000000000 +0200 +++ irrlicht/source/Irrlicht/Android/jni/Android.mk 2016-02-15 05:34:34.913711815 +0200 -@@ -11,7 +11,17 @@ +@@ -11,7 +11,15 @@ ifndef NDEBUG LOCAL_CFLAGS += -g -D_DEBUG else -LOCAL_CFLAGS += -fexpensive-optimizations -O3 -+ifeq ($(TARGET_ARCH_ABI),armeabi-v7a) -+LOCAL_CFLAGS += -mfpu=vfpv3-d16 -march=armv7-a -Ofast -fdata-sections -ffunction-sections -fvisibility=hidden -flto -+LOCAL_CXXFLAGS += $(LOCAL_CFLAGS) -+LOCAL_LDFLAGS += -Wl,--no-warn-mismatch,--gc-sections,--icf=safe ++ifeq ($(TARGET_ABI),armeabi-v7a) ++LOCAL_CFLAGS += -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb +endif -+ifeq ($(TARGET_ARCH_ABI),x86) -+LOCAL_CFLAGS += -mhard-float -Ofast -fdata-sections -ffunction-sections -fmodulo-sched -fmodulo-sched-allow-regmoves -fvisibility=hidden -fno-stack-protector -+LOCAL_CXXFLAGS += -Ofast -fdata-sections -ffunction-sections -fmodulo-sched -fmodulo-sched-allow-regmoves -fvisibility=hidden -+LOCAL_LDFLAGS = -Wl,--no-warn-mismatch,--gc-sections,--icf=safe -+LOCAL_DISABLE_FATAL_LINKER_WARNINGS := true ++ifeq ($(TARGET_ABI),x86) ++LOCAL_CFLAGS += -march=i686 -mtune=intel -mssse3 -mfpmath=sse -m32 -funroll-loops -fno-stack-protector +endif ++LOCAL_CFLAGS += -Ofast -fdata-sections -ffunction-sections -fvisibility=hidden -flto ++LOCAL_CXXFLAGS := $(LOCAL_CFLAGS) ++LOCAL_LDFLAGS := -Wl,--no-warn-mismatch,--gc-sections,--icf=safe endif - + LOCAL_C_INCLUDES := ../../../include diff --git a/build/android/src/main/AndroidManifest.xml b/build/android/src/main/AndroidManifest.xml index 11d56bc32..e77a820f3 100644 --- a/build/android/src/main/AndroidManifest.xml +++ b/build/android/src/main/AndroidManifest.xml @@ -34,7 +34,7 @@ android:theme="@style/AppTheme"> + android:value="MultiCraft" /> diff --git a/build/android/src/main/java/mobi/MultiCraft/GameActivity.java b/build/android/src/main/java/mobi/MultiCraft/GameActivity.java index 49ab2d595..9c4ddeba4 100644 --- a/build/android/src/main/java/mobi/MultiCraft/GameActivity.java +++ b/build/android/src/main/java/mobi/MultiCraft/GameActivity.java @@ -9,7 +9,7 @@ import android.view.WindowManager; public class GameActivity extends NativeActivity { static { - System.loadLibrary("multicraft"); + System.loadLibrary("MultiCraft"); } private int messageReturnCode; @@ -124,4 +124,4 @@ public class GameActivity extends NativeActivity { return width; } -} \ No newline at end of file +} diff --git a/src/client/clientlauncher.cpp b/src/client/clientlauncher.cpp index 721b6058c..3fb571323 100644 --- a/src/client/clientlauncher.cpp +++ b/src/client/clientlauncher.cpp @@ -550,6 +550,12 @@ void ClientLauncher::main_menu(MainMenuData *menudata) bool ClientLauncher::create_engine_device() { + #ifdef __ANDROID__ + // set correct resolution + g_settings->setU16("screen_w", porting::getDisplaySize().X); + g_settings->setU16("screen_h", porting::getDisplaySize().Y); + #endif + // Resolution selection bool fullscreen = g_settings->getBool("fullscreen"); u16 screen_w = g_settings->getU16("screen_w"); diff --git a/src/porting_android.cpp b/src/porting_android.cpp index e22c6c5ed..5fae08546 100644 --- a/src/porting_android.cpp +++ b/src/porting_android.cpp @@ -47,7 +47,6 @@ void android_main(android_app *app) Thread::setName("Main"); try { - app_dummy(); char *argv[] = {strdup(PROJECT_NAME), NULL}; main(ARRLEN(argv) - 1, argv); free(argv[0]); @@ -136,7 +135,7 @@ void initAndroid() /* in the start-up code */ __android_log_print(ANDROID_LOG_ERROR, PROJECT_NAME_C, "Initializing GPROF profiler"); - monstartup("libmulticraft.so"); + monstartup("libMultiCraft.so"); #endif } @@ -206,7 +205,7 @@ void initializePathsAndroid() cls_File, mt_getAbsPath, "getCacheDir"); path_storage = getAndroidPath(cls_Env, NULL, cls_File, mt_getAbsPath, "getExternalStorageDirectory"); - path_user = path_storage + DIR_DELIM + "Android/data/mobi.MultiCraft/Files"; + path_user = path_storage + DIR_DELIM + "Android/data/mobi.MultiCraft/files"; path_share = path_user; path_locale = path_user + DIR_DELIM + "locale"; } diff --git a/src/util/srp.cpp b/src/util/srp.cpp index f14d22303..4db9a7465 100644 --- a/src/util/srp.cpp +++ b/src/util/srp.cpp @@ -611,7 +611,7 @@ SRP_Result srp_create_salted_verification_key( SRP_HashAlgorithm alg, if (fill_buff() != SRP_OK) goto error_and_exit; *bytes_s = (unsigned char *)srp_alloc(size_to_fill); if (!*bytes_s) goto error_and_exit; - memcpy(*bytes_s, &g_rand_buff + g_rand_idx, size_to_fill); + memcpy(*bytes_s, &g_rand_buff[g_rand_idx], size_to_fill); g_rand_idx += size_to_fill; }