diff options
author | Stewart Miles <smiles@google.com> | 2017-07-13 06:27:39 -0700 |
---|---|---|
committer | Stewart Miles <smiles@google.com> | 2017-07-20 11:01:00 -0700 |
commit | a8923222033763f1a74f836c656af19d9f620378 (patch) | |
tree | 547afad28430abdeed4af6a1d6c0a2d6a722c6e8 /samples | |
parent | 2e2063cbeb6ea95c804796c443153f71797c3629 (diff) | |
download | flatbuffers-a8923222033763f1a74f836c656af19d9f620378.tar.gz flatbuffers-a8923222033763f1a74f836c656af19d9f620378.tar.bz2 flatbuffers-a8923222033763f1a74f836c656af19d9f620378.zip |
C++98 (stlport) support for core FlatBuffers and FlexBuffers.
* Added internal - limited - implementation of flatbuffers::unique_ptr
for STLs that don't ship with std::unique_ptr. In C++11 and beyond
this is just an alias for std::unique_ptr.
* Aliased used type traits structs is_scalar is_floating_point is_unsigned
into flatbuffers namespace so they can be replaced in C++98 implementations.
Right now these point at stlport's TR1 implementations.
* Wrapped vector::data() in vector_data().
* Wrapped vector::emplace_back() in vector_emplace_back().
* Wrapper string::back() in string_back().
* Added variants of FlatBufferBuilder::CreateVector() and
FlatBufferBuilder::CreateVectorOfStructs() that allow the use of plain
function pointers.
Generated code has also been modified to use plain functions to build objects
rather than std::function() so all generated code will work in C++98
applications.
* Added flexbuffers::Builder::Vector(), flexbuffers::Builder::TypedVector()
and flexbuffers::Builder::Map() methods that allow the use of plain function
pointers.
* Changed Parser to internally use plain function pointers when parsing table
and vector delimiters.
* Added specializations of NumToString() for 64-bit types that aren't supported
by stringstream in stlport.
* Overloaded numeric_limits for 64-bit types not supported by stlport.
* Replaced build_apk.sh (which was broken by deprecation of the
"android" tool in the Android SDK) with build.gradle and the
appropriate gradle wrapper to build an APK.
* Switched Android build to build against all STL variants.
* Updated travis configuration to build Android test and sample.
Tested:
* Verified all tests continue to work on Linux, OSX and Android.
* Verified Travis build is green.
Change-Id: I9e634363793f85b9f141d21454b10686020a2065
Diffstat (limited to 'samples')
-rwxr-xr-x | samples/android/AndroidManifest.xml | 11 | ||||
-rw-r--r-- | samples/android/build.gradle | 108 | ||||
-rwxr-xr-x | samples/android/build_apk.sh | 511 | ||||
-rw-r--r-- | samples/android/gradle/wrapper/gradle-wrapper.jar | bin | 0 -> 54706 bytes | |||
-rw-r--r-- | samples/android/gradle/wrapper/gradle-wrapper.properties | 6 | ||||
-rwxr-xr-x | samples/android/gradlew | 172 | ||||
-rw-r--r-- | samples/android/gradlew.bat | 84 | ||||
-rwxr-xr-x | samples/android/jni/Android.mk | 2 | ||||
-rwxr-xr-x | samples/android/jni/Application.mk | 6 | ||||
-rwxr-xr-x | samples/android_sample.sh | 7 | ||||
-rw-r--r-- | samples/monster_generated.h | 18 |
11 files changed, 391 insertions, 534 deletions
diff --git a/samples/android/AndroidManifest.xml b/samples/android/AndroidManifest.xml index 0fa3dcfc..352e0fad 100755 --- a/samples/android/AndroidManifest.xml +++ b/samples/android/AndroidManifest.xml @@ -17,17 +17,14 @@ --> <!-- BEGIN_INCLUDE(manifest) --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.samples.FlatBufferSample" - android:versionCode="1" - android:versionName="1.0"> + package="com.samples.FlatBufferSample"> <uses-feature android:glEsVersion="0x00020000"></uses-feature> - <!-- This is the platform API where NativeActivity was introduced. --> - <uses-sdk android:minSdkVersion="9" /> <!-- This .apk has no Java code itself, so set hasCode to false. --> - <application android:label="@string/app_name" android:hasCode="false"> - + <application android:label="@string/app_name" + android:hasCode="false" + android:allowBackup="false"> <!-- Our activity is the built-in NativeActivity framework class. This will take care of integrating with our NDK code. --> <activity android:name="android.app.NativeActivity" diff --git a/samples/android/build.gradle b/samples/android/build.gradle new file mode 100644 index 00000000..e6af6d6f --- /dev/null +++ b/samples/android/build.gradle @@ -0,0 +1,108 @@ +// Copyright (c) 2017 Google, Inc. +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +buildscript { + repositories { + jcenter() + } + dependencies { + classpath 'com.android.tools.build:gradle:2.3.0' + } +} + +allprojects { + repositories { + jcenter() + } +} + +apply plugin: 'com.android.application' + +android { + compileSdkVersion 25 + buildToolsVersion '25.0.2' + + sourceSets { + main { + manifest.srcFile 'AndroidManifest.xml' + res.srcDirs = ['res'] + } + } + + externalNativeBuild { + ndkBuild { + path "jni/Android.mk" + } + } + + defaultConfig { + applicationId 'com.samples.FlatBufferSample' + // This is the platform API where NativeActivity was introduced. + minSdkVersion 9 + targetSdkVersion 25 + versionCode 1 + versionName "1.0" + + buildTypes { + release { + minifyEnabled false + } + } + + externalNativeBuild { + ndkBuild { + targets "FlatBufferSample" + arguments "-j" + Runtime.getRuntime().availableProcessors() + abiFilters "armeabi", "armeabi-v7a", "arm64-v8a", "x86", "x86_64" + } + } + } + + lintOptions { + abortOnError false + } + + // Build with each STL variant. + productFlavors { + stlport { + applicationIdSuffix ".stlport" + versionNameSuffix "-stlport" + externalNativeBuild { + ndkBuild { + arguments "APP_STL=stlport_static" + } + } + } + gnustl { + applicationIdSuffix ".gnustl" + versionNameSuffix "-gnustl" + externalNativeBuild { + ndkBuild { + arguments "APP_STL=gnustl_static" + } + } + } + libcpp { + applicationIdSuffix ".libcpp" + versionNameSuffix "-libcpp" + externalNativeBuild { + ndkBuild { + arguments "APP_STL=c++_static" + } + } + } + } +} diff --git a/samples/android/build_apk.sh b/samples/android/build_apk.sh deleted file mode 100755 index 1b9f4a45..00000000 --- a/samples/android/build_apk.sh +++ /dev/null @@ -1,511 +0,0 @@ -#!/bin/bash -eu -# -# Copyright (c) 2013 Google, Inc. -# -# This software is provided 'as-is', without any express or implied -# warranty. In no event will the authors be held liable for any damages -# arising from the use of this software. -# Permission is granted to anyone to use this software for any purpose, -# including commercial applications, and to alter it and redistribute it -# freely, subject to the following restrictions: -# 1. The origin of this software must not be misrepresented; you must not -# claim that you wrote the original software. If you use this software -# in a product, an acknowledgment in the product documentation would be -# appreciated but is not required. -# 2. Altered source versions must be plainly marked as such, and must not be -# misrepresented as being the original software. -# 3. This notice may not be removed or altered from any source distribution. -# -# Build, deploy, debug / execute a native Android package based upon -# NativeActivity. - -declare -r script_directory=$(dirname $0) -declare -r android_root=${script_directory}/../../../../../../ -declare -r script_name=$(basename $0) -declare -r android_manifest=AndroidManifest.xml -declare -r os_name=$(uname -s) - -# Minimum Android target version supported by this project. -: ${BUILDAPK_ANDROID_TARGET_MINVERSION:=10} -# Directory containing the Android SDK -# (http://developer.android.com/sdk/index.html). -: ${ANDROID_SDK_HOME:=} -# Directory containing the Android NDK -# (http://developer.android.com/tools/sdk/ndk/index.html). -: ${NDK_HOME:=} - -# Display script help and exit. -usage() { - echo " -Build the Android package in the current directory and deploy it to a -connected device. - -Usage: ${script_name} \\ - [ADB_DEVICE=serial_number] [BUILD=0] [DEPLOY=0] [RUN_DEBUGGER=1] \ - [LAUNCH=0] [SWIG_BIN=swig_binary_directory] [SWIG_LIB=swig_include_directory] [ndk-build arguments ...] - -ADB_DEVICE=serial_number: - serial_number specifies the device to deploy the built apk to if multiple - Android devices are connected to the host. -BUILD=0: - Disables the build of the package. -DEPLOY=0: - Disables the deployment of the built apk to the Android device. -RUN_DEBUGGER=1: - Launches the application in gdb after it has been deployed. To debug in - gdb, NDK_DEBUG=1 must also be specified on the command line to build a - debug apk. -LAUNCH=0: - Disable the launch of the apk on the Android device. -SWIG_BIN=swig_binary_directory: - The directory where the SWIG binary lives. No need to set this if SWIG is - installed and point to from your PATH variable. -SWIG_LIB=swig_include_directory: - The directory where SWIG shared include files are, usually obtainable from - commandline with \"swig -swiglib\". No need to set this if SWIG is installed - and point to from your PATH variable. -ndk-build arguments...: - Additional arguments for ndk-build. See ndk-build -h for more information. -" >&2 - exit 1 -} - -# Get the number of CPU cores present on the host. -get_number_of_cores() { - case ${os_name} in - Darwin) - sysctl hw.ncpu | awk '{ print $2 }' - ;; - CYGWIN*|Linux) - awk '/^processor/ { n=$3 } END { print n + 1 }' /proc/cpuinfo - ;; - *) - echo 1 - ;; - esac -} - -# Get the package name from an AndroidManifest.xml file. -get_package_name_from_manifest() { - xmllint --xpath 'string(/manifest/@package)' "${1}" -} - -# Get the library name from an AndroidManifest.xml file. -get_library_name_from_manifest() { - echo "\ -setns android=http://schemas.android.com/apk/res/android -xpath string(/manifest/application/activity\ -[@android:name=\"android.app.NativeActivity\"]/meta-data\ -[@android:name=\"android.app.lib_name\"]/@android:value)" | - xmllint --shell "${1}" | awk '/Object is a string/ { print $NF }' -} - -# Get the number of Android devices connected to the system. -get_number_of_devices_connected() { - adb devices -l | \ - awk '/^..*$/ { if (p) { print $0 } } - /List of devices attached/ { p = 1 }' | \ - wc -l - return ${PIPESTATUS[0]} -} - -# Kill a process and its' children. This is provided for cygwin which -# doesn't ship with pkill. -kill_process_group() { - local parent_pid="${1}" - local child_pid= - for child_pid in $(ps -f | \ - awk '{ if ($3 == '"${parent_pid}"') { print $2 } }'); do - kill_process_group "${child_pid}" - done - kill "${parent_pid}" 2>/dev/null -} - -# Find and run "adb". -adb() { - local adb_path= - for path in "$(which adb 2>/dev/null)" \ - "${ANDROID_SDK_HOME}/sdk/platform-tools/adb" \ - "${android_root}/prebuilts/sdk/platform-tools/adb"; do - if [[ -e "${path}" ]]; then - adb_path="${path}" - break - fi - done - if [[ "${adb_path}" == "" ]]; then - echo -e "Unable to find adb." \ - "\nAdd the Android ADT sdk/platform-tools directory to the" \ - "PATH." >&2 - exit 1 - fi - "${adb_path}" "$@" -} - -# Find and run "android". -android() { - local android_executable=android - if echo "${os_name}" | grep -q CYGWIN; then - android_executable=android.bat - fi - local android_path= - for path in "$(which ${android_executable})" \ - "${ANDROID_SDK_HOME}/sdk/tools/${android_executable}" \ - "${android_root}/prebuilts/sdk/tools/${android_executable}"; do - if [[ -e "${path}" ]]; then - android_path="${path}" - break - fi - done - if [[ "${android_path}" == "" ]]; then - echo -e "Unable to find android tool." \ - "\nAdd the Android ADT sdk/tools directory to the PATH." >&2 - exit 1 - fi - # Make sure ant is installed. - if [[ "$(which ant)" == "" ]]; then - echo -e "Unable to find ant." \ - "\nPlease install ant and add to the PATH." >&2 - exit 1 - fi - - "${android_path}" "$@" -} - -# Find and run "ndk-build" -ndkbuild() { - local ndkbuild_path= - for path in "$(which ndk-build 2>/dev/null)" \ - "${NDK_HOME}/ndk-build" \ - "${android_root}/prebuilts/ndk/current/ndk-build"; do - if [[ -e "${path}" ]]; then - ndkbuild_path="${path}" - break - fi - done - if [[ "${ndkbuild_path}" == "" ]]; then - echo -e "Unable to find ndk-build." \ - "\nAdd the Android NDK directory to the PATH." >&2 - exit 1 - fi - "${ndkbuild_path}" "$@" -} - -# Get file modification time of $1 in seconds since the epoch. -stat_mtime() { - local filename="${1}" - case ${os_name} in - Darwin) stat -f%m "${filename}" 2>/dev/null || echo 0 ;; - *) stat -c%Y "${filename}" 2>/dev/null || echo 0 ;; - esac -} - -# Build the native (C/C++) build targets in the current directory. -build_native_targets() { - # Save the list of output modules in the install directory so that it's - # possible to restore their timestamps after the build is complete. This - # works around a bug in ndk/build/core/setup-app.mk which results in the - # unconditional execution of the clean-installed-binaries rule. - restore_libraries="$(find libs -type f 2>/dev/null | \ - sed -E 's@^libs/(.*)@\1@')" - - # Build native code. - ndkbuild -j$(get_number_of_cores) "$@" - - # Restore installed libraries. - # Obviously this is a nasty hack (along with ${restore_libraries} above) as - # it assumes it knows where the NDK will be placing output files. - ( - IFS=$'\n' - for libpath in ${restore_libraries}; do - source_library="obj/local/${libpath}" - target_library="libs/${libpath}" - if [[ -e "${source_library}" ]]; then - cp -a "${source_library}" "${target_library}" - fi - done - ) -} - -# Select the oldest installed android build target that is at least as new as -# BUILDAPK_ANDROID_TARGET_MINVERSION. If a suitable build target isn't found, -# this function prints an error message and exits with an error. -select_android_build_target() { - local -r android_targets_installed=$( \ - android list targets | \ - awk -F'"' '/^id:.*android/ { print $2 }') - local android_build_target= - for android_target in $(echo "${android_targets_installed}" | \ - awk -F- '{ print $2 }' | sort -n); do - local isNumber='^[0-9]+$' - # skip preview API releases e.g. 'android-L' - if [[ $android_target =~ $isNumber ]]; then - if [[ $((android_target)) -ge \ - $((BUILDAPK_ANDROID_TARGET_MINVERSION)) ]]; then - android_build_target="android-${android_target}" - break - fi - # else - # The API version is a letter, so skip it. - fi - done - if [[ "${android_build_target}" == "" ]]; then - echo -e \ - "Found installed Android targets:" \ - "$(echo ${android_targets_installed} | sed 's/ /\n /g;s/^/\n /;')" \ - "\nAndroid SDK platform" \ - "android-$((BUILDAPK_ANDROID_TARGET_MINVERSION))" \ - "must be installed to build this project." \ - "\nUse the \"android\" application to install API" \ - "$((BUILDAPK_ANDROID_TARGET_MINVERSION)) or newer." >&2 - exit 1 - fi - echo "${android_build_target}" -} - -# Sign unsigned apk $1 and write the result to $2 with key store file $3 and -# password $4. -# If a key store file $3 and password $4 aren't specified, a temporary -# (60 day) key is generated and used to sign the package. -sign_apk() { - local unsigned_apk="${1}" - local signed_apk="${2}" - if [[ $(stat_mtime "${unsigned_apk}") -gt \ - $(stat_mtime "${signed_apk}") ]]; then - local -r key_alias=$(basename ${signed_apk} .apk) - local keystore="${3}" - local key_password="${4}" - [[ "${keystore}" == "" ]] && keystore="${unsigned_apk}.keystore" - [[ "${key_password}" == "" ]] && \ - key_password="${key_alias}123456" - if [[ ! -e ${keystore} ]]; then - keytool -genkey -v -dname "cn=, ou=${key_alias}, o=fpl" \ - -storepass ${key_password} \ - -keypass ${key_password} -keystore ${keystore} \ - -alias ${key_alias} -keyalg RSA -keysize 2048 -validity 60 - fi - cp "${unsigned_apk}" "${signed_apk}" - jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 \ - -keystore ${keystore} -storepass ${key_password} \ - -keypass ${key_password} "${signed_apk}" ${key_alias} - fi -} - -# Build the apk $1 for package filename $2 in the current directory using the -# ant build target $3. -build_apk() { - local -r output_apk="${1}" - local -r package_filename="${2}" - local -r ant_target="${3}" - # Get the list of installed android targets and select the oldest target - # that is at least as new as BUILDAPK_ANDROID_TARGET_MINVERSION. - local -r android_build_target=$(select_android_build_target) - [[ "${android_build_target}" == "" ]] && exit 1 - echo "Building ${output_apk} for target ${android_build_target}" >&2 - - # Create / update build.xml and local.properties files. - if [[ $(stat_mtime "${android_manifest}") -gt \ - $(stat_mtime build.xml) ]]; then - android update project --target "${android_build_target}" \ - -n ${package_filename} --path . - fi - - # Use ant to build the apk. - ant -quiet ${ant_target} - - # Sign release apks with a temporary key as these packages will not be - # redistributed. - local unsigned_apk="bin/${package_filename}-${ant_target}-unsigned.apk" - if [[ "${ant_target}" == "release" ]]; then - sign_apk "${unsigned_apk}" "${output_apk}" "" "" - fi -} - -# Uninstall package $1 and install apk $2 on device $3 where $3 is "-s device" -# or an empty string. If $3 is an empty string adb will fail when multiple -# devices are connected to the host system. -install_apk() { - local -r uninstall_package_name="${1}" - local -r install_apk="${2}" - local -r adb_device="${3}" - # Uninstall the package if it's already installed. - adb ${adb_device} uninstall "${uninstall_package_name}" 1>&2 > /dev/null || \ - true # no error check - - # Install the apk. - # NOTE: The following works around adb not returning an error code when - # it fails to install an apk. - echo "Install ${install_apk}" >&2 - local -r adb_install_result=$(adb ${adb_device} install "${install_apk}") - echo "${adb_install_result}" - if echo "${adb_install_result}" | grep -qF 'Failure ['; then - exit 1 - fi -} - -# Launch previously installed package $1 on device $2. -# If $2 is an empty string adb will fail when multiple devices are connected -# to the host system. -launch_package() { - ( - # Determine the SDK version of Android on the device. - local -r android_sdk_version=$( - adb ${adb_device} shell cat system/build.prop | \ - awk -F= '/ro.build.version.sdk/ { - v=$2; sub(/[ \r\n]/, "", v); print v - }') - - # Clear logs from previous runs. - # Note that logcat does not just 'tail' the logs, it dumps the entire log - # history. - adb ${adb_device} logcat -c - - local finished_msg='Displayed '"${package_name}" - local timeout_msg='Activity destroy timeout.*'"${package_name}" - # Maximum time to wait before stopping log monitoring. 0 = infinity. - local launch_timeout=0 - # If this is a Gingerbread device, kill log monitoring after 10 seconds. - if [[ $((android_sdk_version)) -le 10 ]]; then - launch_timeout=10 - fi - # Display logcat in the background. - # Stop displaying the log when the app launch / execution completes or the - # logcat - ( - adb ${adb_device} logcat | \ - awk " - { - print \$0 - } - - /ActivityManager.*: ${finished_msg}/ { - exit 0 - } - - /ActivityManager.*: ${timeout_msg}/ { - exit 0 - }" & - adb_logcat_pid=$!; - if [[ $((launch_timeout)) -gt 0 ]]; then - sleep $((launch_timeout)); - kill ${adb_logcat_pid}; - else - wait ${adb_logcat_pid}; - fi - ) & - logcat_pid=$! - # Kill adb logcat if this shell exits. - trap "kill_process_group ${logcat_pid}" SIGINT SIGTERM EXIT - - # If the SDK is newer than 10, "am" supports stopping an activity. - adb_stop_activity= - if [[ $((android_sdk_version)) -gt 10 ]]; then - adb_stop_activity=-S - fi - - # Launch the activity and wait for it to complete. - adb ${adb_device} shell am start ${adb_stop_activity} -n \ - ${package_name}/android.app.NativeActivity - - wait "${logcat_pid}" - ) -} - -# See usage(). -main() { - # Parse arguments for this script. - local adb_device= - local ant_target=release - local disable_deploy=0 - local disable_build=0 - local run_debugger=0 - local launch=1 - local build_package=1 - for opt; do - case ${opt} in - # NDK_DEBUG=0 tells ndk-build to build this as debuggable but to not - # modify the underlying code whereas NDK_DEBUG=1 also builds as debuggable - # but does modify the code - NDK_DEBUG=1) ant_target=debug ;; - NDK_DEBUG=0) ant_target=debug ;; - ADB_DEVICE*) adb_device="$(\ - echo "${opt}" | sed -E 's/^ADB_DEVICE=([^ ]+)$/-s \1/;t;s/.*//')" ;; - BUILD=0) disable_build=1 ;; - DEPLOY=0) disable_deploy=1 ;; - RUN_DEBUGGER=1) run_debugger=1 ;; - LAUNCH=0) launch=0 ;; - clean) build_package=0 disable_deploy=1 launch=0 ;; - -h|--help|help) usage ;; - esac - done - - # If a target device hasn't been specified and multiple devices are connected - # to the host machine, display an error. - local -r devices_connected=$(get_number_of_devices_connected) - if [[ "${adb_device}" == "" && $((devices_connected)) -gt 1 && \ - ($((disable_deploy)) -eq 0 || $((launch)) -ne 0 || \ - $((run_debugger)) -ne 0) ]]; then - if [[ $((disable_deploy)) -ne 0 ]]; then - echo "Deployment enabled, disable using DEPLOY=0" >&2 - fi - if [[ $((launch)) -ne 0 ]]; then - echo "Launch enabled." >&2 - fi - if [[ $((disable_deploy)) -eq 0 ]]; then - echo "Deployment enabled." >&2 - fi - if [[ $((run_debugger)) -ne 0 ]]; then - echo "Debugger launch enabled." >&2 - fi - echo " -Multiple Android devices are connected to this host. Either disable deployment -and execution of the built .apk using: - \"${script_name} DEPLOY=0 LAUNCH=0\" - -or specify a device to deploy to using: - \"${script_name} ADB_DEVICE=\${device_serial}\". - -The Android devices connected to this machine are: -$(adb devices -l) -" >&2 - exit 1 - fi - - if [[ $((disable_build)) -eq 0 ]]; then - # Build the native target. - build_native_targets "$@" - fi - - # Get the package name from the manifest. - local -r package_name=$(get_package_name_from_manifest "${android_manifest}") - if [[ "${package_name}" == "" ]]; then - echo -e "No package name specified in ${android_manifest},"\ - "skipping apk build, deploy" - "\nand launch steps." >&2 - exit 0 - fi - local -r package_basename=${package_name/*./} - local package_filename=$(get_library_name_from_manifest ${android_manifest}) - [[ "${package_filename}" == "" ]] && package_filename="${package_basename}" - - # Output apk name. - local -r output_apk="bin/${package_filename}-${ant_target}.apk" - - if [[ $((disable_build)) -eq 0 && $((build_package)) -eq 1 ]]; then - # Build the apk. - build_apk "${output_apk}" "${package_filename}" "${ant_target}" - fi - - # Deploy to the device. - if [[ $((disable_deploy)) -eq 0 ]]; then - install_apk "${package_name}" "${output_apk}" "${adb_device}" - fi - - if [[ "${ant_target}" == "debug" && $((run_debugger)) -eq 1 ]]; then - # Start debugging. - ndk-gdb ${adb_device} --start - elif [[ $((launch)) -eq 1 ]]; then - launch_package "${package_name}" "${adb_device}" - fi -} - -main "$@" diff --git a/samples/android/gradle/wrapper/gradle-wrapper.jar b/samples/android/gradle/wrapper/gradle-wrapper.jar Binary files differnew file mode 100644 index 00000000..b4163b81 --- /dev/null +++ b/samples/android/gradle/wrapper/gradle-wrapper.jar diff --git a/samples/android/gradle/wrapper/gradle-wrapper.properties b/samples/android/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..1e1168cf --- /dev/null +++ b/samples/android/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Mon Jun 19 11:54:59 PDT 2017 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-all.zip diff --git a/samples/android/gradlew b/samples/android/gradlew new file mode 100755 index 00000000..cccdd3d5 --- /dev/null +++ b/samples/android/gradlew @@ -0,0 +1,172 @@ +#!/usr/bin/env sh + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "$@" diff --git a/samples/android/gradlew.bat b/samples/android/gradlew.bat new file mode 100644 index 00000000..f9553162 --- /dev/null +++ b/samples/android/gradlew.bat @@ -0,0 +1,84 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/samples/android/jni/Android.mk b/samples/android/jni/Android.mk index 6f22d285..917c2f9e 100755 --- a/samples/android/jni/Android.mk +++ b/samples/android/jni/Android.mk @@ -38,7 +38,7 @@ $(info $(LOCAL_C_INCLUDES)) LOCAL_SRC_FILES := main.cpp LOCAL_CPPFLAGS := -std=c++11 -fexceptions -Wall -Wno-literal-suffix -LOCAL_LDLIBS := -llog -landroid +LOCAL_LDLIBS := -llog -landroid -latomic LOCAL_ARM_MODE := arm LOCAL_STATIC_LIBRARIES := android_native_app_glue flatbuffers diff --git a/samples/android/jni/Application.mk b/samples/android/jni/Application.mk index 2fc9c737..ca9e8004 100755 --- a/samples/android/jni/Application.mk +++ b/samples/android/jni/Application.mk @@ -13,10 +13,8 @@ # 2. Altered source versions must be plainly marked as such, and must not be # misrepresented as being the original software. # 3. This notice may not be removed or altered from any source distribution. -APP_PLATFORM := android-10 +APP_PLATFORM := android-9 APP_PROJECT_PATH := $(call my-dir)/.. -APP_STL := gnustl_static - +APP_STL ?= stlport_static APP_ABI := armeabi-v7a - APP_CPPFLAGS += -std=c++11 diff --git a/samples/android_sample.sh b/samples/android_sample.sh index ead8fd80..53633aca 100755 --- a/samples/android_sample.sh +++ b/samples/android_sample.sh @@ -29,8 +29,7 @@ fi # Execute `build_apk.sh` to build and run the android app. cd android -./build_apk.sh +./gradlew build + + -# Cleanup the temporary files. -rm build.xml local.properties proguard-project.txt project.properties -rm -rf bin libs obj diff --git a/samples/monster_generated.h b/samples/monster_generated.h index f4bdbb34..9fca774d 100644 --- a/samples/monster_generated.h +++ b/samples/monster_generated.h @@ -103,6 +103,7 @@ struct EquipmentUnion { void Reset(); +#ifndef FLATBUFFERS_CPP98_STL template <typename T> void Set(T&& val) { Reset(); @@ -111,6 +112,7 @@ struct EquipmentUnion { value = new T(std::forward<T>(val)); } } +#endif // FLATBUFFERS_CPP98_STL static void *UnPack(const void *obj, Equipment type, const flatbuffers::resolver_function_t *resolver); flatbuffers::Offset<void> Pack(flatbuffers::FlatBufferBuilder &_fbb, const flatbuffers::rehasher_function_t *_rehasher = nullptr) const; @@ -165,13 +167,13 @@ STRUCT_END(Vec3, 12); struct MonsterT : public flatbuffers::NativeTable { typedef Monster TableType; - std::unique_ptr<Vec3> pos; + flatbuffers::unique_ptr<Vec3> pos; int16_t mana; int16_t hp; std::string name; std::vector<uint8_t> inventory; Color color; - std::vector<std::unique_ptr<WeaponT>> weapons; + std::vector<flatbuffers::unique_ptr<WeaponT>> weapons; EquipmentUnion equipped; MonsterT() : mana(150), @@ -461,13 +463,13 @@ inline MonsterT *Monster::UnPack(const flatbuffers::resolver_function_t *_resolv inline void Monster::UnPackTo(MonsterT *_o, const flatbuffers::resolver_function_t *_resolver) const { (void)_o; (void)_resolver; - { auto _e = pos(); if (_e) _o->pos = std::unique_ptr<Vec3>(new Vec3(*_e)); }; + { auto _e = pos(); if (_e) _o->pos = flatbuffers::unique_ptr<Vec3>(new Vec3(*_e)); }; { auto _e = mana(); _o->mana = _e; }; { auto _e = hp(); _o->hp = _e; }; { auto _e = name(); if (_e) _o->name = _e->str(); }; { auto _e = inventory(); if (_e) { _o->inventory.resize(_e->size()); for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->inventory[_i] = _e->Get(_i); } } }; { auto _e = color(); _o->color = _e; }; - { auto _e = weapons(); if (_e) { _o->weapons.resize(_e->size()); for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->weapons[_i] = std::unique_ptr<WeaponT>(_e->Get(_i)->UnPack(_resolver)); } } }; + { auto _e = weapons(); if (_e) { _o->weapons.resize(_e->size()); for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->weapons[_i] = flatbuffers::unique_ptr<WeaponT>(_e->Get(_i)->UnPack(_resolver)); } } }; { auto _e = equipped_type(); _o->equipped.type = _e; }; { auto _e = equipped(); if (_e) _o->equipped.value = EquipmentUnion::UnPack(_e, equipped_type(), _resolver); }; } @@ -479,13 +481,14 @@ inline flatbuffers::Offset<Monster> Monster::Pack(flatbuffers::FlatBufferBuilder inline flatbuffers::Offset<Monster> CreateMonster(flatbuffers::FlatBufferBuilder &_fbb, const MonsterT *_o, const flatbuffers::rehasher_function_t *_rehasher) { (void)_rehasher; (void)_o; + struct _VectorArgs { flatbuffers::FlatBufferBuilder *__fbb; const MonsterT* __o; const flatbuffers::rehasher_function_t *__rehasher; } _va = { &_fbb, _o, _rehasher}; (void)_va; auto _pos = _o->pos ? _o->pos.get() : 0; auto _mana = _o->mana; auto _hp = _o->hp; auto _name = _o->name.size() ? _fbb.CreateString(_o->name) : 0; auto _inventory = _o->inventory.size() ? _fbb.CreateVector(_o->inventory) : 0; auto _color = _o->color; - auto _weapons = _o->weapons.size() ? _fbb.CreateVector<flatbuffers::Offset<Weapon>>(_o->weapons.size(), [&](size_t i) { return CreateWeapon(_fbb, _o->weapons[i].get(), _rehasher); }) : 0; + auto _weapons = _o->weapons.size() ? _fbb.CreateVector<flatbuffers::Offset<Weapon>> (_o->weapons.size(), [](size_t i, _VectorArgs *__va) { return CreateWeapon(*__va->__fbb, __va->__o->weapons[i].get(), __va->__rehasher); }, &_va ) : 0; auto _equipped_type = _o->equipped.type; auto _equipped = _o->equipped.Pack(_fbb); return MyGame::Sample::CreateMonster( @@ -521,6 +524,7 @@ inline flatbuffers::Offset<Weapon> Weapon::Pack(flatbuffers::FlatBufferBuilder & inline flatbuffers::Offset<Weapon> CreateWeapon(flatbuffers::FlatBufferBuilder &_fbb, const WeaponT *_o, const flatbuffers::rehasher_function_t *_rehasher) { (void)_rehasher; (void)_o; + struct _VectorArgs { flatbuffers::FlatBufferBuilder *__fbb; const WeaponT* __o; const flatbuffers::rehasher_function_t *__rehasher; } _va = { &_fbb, _o, _rehasher}; (void)_va; auto _name = _o->name.size() ? _fbb.CreateString(_o->name) : 0; auto _damage = _o->damage; return MyGame::Sample::CreateWeapon( @@ -616,10 +620,10 @@ inline void FinishMonsterBuffer( fbb.Finish(root); } -inline std::unique_ptr<MonsterT> UnPackMonster( +inline flatbuffers::unique_ptr<MonsterT> UnPackMonster( const void *buf, const flatbuffers::resolver_function_t *res = nullptr) { - return std::unique_ptr<MonsterT>(GetMonster(buf)->UnPack(res)); + return flatbuffers::unique_ptr<MonsterT>(GetMonster(buf)->UnPack(res)); } } // namespace Sample |