diff options
author | asuonpaa <34128694+asuonpaa@users.noreply.github.com> | 2019-11-13 16:04:17 +0200 |
---|---|---|
committer | dan sinclair <dsinclair@google.com> | 2019-11-13 09:04:17 -0500 |
commit | 956d9bb1338c9c5cbc717b7b9419dac1f330125d (patch) | |
tree | 5d051f935c618f353b69b85a5192231865e944a6 /samples | |
parent | 72614a05a50cfeb9dc64752962fb717cb1974cd5 (diff) | |
download | amber-956d9bb1338c9c5cbc717b7b9419dac1f330125d.tar.gz |
Add option to use Amber as a shared library on Android (#708)
Diffstat (limited to 'samples')
-rw-r--r-- | samples/Android.mk | 4 | ||||
-rw-r--r-- | samples/android_main.cc | 45 |
2 files changed, 49 insertions, 0 deletions
diff --git a/samples/Android.mk b/samples/Android.mk index cb6308f..6ebdbc8 100644 --- a/samples/Android.mk +++ b/samples/Android.mk @@ -19,6 +19,7 @@ LOCAL_MODULE:=amber_ndk LOCAL_CPP_EXTENSION := .cc .cpp .cxx LOCAL_SRC_FILES:= \ amber.cc \ + android_main.cc \ config_helper.cc \ config_helper_vulkan.cc \ log.cc \ @@ -30,5 +31,8 @@ LOCAL_LDLIBS:=-landroid -lvulkan -llog LOCAL_CXXFLAGS:=-std=c++11 -fno-exceptions -fno-rtti -Werror -Wno-unknown-pragmas -DAMBER_ENGINE_VULKAN=1 -DAMBER_ENABLE_LODEPNG=1 LOCAL_STATIC_LIBRARIES:=amber lodepng include $(BUILD_EXECUTABLE) +LOCAL_MODULE:=amber_ndk_sharedlib +LOCAL_MODULE_FILENAME:=libamber_ndk +include $(BUILD_SHARED_LIBRARY) include $(LOCAL_PATH)/../Android.mk diff --git a/samples/android_main.cc b/samples/android_main.cc new file mode 100644 index 0000000..cc82335 --- /dev/null +++ b/samples/android_main.cc @@ -0,0 +1,45 @@ +// Copyright 2019 The Amber Authors. +// +// 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 <jni.h> + +#include <sstream> +#include <string> +#include <vector> + +extern int main(int argc, const char** argv); + +extern "C" JNIEXPORT JNICALL int Java_com_google_amber_Amber_androidMain( + JNIEnv* env, + jobject, + jstring args_jstring) { + // Redirect std output to a file + freopen("/sdcard/amberlog.txt", "w", stdout); + freopen("/sdcard/amberlog.txt", "a", stderr); + + std::string args(env->GetStringUTFChars(args_jstring, NULL)); + + // Parse argument string and add -d by default + std::stringstream ss(args); + std::vector<std::string> argv_string{std::istream_iterator<std::string>{ss}, + std::istream_iterator<std::string>{}}; + std::vector<const char*> argv; + argv.push_back("amber"); + argv.push_back("-d"); + + for (auto s : argv_string) + argv.push_back(s.c_str()); + + return main(argv.size(), argv.data()); +} |