blob: dba6624f25d4dc44bd4e9a66c5c3e67fb8cc2b3f [file] [log] [blame]
Austin Schuh272c6132020-11-14 16:37:52 -08001apply plugin: 'com.android.application'
2apply plugin: 'kotlin-android'
3apply plugin: 'kotlin-android-extensions'
4
5android {
6 compileSdkVersion 30
7 buildToolsVersion "30.0.2"
8
9 defaultConfig {
10 applicationId "com.flatbuffers.app"
11 minSdkVersion 16
12 targetSdkVersion 30
13 versionCode 1
14 versionName "1.0"
15
16 compileOptions {
17 sourceCompatibility JavaVersion.VERSION_1_8
18 targetCompatibility JavaVersion.VERSION_1_8
19 }
20
21 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
22 externalNativeBuild {
23 cmake {
24 arguments "-DFLATBUFFERS_SRC=${rootProject.projectDir}/.."
25 }
26 }
27 }
28
29 buildTypes {
30 release {
31 minifyEnabled false
32 proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
33 }
34 }
35
36 ndkVersion "21.3.6528147"
37 externalNativeBuild {
38 cmake {
39 path "src/main/cpp/CMakeLists.txt"
40 }
41 }
42
43 task generateFbsCpp(type: Exec) {
44 def inputDir = file("$projectDir/src/main/fbs")
45 def outputCppDir = file("$projectDir/src/main/cpp/generated/")
46 def fbsFiles = layout.files { file(inputDir).listFiles() }.filter { File f -> f.name.endsWith(".fbs") }.toList()
47 ignoreExitValue(true)
48
49 standardOutput = new ByteArrayOutputStream()
50 errorOutput = new ByteArrayOutputStream()
James Kuszmaul8e62b022022-03-22 09:33:25 -070051 def commandLineArgs = ['flatc', '-o', outputCppDir, '--cpp']
52 fbsFiles.forEach{
53 commandLineArgs.add(it.path)
54 }
55 commandLine commandLineArgs
Austin Schuh272c6132020-11-14 16:37:52 -080056
57 doFirst {
58 delete "$outputCppDir/"
59 mkdir "$outputCppDir/"
60 }
61 doLast {
62 if (execResult.getExitValue() != 0) {
63 println(standardOutput.toString())
64 throw new GradleException("flatc command line failed")
65 }
66 }
67 }
68
69 task generateFbsKotlin(type: Exec) {
70 def inputDir = file("$projectDir/src/main/fbs")
71 def outputKotlinDir = file("$projectDir/src/main/java/generated/")
72 def fbsFiles = layout.files { file(inputDir).listFiles() }.filter { File f -> f.name.endsWith(".fbs") }.toList()
73 ignoreExitValue(true)
74
75 standardOutput = new ByteArrayOutputStream()
76 errorOutput = new ByteArrayOutputStream()
James Kuszmaul8e62b022022-03-22 09:33:25 -070077 def commandLineArgs = ['flatc', '-o', outputKotlinDir, '--kotlin']
78 fbsFiles.forEach{
79 commandLineArgs.add(it.path)
80 }
81 commandLine commandLineArgs
Austin Schuh272c6132020-11-14 16:37:52 -080082
83 doFirst {
84 delete "$outputKotlinDir/"
85 mkdir "$outputKotlinDir/"
86 }
87 doLast {
88 if (execResult.getExitValue() != 0) {
89 println(standardOutput.toString())
90 throw new GradleException("flatc command line failed")
91 }
92 }
93 }
94
95 afterEvaluate {
96 android.applicationVariants.all { variant ->
97 variant.javaCompiler.dependsOn(generateFbsKotlin)
98 variant.javaCompiler.dependsOn(generateFbsCpp)
99 }
100 }
101
102 flavorDimensions "stl-variant"
103 productFlavors {
Austin Schuh272c6132020-11-14 16:37:52 -0800104 gnustl {
105 dimension "stl-variant"
106 applicationIdSuffix ".gnustl"
107 versionNameSuffix "-gnustl"
108 externalNativeBuild {
109 ndkBuild {
110 arguments "APP_STL=gnustl_static"
111 }
112 }
113 }
114 libcpp {
115 dimension "stl-variant"
116 applicationIdSuffix ".libcpp"
117 versionNameSuffix "-libcpp"
118 externalNativeBuild {
119 ndkBuild {
120 arguments "APP_STL=c++_static"
121 }
122 }
123 }
124 }
125}
126
127dependencies {
128 implementation fileTree(dir: "libs", include: ["*.jar"])
129 implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
130 implementation 'androidx.core:core-ktx:1.3.2'
131 implementation 'androidx.appcompat:appcompat:1.2.0'
James Kuszmaul8e62b022022-03-22 09:33:25 -0700132 implementation 'com.google.flatbuffers:flatbuffers-java:2.0.0'
Austin Schuh272c6132020-11-14 16:37:52 -0800133
134}