diff --git a/.gitignore b/.gitignore index 7bf8de95..e8a31cc7 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,6 @@ xcuserdata *.pyc .scons* .DS_Store +Build/Targets/arm64-android-linux/Debug +Build/Targets/arm64-android-linux/Release + diff --git a/Build/Targets/arm-android-linux/Config.scons b/Build/Targets/arm-android-linux/Config.scons index bdbf08d3..ab7c9d9f 100644 --- a/Build/Targets/arm-android-linux/Config.scons +++ b/Build/Targets/arm-android-linux/Config.scons @@ -19,8 +19,8 @@ if env.has_key('android_host_system') and env['android_host_system']: ANDROID_HOST_SYSTEM = env['android_host_system'] else: PLATFORM_TO_TARGET_MAP = { - 'linux-i386' : 'linux-x86', - 'linux2' : 'linux-x86', + 'linux-i386' : 'linux-x86_64', + 'linux2' : 'linux-x86_64', 'win32' : 'windows', 'cygwin' : 'windows', 'darwin' : 'darwin-x86' @@ -32,8 +32,8 @@ else: # set defaults ANDROID_ARCH = 'arm' -ANDROID_PLATFORM = 'android-9' -ANDROID_TOOLCHAIN = 'arm-linux-androideabi-4.4.3' +ANDROID_PLATFORM = 'android-14' +ANDROID_TOOLCHAIN = 'arm-linux-androideabi-4.9' ANDROID_CROSS_PREFIX = 'arm-linux-androideabi' if not os.path.exists(os.path.join(ANDROID_NDK_ROOT, 'toolchains', ANDROID_TOOLCHAIN)): diff --git a/Build/Targets/arm64-android-linux/Config.scons b/Build/Targets/arm64-android-linux/Config.scons new file mode 100644 index 00000000..fdf91cc9 --- /dev/null +++ b/Build/Targets/arm64-android-linux/Config.scons @@ -0,0 +1,107 @@ +################################################################# +# Important: this build file has been tested with Android NDK r6, r7 and r8 +# It may or may not work with other releases of the NDK. Please notify +# us if you find a newer NDK for which this does not work. +################################################################# + +import os +import re +import sys +import platform + +# we need to know when the NDK is +ANDROID_NDK_ROOT=os.getenv('ANDROID_NDK_ROOT') +if not ANDROID_NDK_ROOT: + raise Exception('ANDROID_NDK_ROOT environment variable not set') + +# detect the host system on which we're running +if env.has_key('android_host_system') and env['android_host_system']: + ANDROID_HOST_SYSTEM = env['android_host_system'] +else: + PLATFORM_TO_TARGET_MAP = { + 'linux-i386' : 'linux-x86_64', + 'linux2' : 'linux-x86_64', + 'win32' : 'windows', + 'cygwin' : 'windows', + 'darwin' : 'darwin-x86' + } + if sys.platform in PLATFORM_TO_TARGET_MAP: + ANDROID_HOST_SYSTEM = PLATFORM_TO_TARGET_MAP[sys.platform] + else: + raise Exception('Android Host Platform cannot be determined') + +# set defaults +ANDROID_ARCH = 'arm64' +ANDROID_PLATFORM = 'android-21' +ANDROID_TOOLCHAIN = 'aarch64-linux-android-4.9' +ANDROID_CROSS_PREFIX = 'aarch64-linux-android' + +if not os.path.exists(os.path.join(ANDROID_NDK_ROOT, 'toolchains', ANDROID_TOOLCHAIN)): + toolchain_dirs = os.listdir(ANDROID_NDK_ROOT+'/toolchains') + for toolchain_dir in toolchain_dirs: + if os.path.exists(os.path.join(ANDROID_NDK_ROOT, 'toolchains', toolchain_dir, 'prebuilt', ANDROID_HOST_SYSTEM)): + ANDROID_TOOLCHAIN=toolchain_dir + suffix_pos = toolchain_dir.rfind('-') + if (suffix_pos >= 0): + ANDROID_CROSS_PREFIX = ANDROID_TOOLCHAIN[:suffix_pos] + print "Auto-selecting toolchain:", ANDROID_TOOLCHAIN + break + +# override defaults from command line args +if ARGUMENTS.get('android_toolchain'): + ANDROID_TOOLCHAIN=ARGUMENTS.get('android_toolchain') + +if ARGUMENTS.get('android_cross_prefix'): + ANDROID_CROSS_PREFIX=ARGUMENTS.get('android_cross_prefix') + +if ARGUMENTS.get('android_platform'): + ANDROID_PLATFORM=ARGUMENTS.get('android_platform') + +if ARGUMENTS.get('android_arch'): + ANDROID_ARCH=ARGUMENTS.get('android_arch') + +print 'Building for Android: ' +print 'ANDROID_HOST_SYSTEM =', ANDROID_HOST_SYSTEM +print 'ANDROID_TOOLCHAIN =', ANDROID_TOOLCHAIN +print 'ANDROID_PLATFORM =', ANDROID_PLATFORM +print 'ANDROID_ARCH =', ANDROID_ARCH + +ANDROID_TOOLCHAIN_BIN = ANDROID_NDK_ROOT+'/toolchains/'+ANDROID_TOOLCHAIN+'/prebuilt/'+ANDROID_HOST_SYSTEM+'/bin' +ANDROID_SYSROOT = ANDROID_NDK_ROOT+'/platforms/'+ANDROID_PLATFORM+'/arch-'+ANDROID_ARCH + +### add the tools to the path +env.PrependENVPath('PATH', ANDROID_TOOLCHAIN_BIN) + +### special C Runtime startup for executables +env['NPT_EXTRA_EXECUTABLE_OBJECTS'] = [] +env['NPT_EXTRA_LIBS'] = ['gcc'] + +### Load the tools +LoadTool('gcc-generic', env, gcc_cross_prefix=ANDROID_CROSS_PREFIX, gcc_strict=False) +env.AppendUnique(CCFLAGS = ['-I'+ANDROID_NDK_ROOT+'/sources/cxx-stl/system/include' , + '--sysroot', ANDROID_SYSROOT, + # '-msoft-float', + '-fpic', + # '-mthumb-interwork', + '-ffunction-sections', + '-funwind-tables', + '-fstack-protector', + '-fno-short-enums']) +env.AppendUnique(CXXFLAGS = ['-fno-exceptions', '-fno-rtti']) +env.AppendUnique(CPPDEFINES = ['ANDROID', 'NPT_CONFIG_HAVE_SYSTEM_LOG_CONFIG']) +env.AppendUnique(LINKFLAGS = ['--sysroot', ANDROID_SYSROOT, + '-Wl,--no-undefined', + '-Wl,-z,noexecstack', + '-L'+ANDROID_SYSROOT+'/usr/lib', + '-lc', + '-lstdc++', + '-lm', + '-llog', + '-ldl']) + +### Specific System choices +env['NPT_SYSTEM_SOURCES']={'System/StdC':'NptStdc[!D]*.cpp', + 'System/Bsd':'*.cpp', + 'System/Posix':'*.cpp', + 'System/Null':['NptNullSerialPort.cpp', 'NptNullAutoreleasePool.cpp'], + 'System/Android':'*.cpp'} diff --git a/README.md b/README.md index 3c467342..b62fd62a 100644 --- a/README.md +++ b/README.md @@ -109,8 +109,12 @@ Under Source/Extras/Managed ## Android Java/JNI To build the JNI shared library, you will need to install the Android NDK and set up the proper environment variables such as ANDROID_NDK_ROOT. +(android-ndk-r15c recommended;If a path error occurs, use the absolute path.) ``` +> scons -c target=arm-android-linux build_config=Release > scons target=arm-android-linux build_config=Release +> scons -c target=arm64-android-linux build_config=Release +> scons target=arm64-android-linux build_config=Release > cd Source/Platform/Android/module/platinum > ndk-build NDK_DEBUG=0 ``` diff --git a/Source/Platform/Android/module/platinum/AndroidManifest.xml b/Source/Platform/Android/module/platinum/AndroidManifest.xml index a30a0a96..ca8411a3 100644 --- a/Source/Platform/Android/module/platinum/AndroidManifest.xml +++ b/Source/Platform/Android/module/platinum/AndroidManifest.xml @@ -4,11 +4,11 @@ android:versionCode="1" android:versionName="1.0" > - + - \ No newline at end of file + diff --git a/Source/Platform/Android/module/platinum/jni/Android.mk b/Source/Platform/Android/module/platinum/jni/Android.mk index e39fe627..94928b0b 100644 --- a/Source/Platform/Android/module/platinum/jni/Android.mk +++ b/Source/Platform/Android/module/platinum/jni/Android.mk @@ -2,12 +2,23 @@ LOCAL_PATH := $(call my-dir) PLT_ROOT := $(LOCAL_PATH)/../../../../../.. PLT_SRC_ROOT := $(PLT_ROOT)/Source - +$(warning "TARGET_ARCH_ABI:$(TARGET_ARCH_ABI)") ifeq ($(NDK_DEBUG),1) +ifeq ($(TARGET_ARCH_ABI),arm64-v8a) +$(warning "build arm64") +PLT_PREBUILT_PATH := ../../../../../../Build/Targets/arm64-android-linux/Debug +else PLT_PREBUILT_PATH := ../../../../../../Build/Targets/arm-android-linux/Debug +endif +else +ifeq ($(TARGET_ARCH_ABI),arm64-v8a) +$(warning "build arm64") +PLT_PREBUILT_PATH := ../../../../../../Build/Targets/arm64-android-linux/Release else PLT_PREBUILT_PATH := ../../../../../../Build/Targets/arm-android-linux/Release endif +endif + include $(CLEAR_VARS) LOCAL_MODULE := Platinum @@ -18,13 +29,13 @@ LOCAL_EXPORT_C_INCLUDES += $(PLT_SRC_ROOT)/Devices/MediaConnect LOCAL_EXPORT_C_INCLUDES += $(PLT_SRC_ROOT)/Devices/MediaServer LOCAL_EXPORT_C_INCLUDES += $(PLT_SRC_ROOT)/Devices/MediaRenderer LOCAL_EXPORT_C_INCLUDES += $(PLT_SRC_ROOT)/Extras -LOCAL_C_INCLUDES += $(PLT_ROOT)/../Neptune/Source/Core +LOCAL_C_INCLUDES += $(PLT_ROOT)/ThirdParty/Neptune/Source/Core include $(PREBUILT_STATIC_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := Neptune LOCAL_SRC_FILES := $(PLT_PREBUILT_PATH)/libNeptune.a -LOCAL_EXPORT_C_INCLUDES += $(PLT_ROOT)/../Neptune/Source/Core +LOCAL_EXPORT_C_INCLUDES += $(PLT_ROOT)/ThirdParty/Neptune/Source/Core include $(PREBUILT_STATIC_LIBRARY) ifneq ($(NPT_CONFIG_NO_SSL),1) diff --git a/Source/Platform/Android/module/platinum/jni/Application.mk b/Source/Platform/Android/module/platinum/jni/Application.mk index d0a1e397..fbc3bf68 100644 --- a/Source/Platform/Android/module/platinum/jni/Application.mk +++ b/Source/Platform/Android/module/platinum/jni/Application.mk @@ -1 +1 @@ -APP_ABI := armeabi armeabi-v7a \ No newline at end of file +APP_ABI := armeabi armeabi-v7a arm64-v8a diff --git a/Source/Platform/Android/module/platinum/project.properties b/Source/Platform/Android/module/platinum/project.properties index 03d06171..22e1c480 100644 --- a/Source/Platform/Android/module/platinum/project.properties +++ b/Source/Platform/Android/module/platinum/project.properties @@ -11,5 +11,5 @@ #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt # Project target. -target=android-10 +target=android-14 android.library=true