aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Thomson <paulthomson@users.noreply.github.com>2021-09-28 13:28:55 +0000
committerGitHub <noreply@github.com>2021-09-28 14:28:55 +0100
commit93e89eed2c22deb62b2d0a46a2e376c5132775cd (patch)
tree638dac80320509529d7e7be043a92e28a7b17194
parent6b3fcb0353533d1236035c4aa3b587be5d8b37cd (diff)
downloadamber-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
-rw-r--r--.gitignore4
-rw-r--r--CMakeLists.txt4
-rw-r--r--android_gradle/app/build.gradle44
-rw-r--r--android_gradle/app/src/androidTest/java/com/google/amber/AmberLauncher.java2
-rw-r--r--android_gradle/app/src/main/AndroidManifest.xml1
-rw-r--r--android_gradle/app/src/main/java/com/google/amber/Amber.java2
-rw-r--r--android_gradle/build.gradle13
-rw-r--r--android_gradle/gradle.properties2
-rw-r--r--android_gradle/gradle/wrapper/gradle-wrapper.jarbin54329 -> 59203 bytes
-rw-r--r--android_gradle/gradle/wrapper/gradle-wrapper.properties6
-rw-r--r--android_gradle/settings.gradle7
-rw-r--r--samples/Android.mk4
-rw-r--r--samples/CMakeLists.txt8
-rw-r--r--samples/amber.cc8
-rw-r--r--samples/android_helper.cc (renamed from samples/android_main.cc)18
-rw-r--r--third_party/CMakeLists.txt38
16 files changed, 101 insertions, 60 deletions
diff --git a/.gitignore b/.gitignore
index 8c314d9..e847034 100644
--- a/.gitignore
+++ b/.gitignore
@@ -26,5 +26,5 @@ third_party/robin-hood-hashing
[._]*.s[a-w][a-z]
# C-Lion
-.idea
-cmake-build-debug
+.idea/
+cmake-build-*/
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9f65d5f..c064649 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -202,7 +202,6 @@ endif()
function(amber_default_compile_options TARGET)
if (${COMPILER_IS_LIKE_GNU})
target_compile_options(${TARGET} PRIVATE
- -std=c++11
-fno-exceptions
-fvisibility=hidden
-Wall
@@ -230,7 +229,6 @@ function(amber_default_compile_options TARGET)
endif()
if (MSVC)
- # Specify /EHs for exception handling.
target_compile_options(${TARGET} PRIVATE
/bigobj
/EHsc
@@ -266,6 +264,6 @@ endfunction()
add_subdirectory(third_party)
add_subdirectory(src)
-if (${AMBER_ENABLE_SAMPLES} AND NOT ANDROID)
+if (${AMBER_ENABLE_SAMPLES})
add_subdirectory(samples)
endif()
diff --git a/android_gradle/app/build.gradle b/android_gradle/app/build.gradle
index 40c4c54..b756f6b 100644
--- a/android_gradle/app/build.gradle
+++ b/android_gradle/app/build.gradle
@@ -1,26 +1,37 @@
-apply plugin: 'com.android.application'
+plugins {
+ id 'com.android.application'
+}
android {
- compileSdkVersion 29
- buildToolsVersion "29.0.2"
+ compileSdk 30
+ buildToolsVersion "30.0.2"
+ ndkVersion "21.4.7075529"
defaultConfig {
applicationId "com.google.amber"
minSdkVersion 24
- targetSdkVersion 29
+ targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
+
+ externalNativeBuild {
+ cmake {
+ arguments "-DAMBER_USE_LOCAL_VULKAN=1"
+ targets "amber_ndk"
+ }
+ }
}
- sourceSets {
- androidTest.manifest.srcFile "src/androidTest/AndroidManifest.xml"
+ externalNativeBuild {
+ cmake {
+ path "../../CMakeLists.txt"
+ }
}
- dependencies {
- androidTestImplementation 'androidx.test:runner:1.1.0'
- androidTestImplementation 'androidx.test:rules:1.1.0'
+ sourceSets {
+ androidTest.manifest.srcFile "src/androidTest/AndroidManifest.xml"
}
buildTypes {
@@ -29,6 +40,10 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt')
}
}
+ compileOptions {
+ sourceCompatibility JavaVersion.VERSION_1_8
+ targetCompatibility JavaVersion.VERSION_1_8
+ }
sourceSets {
main {
@@ -41,9 +56,10 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
- implementation 'androidx.appcompat:appcompat:1.1.0'
- implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
- testImplementation 'junit:junit:4.12'
- androidTestImplementation 'androidx.test.ext:junit:1.1.1'
- androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
+ implementation 'androidx.appcompat:appcompat:1.3.1'
+ implementation 'com.google.android.material:material:1.4.0'
+ implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
+ testImplementation 'junit:junit:4.13.2'
+ androidTestImplementation 'androidx.test.ext:junit:1.1.3'
+ androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
diff --git a/android_gradle/app/src/androidTest/java/com/google/amber/AmberLauncher.java b/android_gradle/app/src/androidTest/java/com/google/amber/AmberLauncher.java
index 4864843..ad92154 100644
--- a/android_gradle/app/src/androidTest/java/com/google/amber/AmberLauncher.java
+++ b/android_gradle/app/src/androidTest/java/com/google/amber/AmberLauncher.java
@@ -54,7 +54,7 @@ public class AmberLauncher {
String stdout_file = args.getString("stdout", new File(outputDir, "amber_stdout.txt").toString());
String stderr_file = args.getString("stderr", new File(outputDir, "amber_stderr.txt").toString());
- int res = Amber.androidMain(args_list.toArray(new String[0]), stdout_file, stderr_file);
+ int res = Amber.androidHelper(args_list.toArray(new String[0]), stdout_file, stderr_file);
// If the process crashes during the above call or we call System.exit below, the output
// from `adb shell am instrument ...` will be:
diff --git a/android_gradle/app/src/main/AndroidManifest.xml b/android_gradle/app/src/main/AndroidManifest.xml
index 0ab9856..c74c390 100644
--- a/android_gradle/app/src/main/AndroidManifest.xml
+++ b/android_gradle/app/src/main/AndroidManifest.xml
@@ -4,6 +4,7 @@
<application
android:allowBackup="true"
+ android:fullBackupOnly="true"
android:label="Amber"
android:supportsRtl="true">
<meta-data
diff --git a/android_gradle/app/src/main/java/com/google/amber/Amber.java b/android_gradle/app/src/main/java/com/google/amber/Amber.java
index 8319ccf..008c528 100644
--- a/android_gradle/app/src/main/java/com/google/amber/Amber.java
+++ b/android_gradle/app/src/main/java/com/google/amber/Amber.java
@@ -19,5 +19,5 @@ public class Amber {
System.loadLibrary("amber_ndk");
}
- public static native int androidMain(String[] args, String stdout_file, String stderr_file);
+ public static native int androidHelper(String[] args, String stdout_file, String stderr_file);
}
diff --git a/android_gradle/build.gradle b/android_gradle/build.gradle
index 82c93bf..d340082 100644
--- a/android_gradle/build.gradle
+++ b/android_gradle/build.gradle
@@ -4,25 +4,16 @@ buildscript {
repositories {
google()
- jcenter()
- maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' }
+ mavenCentral()
}
dependencies {
- classpath 'com.android.tools.build:gradle:4.0.0-alpha04'
+ classpath 'com.android.tools.build:gradle:7.0.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
-allprojects {
- repositories {
- google()
- jcenter()
- maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' }
- }
-}
-
task clean(type: Delete) {
delete rootProject.buildDir
}
diff --git a/android_gradle/gradle.properties b/android_gradle/gradle.properties
index 199d16e..4941ecd 100644
--- a/android_gradle/gradle.properties
+++ b/android_gradle/gradle.properties
@@ -6,7 +6,7 @@
# 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=-Xmx1536m
+org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
# 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
diff --git a/android_gradle/gradle/wrapper/gradle-wrapper.jar b/android_gradle/gradle/wrapper/gradle-wrapper.jar
index f6b961f..e708b1c 100644
--- a/android_gradle/gradle/wrapper/gradle-wrapper.jar
+++ b/android_gradle/gradle/wrapper/gradle-wrapper.jar
Binary files differ
diff --git a/android_gradle/gradle/wrapper/gradle-wrapper.properties b/android_gradle/gradle/wrapper/gradle-wrapper.properties
index 421d5b6..e81b594 100644
--- a/android_gradle/gradle/wrapper/gradle-wrapper.properties
+++ b/android_gradle/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Mon Dec 09 14:37:37 GMT 2019
+#Sat Sep 25 16:43:12 BST 2021
distributionBase=GRADLE_USER_HOME
+distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
distributionPath=wrapper/dists
-zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-6.0-rc-1-all.zip
+zipStoreBase=GRADLE_USER_HOME
diff --git a/android_gradle/settings.gradle b/android_gradle/settings.gradle
index 9a979bb..2c4357f 100644
--- a/android_gradle/settings.gradle
+++ b/android_gradle/settings.gradle
@@ -1,2 +1,9 @@
+dependencyResolutionManagement {
+ repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
+ repositories {
+ google()
+ mavenCentral()
+ }
+}
rootProject.name='Amber'
include ':app'
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
diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt
index 897c666..410dc02 100644
--- a/third_party/CMakeLists.txt
+++ b/third_party/CMakeLists.txt
@@ -52,24 +52,28 @@ endif()
if (${AMBER_USE_LOCAL_VULKAN})
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/vulkan-headers)
- set(BUILD_TESTS FALSE)
-
- # The vulkan-loader CMake file assumes that directory exists if
- # Wayland support is to be built.
- if(NOT EXISTS ${WAYLAND_CLIENT_INCLUDE_DIR})
- message(STATUS "Amber: Disabling Wayland support in Vulkan-Loader")
- set(BUILD_WSI_WAYLAND_SUPPORT OFF CACHE BOOL "" FORCE)
- endif()
- message(STATUS "Amber: Disabling X11 support in Vulkan-Loader")
- set(BUILD_WSI_XLIB_SUPPORT OFF CACHE BOOL "" FORCE)
-
- set(ROBIN_HOOD_HASHING_INSTALL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/robin-hood-hashing" CACHE STRING "" FORCE)
-
- add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/vulkan-loader)
- if (MSVC)
- option(BUILD_WERROR "Treat compiler warnings as errors" OFF)
+ # Skip adding the validation layers and the Vulkan loader on Android.
+ if (NOT ANDROID)
+
+ set(BUILD_TESTS FALSE)
+
+ # The vulkan-loader CMake file assumes that directory exists if
+ # Wayland support is to be built.
+ if(NOT EXISTS ${WAYLAND_CLIENT_INCLUDE_DIR})
+ message(STATUS "Amber: Disabling Wayland support in Vulkan-Loader")
+ set(BUILD_WSI_WAYLAND_SUPPORT OFF CACHE BOOL "" FORCE)
+ endif()
+ message(STATUS "Amber: Disabling X11 support in Vulkan-Loader")
+ set(BUILD_WSI_XLIB_SUPPORT OFF CACHE BOOL "" FORCE)
+
+ set(ROBIN_HOOD_HASHING_INSTALL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/robin-hood-hashing" CACHE STRING "" FORCE)
+
+ add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/vulkan-loader)
+ if (MSVC)
+ option(BUILD_WERROR "Treat compiler warnings as errors" OFF)
+ endif()
+ add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/vulkan-validationlayers)
endif()
- add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/vulkan-validationlayers)
endif()
if (${AMBER_ENABLE_VK_DEBUGGING})