Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
F
flatbuffers
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
flatbuffers
Commits
1c8c9438
Commit
1c8c9438
authored
Feb 04, 2015
by
Alex Ames
Committed by
Android (Google) Code Review
Feb 04, 2015
Browse files
Options
Browse Files
Download
Plain Diff
Merge "Added new Android build target and makefile utils." into ub-games-master
parents
4d3db992
ff1ac8ab
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
330 additions
and
7 deletions
+330
-7
build_apk.sh
android/build_apk.sh
+15
-1
Android.mk
android/jni/Android.mk
+15
-6
include.mk
android/jni/include.mk
+172
-0
Android.mk
samples/android/jni/Android.mk
+56
-0
Application.mk
samples/android/jni/Application.mk
+22
-0
main.cpp
samples/android/jni/main.cpp
+28
-0
animal.fbs
samples/android/jni/schemas/animal.fbs
+22
-0
No files found.
android/build_apk.sh
View file @
1c8c9438
...
@@ -235,11 +235,21 @@ select_android_build_target() {
...
@@ -235,11 +235,21 @@ select_android_build_target() {
local
android_build_target
=
local
android_build_target
=
for
android_target
in
$(
echo
"
${
android_targets_installed
}
"
|
\
for
android_target
in
$(
echo
"
${
android_targets_installed
}
"
|
\
awk
-F-
'{ print $2 }'
|
sort
-n
)
;
do
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
\
if
[[
$((
android_target
))
-ge
\
$((
BUILDAPK_ANDROID_TARGET_MINVERSION
))
]]
;
then
$((
BUILDAPK_ANDROID_TARGET_MINVERSION
))
]]
;
then
android_build_target
=
"android-
${
android_target
}
"
android_build_target
=
"android-
${
android_target
}
"
break
break
fi
fi
else
# The API version is a letter
# Letters are sorted to the end by 'sort -n'
# so we're out of numbered platforms. Use this one.
android_build_target
=
"android-
${
android_target
}
"
break
fi
done
done
if
[[
"
${
android_build_target
}
"
==
""
]]
;
then
if
[[
"
${
android_build_target
}
"
==
""
]]
;
then
echo
-e
\
echo
-e
\
...
@@ -415,14 +425,18 @@ main() {
...
@@ -415,14 +425,18 @@ main() {
local
build_package
=
1
local
build_package
=
1
for
opt
;
do
for
opt
;
do
case
${
opt
}
in
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
=
1
)
ant_target
=
debug
;;
NDK_DEBUG
=
0
)
ant_target
=
debug
;;
ADB_DEVICE
*
)
adb_device
=
"
$(
\
ADB_DEVICE
*
)
adb_device
=
"
$(
\
echo
"
${
opt
}
"
|
sed
-E
's/^ADB_DEVICE=([^ ]+)$/-s \1/;t;s/.*//'
)
"
;;
echo
"
${
opt
}
"
|
sed
-E
's/^ADB_DEVICE=([^ ]+)$/-s \1/;t;s/.*//'
)
"
;;
BUILD
=
0
)
disable_build
=
1
;;
BUILD
=
0
)
disable_build
=
1
;;
DEPLOY
=
0
)
disable_deploy
=
1
;;
DEPLOY
=
0
)
disable_deploy
=
1
;;
RUN_DEBUGGER
=
1
)
run_debugger
=
1
;;
RUN_DEBUGGER
=
1
)
run_debugger
=
1
;;
LAUNCH
=
0
)
launch
=
0
;;
LAUNCH
=
0
)
launch
=
0
;;
clean
)
build_package
=
0
;;
clean
)
build_package
=
0
disable_deploy
=
1
launch
=
0
;;
-h
|
--help
|
help
)
usage
;;
-h
|
--help
|
help
)
usage
;;
esac
esac
done
done
...
...
android/jni/Android.mk
View file @
1c8c9438
...
@@ -16,16 +16,25 @@
...
@@ -16,16 +16,25 @@
LOCAL_PATH := $(call my-dir)
LOCAL_PATH := $(call my-dir)
# Empty static library so that other projects can include FlatBuffers as a
# module.
include $(CLEAR_VARS)
include $(CLEAR_VARS)
LOCAL_MODULE := flatbuffers
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../../include
LOCAL_EXPORT_CPPFLAGS := -std=c++11 -fexceptions -Wall -Wno-literal-suffix
include $(BUILD_STATIC_LIBRARY)
# FlatBuffers test
include $(CLEAR_VARS)
LOCAL_MODULE := FlatBufferTest
LOCAL_MODULE := FlatBufferTest
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../include
LOCAL_SRC_FILES := main.cpp \
LOCAL_SRC_FILES := main.cpp ../../tests/test.cpp ../../src/idl_parser.cpp ../../src/idl_gen_text.cpp ../../src/idl_gen_fbs.cpp
../../tests/test.cpp \
../../src/idl_parser.cpp \
../../src/idl_gen_text.cpp \
../../src/idl_gen_fbs.cpp
LOCAL_LDLIBS := -llog -landroid
LOCAL_LDLIBS := -llog -landroid
LOCAL_STATIC_LIBRARIES := android_native_app_glue
LOCAL_STATIC_LIBRARIES := android_native_app_glue flatbuffers
LOCAL_ARM_MODE:=arm
LOCAL_ARM_MODE := arm
LOCAL_CPPFLAGS += -std=c++11 -fexceptions -Wall -Wno-literal-suffix
include $(BUILD_SHARED_LIBRARY)
include $(BUILD_SHARED_LIBRARY)
$(call import-module,android/native_app_glue)
$(call import-module,android/native_app_glue)
...
...
android/jni/include.mk
0 → 100644
View file @
1c8c9438
# 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
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.
# Directory that contains the FlatBuffers compiler.
FLATBUFFERS_FLATC_PATH?=$(CURDIR)/bin
ifeq (Windows,$(PROJECT_OS))
FLATBUFFERS_FLATC := $(FLATBUFFERS_FLATC_PATH)/Debug/flatc.exe
endif
ifeq (Linux,$(PROJECT_OS))
FLATBUFFERS_FLATC := $(FLATBUFFERS_FLATC_PATH)/flatc
endif
ifeq (Darwin,$(PROJECT_OS))
FLATBUFFERS_FLATC := $(FLATBUFFERS_FLATC_PATH)/Debug/flatc
endif
# Search for cmake.
CMAKE_ROOT := $(realpath $(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
# Generate a host build rule for the flatbuffers compiler.
FLATBUFFERS_CMAKELISTS_DIR := \
$(realpath $(dir $(lastword $(MAKEFILE_LIST)))/../..)
ifeq (Windows,$(PROJECT_OS))
define build_flatc_recipe
cd & jni\build_flatc.bat $(CMAKE)
endef
endif
ifeq (Linux,$(PROJECT_OS))
define build_flatc_recipe
mkdir -p bin && cd bin && $(CMAKE) $(FLATBUFFERS_CMAKELISTS_DIR) \
&& $(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)
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) --gen-includes \
$(foreach include,$(4),-I $(include)) -o $$(dir $$@) -c $$<)
endef
# $(flatbuffers_header_build_rules schema_files,schema_dir,output_dir,\
# schema_include_dirs,src_files))
#
# 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))
define flatbuffers_header_build_rules
$(foreach schema,$(1),\
$(call flatbuffers_header_build_rule,$(schema),$(2),$(3),$(4)))\
$(foreach src,$(5),\
$(eval $(LOCAL_PATH)/$$(src): \
$(foreach schema,$(1),$(call flatbuffers_fbs_to_h,$(2),$(3),$(schema)))))
endef
endif # FLATBUFFERS_INCLUDE_MK_
samples/android/jni/Android.mk
0 → 100755
View file @
1c8c9438
# 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 := sample_android_project
# 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
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)
samples/android/jni/Application.mk
0 → 100755
View file @
1c8c9438
# 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-10
APP_PROJECT_PATH := $(call my-dir)/..
APP_STL := gnustl_static
APP_ABI := armeabi-v7a
NDK_TOOLCHAIN_VERSION := 4.8
APP_CPPFLAGS += -std=c++11
samples/android/jni/main.cpp
0 → 100644
View file @
1c8c9438
// 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 "android_native_app_glue.h"
#include "animal_generated.h"
#include "flatbuffers/flatbuffers.h"
void
android_main
(
android_app
*
app
)
{
app_dummy
();
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
);
}
samples/android/jni/schemas/animal.fbs
0 → 100644
View file @
1c8c9438
// 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.
namespace sample;
table Animal {
name:string;
sound:string;
}
root_type Animal;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment