diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 270ffbc9a..dc4e26f14 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -65,24 +65,20 @@ jobs: name: Mac flatc binary path: Release/flatc - -# FIXME: to make this work, this apparently needs: -# - a newer version of gradle in build.gradle (e.g. 3.2.1) -# - google() in the repos in build.gradle -# - gradle version 4.6 in gradle-wrapper.properties ? -# - some kind of flavor declaration? -# All while not breaking the existing Travis Android build. -# good luck. - -# build-android: -# name: Build Android (on Linux) -# runs-on: ubuntu-latest -# steps: -# - uses: actions/checkout@v1 -# - name: set up JDK 1.8 -# uses: actions/setup-java@v1 -# with: -# java-version: 1.8 -# - name: build -# working-directory: android -# run: bash ./gradlew buildDebug + build-android: + name: Build Android (on Linux) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + - name: set up flatc + run: | + cmake -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF . + make + echo "${PWD}" >> $GITHUB_PATH + - name: build + working-directory: android + run: bash ./gradlew clean build diff --git a/.travis.yml b/.travis.yml index e1825fad0..17d3cc0ca 100644 --- a/.travis.yml +++ b/.travis.yml @@ -185,37 +185,18 @@ matrix: components: - tools - platform-tools - - build-tools-25.0.2 - - android-25 - extra-android-m2repository + licenses: + - 'android-sdk-preview-license-52d11cd2' + - 'android-sdk-license-.+' + - 'google-gdk-license-.+' compiler: - gcc - before_install: - # Output something every 10 minutes or Travis kills the job - - while sleep 540; do echo "=====[ $SECONDS seconds still running ]====="; done & - # Install the r17c version of the NDK that still so that we can continue to test with gnustl - # and stlport. - - export ANDROID_NDK_HOME=$HOME/android-ndk - - NDK_ZIP=$ANDROID_NDK_HOME/ndk.zip - - mkdir -p $ANDROID_NDK_HOME - - curl -o $NDK_ZIP https://dl.google.com/android/repository/android-ndk-r17c-linux-x86_64.zip - - unzip -q -d $ANDROID_NDK_HOME $NDK_ZIP - - rm $NDK_ZIP - - mv $ANDROID_NDK_HOME/android-ndk-*/* $ANDROID_NDK_HOME - - rmdir $ANDROID_NDK_HOME/android-ndk-* - - export CMAKE=$(which cmake) - # libc required for prebuilt llvm toolchain the NDK r17c. - - if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get update -qq; fi - - if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install -qq libc6; fi - # Setup environment for Linux build which is required to build the sample. - - if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test; fi - - if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get update -qq; fi - - if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install -qq g++-$GCC_VERSION; fi - - if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install -qq gcc-$GCC_VERSION; fi - - if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo ln -s -v -f $(which g++-$GCC_VERSION) /usr/bin/g++; fi - - if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo ln -s -v -f $(which gcc-$GCC_VERSION) /usr/bin/gcc; fi + - echo y | sdkmanager "platforms;android-30" + - echo y | sdkmanager "build-tools;30.0.2" + - echo y | sdkmanager "ndk-bundle" + - echo y | sdkmanager "cmake;3.6.4111459" script: - - failed=0; for build_gradle in $(git ls-files | grep build.gradle); do ( cd "$(dirname "${build_gradle}")" && ./gradlew build ) || failed=1; done; exit $((failed)) - # Kill the sleep loop - - kill %1 + - cmake -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF .; make; export PATH="$PATH:${PWD}" + - cd android; ./gradlew clean build diff --git a/android/app/.gitignore b/android/app/.gitignore new file mode 100644 index 000000000..796b96d1c --- /dev/null +++ b/android/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/android/app/build.gradle b/android/app/build.gradle new file mode 100644 index 000000000..3ee9ba2fd --- /dev/null +++ b/android/app/build.gradle @@ -0,0 +1,136 @@ +apply plugin: 'com.android.application' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' + +android { + compileSdkVersion 30 + buildToolsVersion "30.0.2" + + defaultConfig { + applicationId "com.flatbuffers.app" + minSdkVersion 16 + targetSdkVersion 30 + versionCode 1 + versionName "1.0" + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + externalNativeBuild { + cmake { + arguments "-DFLATBUFFERS_SRC=${rootProject.projectDir}/.." + } + } + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + + ndkVersion "21.3.6528147" + externalNativeBuild { + cmake { + path "src/main/cpp/CMakeLists.txt" + } + } + + task generateFbsCpp(type: Exec) { + def inputDir = file("$projectDir/src/main/fbs") + def outputCppDir = file("$projectDir/src/main/cpp/generated/") + def fbsFiles = layout.files { file(inputDir).listFiles() }.filter { File f -> f.name.endsWith(".fbs") }.toList() + ignoreExitValue(true) + + standardOutput = new ByteArrayOutputStream() + errorOutput = new ByteArrayOutputStream() + commandLine 'flatc', '-o', outputCppDir, '--cpp', "${fbsFiles.join(" ")}" + + doFirst { + delete "$outputCppDir/" + mkdir "$outputCppDir/" + } + doLast { + if (execResult.getExitValue() != 0) { + println(standardOutput.toString()) + throw new GradleException("flatc command line failed") + } + } + } + + task generateFbsKotlin(type: Exec) { + def inputDir = file("$projectDir/src/main/fbs") + def outputKotlinDir = file("$projectDir/src/main/java/generated/") + def fbsFiles = layout.files { file(inputDir).listFiles() }.filter { File f -> f.name.endsWith(".fbs") }.toList() + ignoreExitValue(true) + + standardOutput = new ByteArrayOutputStream() + errorOutput = new ByteArrayOutputStream() + commandLine 'flatc', '-o', outputKotlinDir, '--kotlin', "${fbsFiles.join(" ")}" + + doFirst { + delete "$outputKotlinDir/" + mkdir "$outputKotlinDir/" + } + doLast { + if (execResult.getExitValue() != 0) { + println(standardOutput.toString()) + throw new GradleException("flatc command line failed") + } + } + } + + afterEvaluate { + android.applicationVariants.all { variant -> + variant.javaCompiler.dependsOn(generateFbsKotlin) + variant.javaCompiler.dependsOn(generateFbsCpp) + } + } + + flavorDimensions "stl-variant" + productFlavors { + stlport { + dimension "stl-variant" + applicationIdSuffix ".stlport" + versionNameSuffix "-stlport" + externalNativeBuild { + ndkBuild { + arguments "APP_STL=stlport_static" + } + } + } + gnustl { + dimension "stl-variant" + applicationIdSuffix ".gnustl" + versionNameSuffix "-gnustl" + externalNativeBuild { + ndkBuild { + arguments "APP_STL=gnustl_static" + } + } + } + libcpp { + dimension "stl-variant" + applicationIdSuffix ".libcpp" + versionNameSuffix "-libcpp" + externalNativeBuild { + ndkBuild { + arguments "APP_STL=c++_static" + } + } + } + } +} + +dependencies { + implementation fileTree(dir: "libs", include: ["*.jar"]) + implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" + implementation 'androidx.core:core-ktx:1.3.2' + implementation 'androidx.appcompat:appcompat:1.2.0' + implementation 'com.google.flatbuffers:flatbuffers-java:1.12.0' + +} diff --git a/android/app/proguard-rules.pro b/android/app/proguard-rules.pro new file mode 100644 index 000000000..f1b424510 --- /dev/null +++ b/android/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml new file mode 100644 index 000000000..c2dcba9b3 --- /dev/null +++ b/android/app/src/main/AndroidManifest.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + diff --git a/android/app/src/main/cpp/CMakeLists.txt b/android/app/src/main/cpp/CMakeLists.txt new file mode 100644 index 000000000..f30dd4a0a --- /dev/null +++ b/android/app/src/main/cpp/CMakeLists.txt @@ -0,0 +1,54 @@ +# For more information about using CMake with Android Studio, read the +# documentation: https://d.android.com/studio/projects/add-native-code.html + +# Sets the minimum version of CMake required to build the native library. + +cmake_minimum_required(VERSION 3.4.1) + +# Creates and names a library, sets it as either STATIC +# or SHARED, and provides the relative paths to its source code. +# You can define multiple libraries, and CMake builds them for you. +# Gradle automatically packages shared libraries with your APK. + +include_directories(${FLATBUFFERS_SRC}/include) + +add_subdirectory(flatbuffers) + +FILE(GLOB Generated_SRCS generated/*.h) + +add_library( # Sets the name of the library. + native-lib + + # Sets the library as a shared library. + SHARED + + # Provides a relative path to your source file(s). + animals.cpp + ${Generated_SRCS} + +) + +# Searches for a specified prebuilt library and stores the path as a +# variable. Because CMake includes system libraries in the search path by +# default, you only need to specify the name of the public NDK library +# you want to add. CMake verifies that the library exists before +# completing its build. + +find_library( # Sets the name of the path variable. + log-lib + + # Specifies the name of the NDK library that + # you want CMake to locate. + log ) + +# Specifies libraries CMake should link to your target library. You +# can link multiple libraries, such as libraries you define in this +# build script, prebuilt third-party libraries, or system libraries. + +target_link_libraries( # Specifies the target library. + native-lib + flatbuffers + flatbuffers_tests + # Links the target library to the log library + # included in the NDK. + ${log-lib} ) diff --git a/android/app/src/main/cpp/animals.cpp b/android/app/src/main/cpp/animals.cpp new file mode 100644 index 000000000..bf87b875c --- /dev/null +++ b/android/app/src/main/cpp/animals.cpp @@ -0,0 +1,39 @@ +/* + * Copyright 2014 Google Inc. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "generated/animal_generated.h" + +using namespace com::fbs::app; +using namespace flatbuffers; + +extern "C" JNIEXPORT jbyteArray JNICALL Java_com_flatbuffers_app_MainActivity_createAnimalFromJNI( + JNIEnv* env, + jobject /* this */) { + // create a new animal flatbuffers + auto fb = FlatBufferBuilder(1024); + auto tiger = CreateAnimalDirect(fb, "Tiger", "Roar", 300); + fb.Finish(tiger); + + // copies it to a Java byte array. + auto buf = reinterpret_cast(fb.GetBufferPointer()); + int size = fb.GetSize(); + auto ret = env->NewByteArray(size); + env->SetByteArrayRegion (ret, 0, fb.GetSize(), buf); + return ret; +} diff --git a/android/app/src/main/cpp/flatbuffers/CMakeLists.txt b/android/app/src/main/cpp/flatbuffers/CMakeLists.txt new file mode 100644 index 000000000..f32b0bbb4 --- /dev/null +++ b/android/app/src/main/cpp/flatbuffers/CMakeLists.txt @@ -0,0 +1,59 @@ +# For more information about using CMake with Android Studio, read the +# documentation: https://d.android.com/studio/projects/add-native-code.html + +# Sets the minimum version of CMake required to build the native library. + +cmake_minimum_required(VERSION 3.4.1) + +include_directories(${FLATBUFFERS_SRC}/include) + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11 -fexceptions -Wall -DFLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE") + +# Certain platforms such as ARM do not use signed chars by default +# which causes issues with certain bounds checks. +set(CMAKE_CXX_FLAGS + "${CMAKE_CXX_FLAGS} -fsigned-char") + +set(FlatBuffers_Library_SRCS + ${FLATBUFFERS_SRC}/include/flatbuffers/base.h + ${FLATBUFFERS_SRC}/include/flatbuffers/flatbuffers.h + ${FLATBUFFERS_SRC}/include/flatbuffers/hash.h + ${FLATBUFFERS_SRC}/include/flatbuffers/idl.h + ${FLATBUFFERS_SRC}/include/flatbuffers/util.h + ${FLATBUFFERS_SRC}/include/flatbuffers/reflection.h + ${FLATBUFFERS_SRC}/include/flatbuffers/reflection_generated.h + ${FLATBUFFERS_SRC}/include/flatbuffers/stl_emulation.h + ${FLATBUFFERS_SRC}/include/flatbuffers/flexbuffers.h + ${FLATBUFFERS_SRC}/include/flatbuffers/registry.h + ${FLATBUFFERS_SRC}/include/flatbuffers/minireflect.h + ${FLATBUFFERS_SRC}/src/idl_parser.cpp + ${FLATBUFFERS_SRC}/src/idl_gen_text.cpp + ${FLATBUFFERS_SRC}/src/reflection.cpp + ${FLATBUFFERS_SRC}/src/util.cpp + ${FLATBUFFERS_SRC}/src/idl_gen_fbs.cpp + ${FLATBUFFERS_SRC}/src/code_generators.cpp + ) + +set(FlatBuffers_Test_SRCS + ${FLATBUFFERS_SRC}/tests/test.cpp + ${FLATBUFFERS_SRC}/tests/test_assert.h + ${FLATBUFFERS_SRC}/tests/test_builder.h + ${FLATBUFFERS_SRC}/tests/test_assert.cpp + ${FLATBUFFERS_SRC}/tests/test_builder.cpp + ${FLATBUFFERS_SRC}/tests/native_type_test_impl.h + ${FLATBUFFERS_SRC}/tests/native_type_test_impl.cpp +) + +add_library( # Sets the name of the library. + flatbuffers + + ${FlatBuffers_Library_SRCS} + ${FlatBuffers_Test_SRCS} + ${Generated_SRCS} +) + +add_library( # Sets the name of the library. + flatbuffers_tests + + ${FlatBuffers_Test_SRCS} +) diff --git a/android/app/src/main/cpp/generated/animal_generated.h b/android/app/src/main/cpp/generated/animal_generated.h new file mode 100644 index 000000000..1ba9b0900 --- /dev/null +++ b/android/app/src/main/cpp/generated/animal_generated.h @@ -0,0 +1,128 @@ +// automatically generated by the FlatBuffers compiler, do not modify + + +#ifndef FLATBUFFERS_GENERATED_ANIMAL_COM_FBS_APP_H_ +#define FLATBUFFERS_GENERATED_ANIMAL_COM_FBS_APP_H_ + +#include "flatbuffers/flatbuffers.h" + +namespace com { +namespace fbs { +namespace app { + +struct Animal; +struct AnimalBuilder; + +struct Animal FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef AnimalBuilder Builder; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_NAME = 4, + VT_SOUND = 6, + VT_WEIGHT = 8 + }; + const flatbuffers::String *name() const { + return GetPointer(VT_NAME); + } + const flatbuffers::String *sound() const { + return GetPointer(VT_SOUND); + } + uint16_t weight() const { + return GetField(VT_WEIGHT, 0); + } + bool Verify(flatbuffers::Verifier &verifier) const { + return VerifyTableStart(verifier) && + VerifyOffset(verifier, VT_NAME) && + verifier.VerifyString(name()) && + VerifyOffset(verifier, VT_SOUND) && + verifier.VerifyString(sound()) && + VerifyField(verifier, VT_WEIGHT) && + verifier.EndTable(); + } +}; + +struct AnimalBuilder { + typedef Animal Table; + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_name(flatbuffers::Offset name) { + fbb_.AddOffset(Animal::VT_NAME, name); + } + void add_sound(flatbuffers::Offset sound) { + fbb_.AddOffset(Animal::VT_SOUND, sound); + } + void add_weight(uint16_t weight) { + fbb_.AddElement(Animal::VT_WEIGHT, weight, 0); + } + explicit AnimalBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) { + start_ = fbb_.StartTable(); + } + AnimalBuilder &operator=(const AnimalBuilder &); + flatbuffers::Offset Finish() { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateAnimal( + flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset name = 0, + flatbuffers::Offset sound = 0, + uint16_t weight = 0) { + AnimalBuilder builder_(_fbb); + builder_.add_sound(sound); + builder_.add_name(name); + builder_.add_weight(weight); + return builder_.Finish(); +} + +inline flatbuffers::Offset CreateAnimalDirect( + flatbuffers::FlatBufferBuilder &_fbb, + const char *name = nullptr, + const char *sound = nullptr, + uint16_t weight = 0) { + auto name__ = name ? _fbb.CreateString(name) : 0; + auto sound__ = sound ? _fbb.CreateString(sound) : 0; + return com::fbs::app::CreateAnimal( + _fbb, + name__, + sound__, + weight); +} + +inline const com::fbs::app::Animal *GetAnimal(const void *buf) { + return flatbuffers::GetRoot(buf); +} + +inline const com::fbs::app::Animal *GetSizePrefixedAnimal(const void *buf) { + return flatbuffers::GetSizePrefixedRoot(buf); +} + +inline bool VerifyAnimalBuffer( + flatbuffers::Verifier &verifier) { + return verifier.VerifyBuffer(nullptr); +} + +inline bool VerifySizePrefixedAnimalBuffer( + flatbuffers::Verifier &verifier) { + return verifier.VerifySizePrefixedBuffer(nullptr); +} + +inline void FinishAnimalBuffer( + flatbuffers::FlatBufferBuilder &fbb, + flatbuffers::Offset root) { + fbb.Finish(root); +} + +inline void FinishSizePrefixedAnimalBuffer( + flatbuffers::FlatBufferBuilder &fbb, + flatbuffers::Offset root) { + fbb.FinishSizePrefixed(root); +} + +} // namespace app +} // namespace fbs +} // namespace com + +#endif // FLATBUFFERS_GENERATED_ANIMAL_COM_FBS_APP_H_ diff --git a/samples/android/jni/schemas/animal.fbs b/android/app/src/main/fbs/animal.fbs similarity index 94% rename from samples/android/jni/schemas/animal.fbs rename to android/app/src/main/fbs/animal.fbs index d1bd38d55..479e22b29 100644 --- a/samples/android/jni/schemas/animal.fbs +++ b/android/app/src/main/fbs/animal.fbs @@ -12,11 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -namespace sample; +namespace com.fbs.app; table Animal { name:string; sound:string; + weight: uint16; } root_type Animal; diff --git a/android/app/src/main/java/com/flatbuffers/app/MainActivity.kt b/android/app/src/main/java/com/flatbuffers/app/MainActivity.kt new file mode 100644 index 000000000..cdc35730e --- /dev/null +++ b/android/app/src/main/java/com/flatbuffers/app/MainActivity.kt @@ -0,0 +1,51 @@ +package com.flatbuffers.app + +import android.annotation.SuppressLint +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle +import android.widget.TextView +import com.fbs.app.Animal +import com.google.flatbuffers.FlatBufferBuilder +import java.nio.ByteBuffer + +@ExperimentalUnsignedTypes +class MainActivity : AppCompatActivity() { + + @SuppressLint("SetTextI18n") + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + + val tiger = Animal.getRootAsAnimal(ByteBuffer.wrap(createAnimalFromJNI())) + findViewById(R.id.tv_animal_one).text = animalInfo(tiger) + + findViewById(R.id.tv_animal_two).text = animalInfo(createAnimalFromKotlin()) + } + + // This function is a sample of communicating FlatBuffers between JNI (native C++) and Java. + // Implementation can be found on animals.cpp file. + private external fun createAnimalFromJNI(): ByteArray + + // Create a "Cow" Animal flatbuffers from Kotlin + private fun createAnimalFromKotlin():Animal { + val fb = FlatBufferBuilder(100) + val cowOffset = Animal.createAnimal( + builder = fb, + nameOffset = fb.createString("Cow"), + soundOffset = fb.createString("Moo"), + weight = 720u + ) + fb.finish(cowOffset) + return Animal.getRootAsAnimal(fb.dataBuffer()) + } + + private fun animalInfo(animal: Animal): String = + "The ${animal.name} sound is ${animal.sound} and it weights ${animal.weight}kg." + + companion object { + // Used to load the 'native-lib' library on application startup. + init { + System.loadLibrary("native-lib") + } + } +} diff --git a/android/app/src/main/java/generated/com/fbs/app/Animal.kt b/android/app/src/main/java/generated/com/fbs/app/Animal.kt new file mode 100644 index 000000000..82cb37dce --- /dev/null +++ b/android/app/src/main/java/generated/com/fbs/app/Animal.kt @@ -0,0 +1,64 @@ +// automatically generated by the FlatBuffers compiler, do not modify + +package com.fbs.app + +import java.nio.* +import kotlin.math.sign +import com.google.flatbuffers.* + +@Suppress("unused") +@ExperimentalUnsignedTypes +class Animal : Table() { + + fun __init(_i: Int, _bb: ByteBuffer) { + __reset(_i, _bb) + } + fun __assign(_i: Int, _bb: ByteBuffer) : Animal { + __init(_i, _bb) + return this + } + val name : String? + get() { + val o = __offset(4) + return if (o != 0) __string(o + bb_pos) else null + } + val nameAsByteBuffer : ByteBuffer get() = __vector_as_bytebuffer(4, 1) + fun nameInByteBuffer(_bb: ByteBuffer) : ByteBuffer = __vector_in_bytebuffer(_bb, 4, 1) + val sound : String? + get() { + val o = __offset(6) + return if (o != 0) __string(o + bb_pos) else null + } + val soundAsByteBuffer : ByteBuffer get() = __vector_as_bytebuffer(6, 1) + fun soundInByteBuffer(_bb: ByteBuffer) : ByteBuffer = __vector_in_bytebuffer(_bb, 6, 1) + val weight : UShort + get() { + val o = __offset(8) + return if(o != 0) bb.getShort(o + bb_pos).toUShort() else 0u + } + companion object { + fun validateVersion() = Constants.FLATBUFFERS_1_12_0() + fun getRootAsAnimal(_bb: ByteBuffer): Animal = getRootAsAnimal(_bb, Animal()) + fun getRootAsAnimal(_bb: ByteBuffer, obj: Animal): Animal { + _bb.order(ByteOrder.LITTLE_ENDIAN) + return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)) + } + fun createAnimal(builder: FlatBufferBuilder, nameOffset: Int, soundOffset: Int, weight: UShort) : Int { + builder.startTable(3) + addSound(builder, soundOffset) + addName(builder, nameOffset) + addWeight(builder, weight) + return endAnimal(builder) + } + fun startAnimal(builder: FlatBufferBuilder) = builder.startTable(3) + fun addName(builder: FlatBufferBuilder, name: Int) = builder.addOffset(0, name, 0) + fun addSound(builder: FlatBufferBuilder, sound: Int) = builder.addOffset(1, sound, 0) + fun addWeight(builder: FlatBufferBuilder, weight: UShort) = builder.addShort(2, weight.toShort(), 0) + fun endAnimal(builder: FlatBufferBuilder) : Int { + val o = builder.endTable() + return o + } + fun finishAnimalBuffer(builder: FlatBufferBuilder, offset: Int) = builder.finish(offset) + fun finishSizePrefixedAnimalBuffer(builder: FlatBufferBuilder, offset: Int) = builder.finishSizePrefixed(offset) + } +} diff --git a/android/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/android/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 000000000..7706ab9e6 --- /dev/null +++ b/android/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + diff --git a/android/app/src/main/res/drawable/ic_launcher_background.xml b/android/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 000000000..07d5da9cb --- /dev/null +++ b/android/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/android/app/src/main/res/layout/activity_main.xml b/android/app/src/main/res/layout/activity_main.xml new file mode 100644 index 000000000..d339c2240 --- /dev/null +++ b/android/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,23 @@ + + + + + + + + diff --git a/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml new file mode 100644 index 000000000..6b78462d6 --- /dev/null +++ b/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml new file mode 100644 index 000000000..6b78462d6 --- /dev/null +++ b/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/android/app/src/main/res/mipmap-hdpi/ic_launcher.png b/android/app/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 000000000..a571e6009 Binary files /dev/null and b/android/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png b/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png new file mode 100644 index 000000000..61da551c5 Binary files /dev/null and b/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png differ diff --git a/android/app/src/main/res/mipmap-mdpi/ic_launcher.png b/android/app/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 000000000..c41dd2853 Binary files /dev/null and b/android/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png b/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png new file mode 100644 index 000000000..db5080a75 Binary files /dev/null and b/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png differ diff --git a/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 000000000..6dba46dab Binary files /dev/null and b/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png new file mode 100644 index 000000000..da31a871c Binary files /dev/null and b/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png differ diff --git a/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 000000000..15ac68172 Binary files /dev/null and b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png new file mode 100644 index 000000000..b216f2d31 Binary files /dev/null and b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png differ diff --git a/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 000000000..f25a41974 Binary files /dev/null and b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png new file mode 100644 index 000000000..e96783ccc Binary files /dev/null and b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png differ diff --git a/android/app/src/main/res/values/colors.xml b/android/app/src/main/res/values/colors.xml new file mode 100644 index 000000000..030098fe0 --- /dev/null +++ b/android/app/src/main/res/values/colors.xml @@ -0,0 +1,6 @@ + + + #6200EE + #3700B3 + #03DAC5 + diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml new file mode 100644 index 000000000..71d53e98a --- /dev/null +++ b/android/app/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + FlatbuffersTestApp + diff --git a/android/app/src/main/res/values/styles.xml b/android/app/src/main/res/values/styles.xml new file mode 100644 index 000000000..391ec9ae3 --- /dev/null +++ b/android/app/src/main/res/values/styles.xml @@ -0,0 +1,10 @@ + + + + + diff --git a/android/build.gradle b/android/build.gradle index 5e9809be7..d37c10c8d 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,108 +1,35 @@ -// 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. - +// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { + ext.kotlin_version = "1.4.10" repositories { + google() jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.0' + classpath 'com.android.tools.build:gradle:4.1.0' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files } } allprojects { repositories { + google() jcenter() } } -apply plugin: 'com.android.application' +tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 -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.example.FlatBufferTest' - // 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 "FlatBufferTest" - arguments "-j" + Runtime.getRuntime().availableProcessors() - abiFilters "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" - } - } - } + compileKotlin { + dependsOn flatbuffer } } + +task clean(type: Delete) { + delete rootProject.buildDir +} diff --git a/android/gradle.properties b/android/gradle.properties new file mode 100644 index 000000000..9bb1cb21f --- /dev/null +++ b/android/gradle.properties @@ -0,0 +1,21 @@ +# Project-wide Gradle settings. +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +org.gradle.jvmargs=-Xmx2048m +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true +# AndroidX package structure to make it clearer which packages are bundled with the +# Android operating system, and which are packaged with your app"s APK +# https://developer.android.com/topic/libraries/support-library/androidx-rn +android.useAndroidX=true +# Automatically convert third-party libraries to use AndroidX +android.enableJetifier=true +# Kotlin code style for this project: "official" or "obsolete": +kotlin.code.style=official diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties index 1e1168cf6..416f23c9b 100644 --- a/android/gradle/wrapper/gradle-wrapper.properties +++ b/android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon Jun 19 11:54:59 PDT 2017 +#Thu Oct 29 19:47:23 CET 2020 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 +distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip diff --git a/android/jni/Android.mk b/android/jni/Android.mk deleted file mode 100644 index 78614fb06..000000000 --- a/android/jni/Android.mk +++ /dev/null @@ -1,64 +0,0 @@ -# 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. - -LOCAL_PATH := $(call my-dir)/../.. - -include $(LOCAL_PATH)/android/jni/include.mk -LOCAL_PATH := $(call realpath-portable,$(LOCAL_PATH)) - -# Empty static library so that other projects can include just the basic -# FlatBuffers headers as a module. -include $(CLEAR_VARS) -LOCAL_MODULE := flatbuffers -LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include -LOCAL_EXPORT_CPPFLAGS := -std=c++11 -fexceptions -Wall \ - -DFLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE - -include $(BUILD_STATIC_LIBRARY) - -# static library that additionally includes text parsing/generation/reflection -# for projects that want richer functionality. -include $(CLEAR_VARS) -LOCAL_MODULE := flatbuffers_extra -LOCAL_SRC_FILES := src/idl_parser.cpp \ - src/idl_gen_text.cpp \ - src/reflection.cpp \ - src/util.cpp -LOCAL_STATIC_LIBRARIES := flatbuffers -LOCAL_ARM_MODE := arm -include $(BUILD_STATIC_LIBRARY) - -# FlatBuffers test -include $(CLEAR_VARS) -LOCAL_MODULE := FlatBufferTest -LOCAL_SRC_FILES := android/jni/main.cpp \ - tests/test.cpp \ - tests/test_assert.h \ - tests/test_builder.h \ - tests/test_assert.cpp \ - tests/test_builder.cpp \ - tests/native_type_test_impl.h \ - tests/native_type_test_impl.cpp \ - src/idl_gen_fbs.cpp \ - src/code_generators.cpp -LOCAL_LDLIBS := -llog -landroid -latomic -LOCAL_STATIC_LIBRARIES := android_native_app_glue flatbuffers_extra -LOCAL_ARM_MODE := arm -include $(BUILD_SHARED_LIBRARY) - -$(call import-module,android/native_app_glue) - -$(call import-add-path,$(LOCAL_PATH)/../..) diff --git a/android/jni/Application.mk b/android/jni/Application.mk deleted file mode 100644 index ca9e8004d..000000000 --- a/android/jni/Application.mk +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright (c) 2014 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. -APP_PLATFORM := android-9 -APP_PROJECT_PATH := $(call my-dir)/.. -APP_STL ?= stlport_static -APP_ABI := armeabi-v7a -APP_CPPFLAGS += -std=c++11 diff --git a/android/jni/build_flatc.bat b/android/jni/build_flatc.bat deleted file mode 100644 index 0b3f2ad18..000000000 --- a/android/jni/build_flatc.bat +++ /dev/null @@ -1,68 +0,0 @@ -@rem Copyright (c) 2013 Google, Inc. -@rem -@rem This software is provided 'as-is', without any express or implied -@rem warranty. In no event will the authors be held liable for any damages -@rem arising from the use of this software. -@rem Permission is granted to anyone to use this software for any purpose, -@rem including commercial applications, and to alter it and redistribute it -@rem freely, subject to the following restrictions: -@rem 1. The origin of this software must not be misrepresented; you must not -@rem claim that you wrote the original software. If you use this software -@rem in a product, an acknowledgment in the product documentation would be -@rem appreciated but is not required. -@rem 2. Altered source versions must be plainly marked as such, and must not be -@rem misrepresented as being the original software. -@rem 3. This notice may not be removed or altered from any source distribution. -@echo off - -setlocal enabledelayedexpansion - -set thispath=%~dp0 - -rem Path to cmake passed in by caller. -set cmake=%1 -rem Path to cmake project to build. -set cmake_project_path=%2 - -rem Newest and oldest version of Visual Studio that it's possible to select. -set visual_studio_version_max=20 -set visual_studio_version_min=8 - -rem Determine the newest version of Visual Studio installed on this machine. -set visual_studio_version= -for /L %%a in (%visual_studio_version_max%,-1,%visual_studio_version_min%) do ( - echo Searching for Visual Studio %%a >&2 - reg query HKLM\SOFTWARE\Microsoft\VisualStudio\%%a.0 /ve 1>NUL 2>NUL - if !ERRORLEVEL! EQU 0 ( - set visual_studio_version=%%a - goto found_vs - ) -) -echo Unable to determine whether Visual Studio is installed. >&2 -exit /B 1 -:found_vs - -rem Map Visual Studio version to cmake generator name. -if "%visual_studio_version%"=="8" ( - set cmake_generator=Visual Studio 8 2005 -) -if "%visual_studio_version%"=="9" ( - set cmake_generator=Visual Studio 9 2008 -) -if %visual_studio_version% GEQ 10 ( - set cmake_generator=Visual Studio %visual_studio_version% -) -rem Set visual studio version variable for msbuild. -set VisualStudioVersion=%visual_studio_version%.0 - -rem Generate Visual Studio solution. -echo Generating solution for %cmake_generator%. >&2 -cd "%cmake_project_path%" -%cmake% -G"%cmake_generator%" -if %ERRORLEVEL% NEQ 0 ( - exit /B %ERRORLEVEL% -) - -rem Build flatc -python %thispath%\msbuild.py flatc.vcxproj -if ERRORLEVEL 1 exit /B 1 diff --git a/android/jni/include.mk b/android/jni/include.mk deleted file mode 100644 index b53e25739..000000000 --- a/android/jni/include.mk +++ /dev/null @@ -1,237 +0,0 @@ -# Copyright 2014 Google Inc. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# This file contains utility functions for Android projects using Flatbuffers. -# To use this file, include it in your project's Android.mk by calling near the -# top of your android makefile like so: -# -# include $(FLATBUFFERS_DIR)/android/jni/include.mk -# -# You will also need to import the flatbuffers module using the standard -# import-module function. -# -# The main functionality this file provides are the following functions: -# flatbuffers_fbs_to_h: Converts flatbuffer schema paths to header paths. -# flatbuffers_header_build_rule: -# Creates a build rule for a schema's generated header. This build rule -# has a dependency on the flatc compiler which will be built if necessary. -# flatbuffers_header_build_rules: -# Creates build rules for generated headers for each schema listed and sets -# up depenedendies. -# -# More information and example usage can be found in the comments preceeding -# each function. - -# Targets to build the Flatbuffers compiler as well as some utility definitions -ifeq (,$(FLATBUFFERS_INCLUDE_MK_)) -FLATBUFFERS_INCLUDE_MK_ := 1 - -# Portable version of $(realpath) that omits drive letters on Windows. -realpath-portable = $(join $(filter %:,$(subst :,: ,$1)),\ - $(realpath $(filter-out %:,$(subst :,: ,$1)))) - -PROJECT_OS := $(OS) -ifeq (,$(OS)) -PROJECT_OS := $(shell uname -s) -else -ifneq ($(findstring Windows,$(PROJECT_OS)),) -PROJECT_OS := Windows -endif -endif - -# The following block generates build rules which result in headers being -# rebuilt from flatbuffers schemas. - -FLATBUFFERS_CMAKELISTS_DIR := \ - $(call realpath-portable,$(dir $(lastword $(MAKEFILE_LIST)))/../..) - -# Directory that contains the FlatBuffers compiler. -ifeq (Windows,$(PROJECT_OS)) -FLATBUFFERS_FLATC_PATH?=$(FLATBUFFERS_CMAKELISTS_DIR) -FLATBUFFERS_FLATC := $(lastword \ - $(wildcard $(FLATBUFFERS_FLATC_PATH)/*/flatc.exe) \ - $(wildcard $(FLATBUFFERS_FLATC_PATH)/flatc.exe)) -endif -ifeq (Linux,$(PROJECT_OS)) -FLATBUFFERS_FLATC_PATH?=$(FLATBUFFERS_CMAKELISTS_DIR) -FLATBUFFERS_FLATC := $(FLATBUFFERS_FLATC_PATH)/flatc -endif -ifeq (Darwin,$(PROJECT_OS)) -FLATBUFFERS_FLATC_PATH?=$(FLATBUFFERS_CMAKELISTS_DIR) -FLATBUFFERS_FLATC := $(lastword \ - $(wildcard $(FLATBUFFERS_FLATC_PATH)/*/flatc) \ - $(wildcard $(FLATBUFFERS_FLATC_PATH)/flatc)) -endif - -FLATBUFFERS_FLATC_ARGS?= - -# Search for cmake. -CMAKE_ROOT := \ - $(call realpath-portable,$(LOCAL_PATH)/../../../../../../prebuilts/cmake) -ifeq (,$(CMAKE)) -ifeq (Linux,$(PROJECT_OS)) -CMAKE := $(wildcard $(CMAKE_ROOT)/linux-x86/current/bin/cmake*) -endif -ifeq (Darwin,$(PROJECT_OS)) -CMAKE := \ - $(wildcard $(CMAKE_ROOT)/darwin-x86_64/current/*.app/Contents/bin/cmake) -endif -ifeq (Windows,$(PROJECT_OS)) -CMAKE := $(wildcard $(CMAKE_ROOT)/windows/current/bin/cmake*) -endif -endif -ifeq (,$(CMAKE)) -CMAKE := cmake -endif - -# Windows friendly portable local path. -# GNU-make doesn't like : in paths, must use relative paths on Windows. -ifeq (Windows,$(PROJECT_OS)) -PORTABLE_LOCAL_PATH = -else -PORTABLE_LOCAL_PATH = $(LOCAL_PATH)/ -endif - -# Generate a host build rule for the flatbuffers compiler. -ifeq (Windows,$(PROJECT_OS)) -define build_flatc_recipe - $(FLATBUFFERS_CMAKELISTS_DIR)\android\jni\build_flatc.bat \ - $(CMAKE) $(FLATBUFFERS_CMAKELISTS_DIR) -endef -endif -ifeq (Linux,$(PROJECT_OS)) -define build_flatc_recipe - +cd $(FLATBUFFERS_CMAKELISTS_DIR) && \ - $(CMAKE) . && \ - $(MAKE) flatc -endef -endif -ifeq (Darwin,$(PROJECT_OS)) -define build_flatc_recipe - cd $(FLATBUFFERS_CMAKELISTS_DIR) && "$(CMAKE)" -GXcode . && \ - xcodebuild -target flatc -endef -endif -ifeq (,$(build_flatc_recipe)) -ifeq (,$(FLATBUFFERS_FLATC)) -$(error flatc binary not found!) -endif -endif - -# Generate a build rule for flatc. -ifeq ($(strip $(FLATBUFFERS_FLATC)),) -flatc_target := build_flatc -.PHONY: $(flatc_target) -FLATBUFFERS_FLATC := \ - python $(FLATBUFFERS_CMAKELISTS_DIR)/android/jni/run_flatc.py \ - $(FLATBUFFERS_CMAKELISTS_DIR) -else -flatc_target := $(FLATBUFFERS_FLATC) -endif -$(flatc_target): - $(call build_flatc_recipe) - -# $(flatbuffers_fbs_to_h schema_dir,output_dir,path) -# -# Convert the specified schema path to a Flatbuffers generated header path. -# For example: -# -# $(call flatbuffers_fbs_to_h,$(MY_PROJ_DIR)/schemas,\ -# $(MY_PROJ_DIR)/gen/include,$(MY_PROJ_DIR)/schemas/example.fbs) -# -# This will convert the file path `$(MY_PROJ_DIR)/schemas/example.fbs)` to -# `$(MY_PROJ_DIR)/gen/include/example_generated.h` -define flatbuffers_fbs_to_h -$(subst $(1),$(2),$(patsubst %.fbs,%_generated.h,$(3))) -endef - -# $(flatbuffers_header_build_rule schema_file,schema_dir,output_dir,\ -# schema_include_dirs) -# -# Generate a build rule that will convert a Flatbuffers schema to a generated -# header derived from the schema filename using flatbuffers_fbs_to_h. For -# example: -# -# $(call flatbuffers_header_build_rule,$(MY_PROJ_DIR)/schemas/example.fbs,\ -# $(MY_PROJ_DIR)/schemas,$(MY_PROJ_DIR)/gen/include) -# -# The final argument, schema_include_dirs, is optional and is only needed when -# the schema files depend on other schema files outside their own directory. -define flatbuffers_header_build_rule -$(eval \ - $(call flatbuffers_fbs_to_h,$(2),$(3),$(1)): $(1) $(flatc_target) - $(call host-echo-build-step,generic,Generate) \ - $(subst $(LOCAL_PATH)/,,$(call flatbuffers_fbs_to_h,$(2),$(3),$(1))) - $(hide) $$(FLATBUFFERS_FLATC) $(FLATBUFFERS_FLATC_ARGS) \ - $(foreach include,$(4),-I $(include)) -o $$(dir $$@) -c $$<) -endef - -# TODO: Remove when the LOCAL_PATH expansion bug in the NDK is fixed. -# Override the default behavior of local-source-file-path to workaround -# a bug which prevents the build of deeply nested projects when NDK_OUT is -# set. -local-source-file-path=\ -$(if $(call host-path-is-absolute,$1),$1,$(call \ - realpath-portable,$(LOCAL_PATH)/$1)) - - -# $(flatbuffers_header_build_rules schema_files,schema_dir,output_dir,\ -# schema_include_dirs,src_files,[build_target],[dependencies])) -# -# $(1) schema_files: Space separated list of flatbuffer schema files. -# $(2) schema_dir: Directory containing the flatbuffer schemas. -# $(3) output_dir: Where to place the generated files. -# $(4) schema_include_dirs: Directories to include when generating schemas. -# $(5) src_files: Files that should depend upon the headers generated from the -# flatbuffer schemas. -# $(6) build_target: Name of a build target that depends upon all generated -# headers. -# $(7) dependencies: Space seperated list of additional build targets src_files -# should depend upon. -# -# Use this in your own Android.mk file to generate build rules that will -# generate header files for your flatbuffer schemas as well as automatically -# set your source files to be dependent on the generated headers. For example: -# -# $(call flatbuffers_header_build_rules,$(MY_PROJ_SCHEMA_FILES),\ -# $(MY_PROJ_SCHEMA_DIR),$(MY_PROJ_GENERATED_OUTPUT_DIR), -# $(MY_PROJ_SCHEMA_INCLUDE_DIRS),$(LOCAL_SRC_FILES)) -# -# NOTE: Due problesm with path processing in ndk-build when presented with -# deeply nested projects must redefine LOCAL_PATH after include this makefile -# using: -# -# LOCAL_PATH := $(call realpath-portable,$(LOCAL_PATH)) -# -define flatbuffers_header_build_rules -$(foreach schema,$(1),\ - $(call flatbuffers_header_build_rule,\ - $(schema),$(strip $(2)),$(strip $(3)),$(strip $(4))))\ -$(foreach src,$(strip $(5)),\ - $(eval $(call local-source-file-path,$(src)): \ - $(foreach schema,$(strip $(1)),\ - $(call flatbuffers_fbs_to_h,$(strip $(2)),$(strip $(3)),$(schema)))))\ -$(if $(6),\ - $(foreach schema,$(strip $(1)),\ - $(eval $(6): \ - $(call flatbuffers_fbs_to_h,$(strip $(2)),$(strip $(3)),$(schema)))),)\ -$(if $(7),\ - $(foreach src,$(strip $(5)),\ - $(eval $(call local-source-file-path,$(src)): $(strip $(7)))),)\ -$(if $(7),\ - $(foreach dependency,$(strip $(7)),\ - $(eval $(6): $(dependency))),) -endef - -endif # FLATBUFFERS_INCLUDE_MK_ diff --git a/android/jni/main.cpp b/android/jni/main.cpp deleted file mode 100644 index 182b346b3..000000000 --- a/android/jni/main.cpp +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2014 Google Inc. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -extern int main(int argc, char **argv); - -void android_main(android_app *) { - main(0, NULL); -} diff --git a/android/jni/msbuild.py b/android/jni/msbuild.py deleted file mode 100644 index 5f92d70f4..000000000 --- a/android/jni/msbuild.py +++ /dev/null @@ -1,77 +0,0 @@ -#!/usr/bin/python -# Copyright 2014 Google Inc. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Simple script that locates the newest MSBuild in one of several locations. - -This script will find the highest version number of MSBuild and run it, -passing its arguments through to MSBuild. -""" - -import glob -import os -import re -import string -import subprocess -import sys - -SYSTEMROOT = os.getenv("SYSTEMROOT", "c:\\windows") -PROGRAM_FILES = os.getenv("ProgramFiles", "c:\\Program Files") -PROGRAM_FILES_X86 = os.getenv("ProgramFiles(x86)", "c:\\Program Files (x86)") - -SEARCH_FOLDERS = [ PROGRAM_FILES + "\\MSBuild\\*\\Bin\\MSBuild.exe", - PROGRAM_FILES_X86 + "\\MSBuild\\*\\Bin\\MSBuild.exe", - SYSTEMROOT + "\\Microsoft.NET\Framework\\*\\MSBuild.exe" ] - -def compare_version(a, b): - """Compare two version number strings of the form W.X.Y.Z. - - The numbers are compared most-significant to least-significant. - For example, 12.345.67.89 > 2.987.88.99. - - Args: - a: First version number string to compare - b: Second version number string to compare - - Returns: - 0 if the numbers are identical, a positive number if 'a' is larger, and - a negative number if 'b' is larger. - """ - aa = string.split(a, ".") - bb = string.split(b, ".") - for i in range(0, 4): - if aa[i] != bb[i]: - return cmp(int(aa[i]), int(bb[i])) - return 0 - -def main(): - msbuilds = [] - - for folder in SEARCH_FOLDERS: - for file in glob.glob(folder): - p = subprocess.Popen([file, "/version"], stdout=subprocess.PIPE) - out, err = p.communicate() - match = re.search("^[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+$", out, re.M) - if match: - msbuilds.append({ 'ver':match.group(), 'exe':file }) - msbuilds.sort(lambda x, y: compare_version(x['ver'], y['ver']), reverse=True) - if len(msbuilds) == 0: - print "Unable to find MSBuild.\n" - return -1; - cmd = [msbuilds[0]['exe']] - cmd.extend(sys.argv[1:]) - return subprocess.call(cmd) - -if __name__ == '__main__': - sys.exit(main()) diff --git a/android/jni/run_flatc.py b/android/jni/run_flatc.py deleted file mode 100755 index cda13bbf8..000000000 --- a/android/jni/run_flatc.py +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/python -# Copyright 2015 Google Inc. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import platform -import subprocess -import sys - -EXECUTABLE_EXTENSION = '.exe' if platform.system() == 'Windows' else '' -# Paths to search for flatc relative to the current working directory. -FLATC_SEARCH_PATHS = [os.path.curdir, 'Release', 'Debug'] - -def main(): - """Script that finds and runs flatc built from source.""" - if len(sys.argv) < 2: - sys.stderr.write('Usage: run_flatc.py flatbuffers_dir [flatc_args]\n') - return 1 - cwd = os.getcwd() - flatc = '' - flatbuffers_dir = sys.argv[1] - for path in FLATC_SEARCH_PATHS: - current = os.path.join(flatbuffers_dir, path, - 'flatc' + EXECUTABLE_EXTENSION) - if os.path.exists(current): - flatc = current - break - if not flatc: - sys.stderr.write('flatc not found\n') - return 1 - command = [flatc] + sys.argv[2:] - return subprocess.call(command) - -if __name__ == '__main__': - sys.exit(main()) diff --git a/android/res/values/strings.xml b/android/res/values/strings.xml deleted file mode 100644 index ec752393e..000000000 --- a/android/res/values/strings.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - FlatBufferTest - diff --git a/android/settings.gradle b/android/settings.gradle new file mode 100644 index 000000000..c4c0afbc9 --- /dev/null +++ b/android/settings.gradle @@ -0,0 +1,2 @@ +include ':app' +rootProject.name = "FlatbuffersTest" diff --git a/samples/android/AndroidManifest.xml b/samples/android/AndroidManifest.xml deleted file mode 100644 index 352e0fade..000000000 --- a/samples/android/AndroidManifest.xml +++ /dev/null @@ -1,45 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - diff --git a/samples/android/build.gradle b/samples/android/build.gradle deleted file mode 100644 index 81c1af0af..000000000 --- a/samples/android/build.gradle +++ /dev/null @@ -1,108 +0,0 @@ -// 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-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/gradle/wrapper/gradle-wrapper.jar b/samples/android/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index b4163b813..000000000 Binary files a/samples/android/gradle/wrapper/gradle-wrapper.jar and /dev/null differ diff --git a/samples/android/gradle/wrapper/gradle-wrapper.properties b/samples/android/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index 1e1168cf6..000000000 --- a/samples/android/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,6 +0,0 @@ -#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 deleted file mode 100755 index cccdd3d51..000000000 --- a/samples/android/gradlew +++ /dev/null @@ -1,172 +0,0 @@ -#!/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 deleted file mode 100644 index f9553162f..000000000 --- a/samples/android/gradlew.bat +++ /dev/null @@ -1,84 +0,0 @@ -@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 deleted file mode 100644 index 917c2f9ee..000000000 --- a/samples/android/jni/Android.mk +++ /dev/null @@ -1,56 +0,0 @@ -# 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. - -LOCAL_PATH := $(call my-dir) -FLATBUFFERS_ROOT_DIR := $(LOCAL_PATH)/../../.. - -# FlatBuffers test -include $(CLEAR_VARS) - -# Include the FlatBuffer utility function to generate header files from schemas. -include $(FLATBUFFERS_ROOT_DIR)/android/jni/include.mk - -LOCAL_MODULE := FlatBufferSample - -# Set up some useful variables to identify schema and output directories and -# schema files. -ANDROID_SAMPLE_GENERATED_OUTPUT_DIR := $(LOCAL_PATH)/gen/include -ANDROID_SAMPLE_SCHEMA_DIR := $(LOCAL_PATH)/schemas -ANDROID_SAMPLE_SCHEMA_FILES := $(ANDROID_SAMPLE_SCHEMA_DIR)/animal.fbs - -LOCAL_C_INCLUDES := $(ANDROID_SAMPLE_GENERATED_OUTPUT_DIR) - -$(info $(LOCAL_C_INCLUDES)) - -LOCAL_SRC_FILES := main.cpp - -LOCAL_CPPFLAGS := -std=c++11 -fexceptions -Wall -Wno-literal-suffix -LOCAL_LDLIBS := -llog -landroid -latomic -LOCAL_ARM_MODE := arm -LOCAL_STATIC_LIBRARIES := android_native_app_glue flatbuffers - -ifeq (,$(ANDROID_SAMPLE_RUN_ONCE)) -ANDROID_SAMPLE_RUN_ONCE := 1 -$(call flatbuffers_header_build_rules,$(ANDROID_SAMPLE_SCHEMA_FILES),$(ANDROID_SAMPLE_SCHEMA_DIR),$(ANDROID_SAMPLE_GENERATED_OUTPUT_DIR),,$(LOCAL_SRC_FILES)) -endif - -include $(BUILD_SHARED_LIBRARY) - -# Path to Flatbuffers root directory. -$(call import-add-path,$(FLATBUFFERS_ROOT_DIR)/..) - -$(call import-module,flatbuffers/android/jni) -$(call import-module,android/native_app_glue) diff --git a/samples/android/jni/Application.mk b/samples/android/jni/Application.mk deleted file mode 100644 index ca9e8004d..000000000 --- a/samples/android/jni/Application.mk +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright (c) 2014 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. -APP_PLATFORM := android-9 -APP_PROJECT_PATH := $(call my-dir)/.. -APP_STL ?= stlport_static -APP_ABI := armeabi-v7a -APP_CPPFLAGS += -std=c++11 diff --git a/samples/android/jni/main.cpp b/samples/android/jni/main.cpp deleted file mode 100644 index 0785a2bca..000000000 --- a/samples/android/jni/main.cpp +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2015 Google Inc. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include - -#include "android_native_app_glue.h" -#include "animal_generated.h" // Includes "flatbuffers/flatbuffers.h". - -void android_main(android_app *) { - flatbuffers::FlatBufferBuilder builder; - auto name = builder.CreateString("Dog"); - auto sound = builder.CreateString("Bark"); - auto animal_buffer = sample::CreateAnimal(builder, name, sound); - builder.Finish(animal_buffer); - - // We now have a FlatBuffer that can be stored on disk or sent over a network. - - // ...Code to store on disk or send over a network goes here... - - // Instead, we're going to access it immediately, as if we just recieved this. - - auto animal = sample::GetAnimal(builder.GetBufferPointer()); - - assert(animal->name()->str() == "Dog"); - assert(animal->sound()->str() == "Bark"); - (void)animal; // To silence "Unused Variable" warnings. - - __android_log_print(ANDROID_LOG_INFO, "FlatBufferSample", - "FlatBuffer successfully created and verified."); -} diff --git a/samples/android/res/values/strings.xml b/samples/android/res/values/strings.xml deleted file mode 100644 index 57ddaf4e1..000000000 --- a/samples/android/res/values/strings.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - FlatBufferSample - diff --git a/samples/android_sample.sh b/samples/android_sample.sh deleted file mode 100755 index 53633acad..000000000 --- a/samples/android_sample.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash -# -# Copyright 2015 Google Inc. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Note: This script requires the Android NDK and Android SDK to be installed. -# It also requires an Android device to be connected for installing and -# running the applicaton. - -sampledir=$(readlink -fn `dirname $0`) -currentdir=$(readlink -fn `pwd`) - -if [[ "$sampledir" != "$currentdir" ]]; then - echo Error: This script must be run from inside the $sampledir directory. - echo You executed it from the $currentdir directory. - exit 1 -fi - -# Execute `build_apk.sh` to build and run the android app. -cd android -./gradlew build - - -