diff options
author | Paul Thomson <paulthomson@users.noreply.github.com> | 2021-09-28 13:28:55 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-28 14:28:55 +0100 |
commit | 93e89eed2c22deb62b2d0a46a2e376c5132775cd (patch) | |
tree | 638dac80320509529d7e7be043a92e28a7b17194 /samples | |
parent | 6b3fcb0353533d1236035c4aa3b587be5d8b37cd (diff) | |
download | amber-93e89eed2c22deb62b2d0a46a2e376c5132775cd.tar.gz |
Update and improve android_gradle (#965)
* Update CMakeLists.txt files so we can build libamber_ndk.so for
Android via CMake.
* `android_gradle/`:
* Update Gradle version, settings, and build files to match the latest
Android sample. Importantly, this removes the use of jcenter and
bintray repositories, which were shut down.
* Specify NDK version so that Gradle can install required native build
tools automatically.
* Define externalNativeBuild so Gradle can perform the Android CMake
build automatically.
* Replace `main` with `android_main` when building the Amber tool as a
library for Android to avoid compiler warnings, and rename other
Android-related symbols to avoid confusion.
Fixes #964
Diffstat (limited to 'samples')
-rw-r--r-- | samples/Android.mk | 4 | ||||
-rw-r--r-- | samples/CMakeLists.txt | 8 | ||||
-rw-r--r-- | samples/amber.cc | 8 | ||||
-rw-r--r-- | samples/android_helper.cc (renamed from samples/android_main.cc) | 18 |
4 files changed, 31 insertions, 7 deletions
diff --git a/samples/Android.mk b/samples/Android.mk index 6ebdbc8..1428ead 100644 --- a/samples/Android.mk +++ b/samples/Android.mk @@ -19,7 +19,6 @@ 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 \ @@ -31,8 +30,11 @@ 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 +LOCAL_SRC_FILES+=android_helper.cc +LOCAL_CXXFLAGS+=-DAMBER_ANDROID_MAIN=1 include $(BUILD_SHARED_LIBRARY) include $(LOCAL_PATH)/../Android.mk diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index 3fa1882..1e91c4d 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -74,3 +74,11 @@ target_include_directories(image_diff PRIVATE "${CMAKE_BINARY_DIR}") target_link_libraries(image_diff libamber "lodepng") amber_default_compile_options(image_diff) set_target_properties(image_diff PROPERTIES OUTPUT_NAME "image_diff") + +if (ANDROID) + add_library(amber_ndk SHARED android_helper.cc ${AMBER_SOURCES}) + target_include_directories(amber_ndk PRIVATE "${CMAKE_BINARY_DIR}") + target_link_libraries(amber_ndk libamber ${AMBER_EXTRA_LIBS}) + amber_default_compile_options(amber_ndk) + target_compile_definitions(amber_ndk PRIVATE AMBER_ANDROID_MAIN=1) +endif() diff --git a/samples/amber.cc b/samples/amber.cc index d037ba4..5973dba 100644 --- a/samples/amber.cc +++ b/samples/amber.cc @@ -447,7 +447,15 @@ std::string disassemble(const std::string& env, } // namespace +#ifdef AMBER_ANDROID_MAIN +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wmissing-prototypes" +#pragma ide diagnostic ignored "OCUnusedGlobalDeclarationInspection" +int android_main(int argc, const char** argv) { +#pragma clang diagnostic pop +#else int main(int argc, const char** argv) { +#endif std::vector<std::string> args(argv, argv + argc); Options options; SampleDelegate delegate; diff --git a/samples/android_main.cc b/samples/android_helper.cc index b24a9bb..7da69ad 100644 --- a/samples/android_main.cc +++ b/samples/android_helper.cc @@ -18,16 +18,20 @@ #include <string> #include <vector> -extern int main(int argc, const char** argv); +extern int android_main(int argc, const char** argv); -extern "C" JNIEXPORT JNICALL int Java_com_google_amber_Amber_androidMain( +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wmissing-prototypes" +#pragma ide diagnostic ignored "OCUnusedGlobalDeclarationInspection" + +extern "C" JNIEXPORT JNICALL int Java_com_google_amber_Amber_androidHelper( JNIEnv* env, jobject, jobjectArray args, jstring stdoutFile, jstring stderrFile) { - const char* stdout_file_cstr = env->GetStringUTFChars(stdoutFile, NULL); - const char* stderr_file_cstr = env->GetStringUTFChars(stderrFile, NULL); + const char* stdout_file_cstr = env->GetStringUTFChars(stdoutFile, nullptr); + const char* stderr_file_cstr = env->GetStringUTFChars(stderrFile, nullptr); // Redirect std output to a file freopen(stdout_file_cstr, "w", stdout); @@ -43,7 +47,7 @@ extern "C" JNIEXPORT JNICALL int Java_com_google_amber_Amber_androidMain( for (jsize i = 0; i < arg_count; i++) { jstring js = static_cast<jstring>(env->GetObjectArrayElement(args, i)); - const char* arg_cstr = env->GetStringUTFChars(js, NULL); + const char* arg_cstr = env->GetStringUTFChars(js, nullptr); argv_string.push_back(arg_cstr); env->ReleaseStringUTFChars(js, arg_cstr); } @@ -53,5 +57,7 @@ extern "C" JNIEXPORT JNICALL int Java_com_google_amber_Amber_androidMain( for (const std::string& arg : argv_string) argv.push_back(arg.c_str()); - return main(argv.size(), argv.data()); + return android_main(static_cast<int>(argv.size()), argv.data()); } + +#pragma clang diagnostic pop |