Files
filament/android/build.gradle
2020-05-28 14:05:20 -07:00

169 lines
4.8 KiB
Groovy

// This script accepts the following parameters:
//
// filament_dist_dir
// Path to the Filament distribution/install directory for Android
// (produced by make/ninja install). This directory must contain lib/arm64-v8a/ etc.
//
// filament_tools_dir
// Path to the Filament distribution/install directory for desktop.
// This directory must contain bin/matc.
//
// filament_exclude_vulkan
// When set, support for Vulkan will be excluded.
//
// filament_skip_samples
// Exclude samples from the project. Useful to speed up compilation.
//
// filament_abis
// List of supported ABIs to build as a comma separated list. Available options are:
// arm64-v8a, armeabi-v7a, x86_64, x86, all
// Defaults to all.
//
// Example:
// ./gradlew -Pfilament_dist_dir=../dist-android-release assembleRelease -Pfilament_abis=x86
buildscript {
def filamentPath = file("../out/android-release/filament").absolutePath
if (project.hasProperty("filament_dist_dir")) {
filamentPath = file(project.property("filament_dist_dir")).absolutePath
}
// Our CMake scripts require a forward-slash path for the FILAMENT_DIST_DIR
// variable, so here we convert the native path to a forward-slash path.
filamentPath = filamentPath.replace(File.separator, '/')
// Warning: changing this property does not work well with incremental builds.
def excludeVulkan = project.hasProperty("filament_exclude_vulkan")
def abis = ["arm64-v8a", "armeabi-v7a", "x86_64", "x86"]
if (project.hasProperty("filament_abis")) {
def newAbis = project.property("filament_abis").split(',')
if (!newAbis.contains("all")) {
abis = newAbis
}
}
// Our minSdkVersion is 19.
ext.versions = [
'minSdk': 19,
'targetSdk': 29,
'compileSdk': 29,
'kotlin': '1.3.72',
'buildTools': '29.0.3',
'ndk': '21.0.6113669'
]
ext.deps = [
'androidx': [
'annotations': "androidx.annotation:annotation:1.1.0",
'core': "androidx.core:core:1.1.0",
],
'kotlin': "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${versions.kotlin}"
]
dependencies {
// NOTE: Do not update to 4.0.0, there is a bug breaking our build, 4.0.1 will have a fix
classpath 'com.android.tools.build:gradle:3.6.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}"
}
ext.cmakeArgs = [
"-DANDROID_PIE=ON",
"-DANDROID_PLATFORM=21",
"-DANDROID_STL=c++_static",
"-DFILAMENT_DIST_DIR=${filamentPath}".toString(),
"-DFILAMENT_SUPPORTS_VULKAN=${excludeVulkan ? 'OFF' : 'ON'}".toString()
]
ext.cppFlags = [
"-std=c++14",
"-Wno-unused-command-line-argument",
// Required to support API levels below 23
"-Wl,--hash-style=both",
"-fno-stack-protector",
"-fno-exceptions",
"-fno-unwind-tables",
"-fno-asynchronous-unwind-tables",
"-fno-rtti",
"-ffast-math",
"-ffp-contract=fast",
"-fvisibility-inlines-hidden",
"-fvisibility=hidden",
"-fomit-frame-pointer",
"-ffunction-sections",
"-fdata-sections",
"-Wl,--gc-sections",
"-Wl,-Bsymbolic-functions",
]
ext.abis = abis
repositories {
mavenCentral()
google()
jcenter()
}
}
subprojects {
group = GROUP
version = VERSION_NAME
repositories {
mavenCentral()
google()
jcenter()
}
if (!name.startsWith("sample")) {
apply plugin: 'com.android.library'
android {
buildToolsVersion versions.buildTools
compileSdkVersion versions.compileSdk
ndkVersion versions.ndk
defaultConfig {
minSdkVersion versions.minSdk
targetSdkVersion versions.targetSdk
externalNativeBuild {
cmake {
arguments.addAll(rootProject.ext.cmakeArgs)
cppFlags.addAll(rootProject.ext.cppFlags)
}
}
ndk {
abiFilters(*rootProject.ext.abis)
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
sourceSets {
main {
jni.srcDirs "src/main/cpp"
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
}
}
gradle.taskGraph.whenReady {
gradle.taskGraph.allTasks.each {
it.onlyIf {
!it.project.ext.has('isSample') || !project.hasProperty('filament_skip_samples')
}
}
}