blob: 1b035bab4b83f928b82807debd5d4455746541b6 [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"
Austin Schuh2dd86a92022-09-14 21:19:23 -070011 minSdkVersion 26
Austin Schuh272c6132020-11-14 16:37:52 -080012 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
Austin Schuh2dd86a92022-09-14 21:19:23 -070021 sourceSets {
22 main {
23 java {
24 srcDir '../../java/src/main/java/'
25 }
26 }
27 }
28
29 ndk {
30 abiFilters 'arm64-v8a', 'armeabi-v7a'
31 }
32
Austin Schuh272c6132020-11-14 16:37:52 -080033 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
34 externalNativeBuild {
35 cmake {
36 arguments "-DFLATBUFFERS_SRC=${rootProject.projectDir}/.."
37 }
38 }
39 }
40
41 buildTypes {
42 release {
43 minifyEnabled false
44 proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
45 }
46 }
47
Austin Schuh272c6132020-11-14 16:37:52 -080048 externalNativeBuild {
49 cmake {
50 path "src/main/cpp/CMakeLists.txt"
51 }
52 }
53
54 task generateFbsCpp(type: Exec) {
55 def inputDir = file("$projectDir/src/main/fbs")
56 def outputCppDir = file("$projectDir/src/main/cpp/generated/")
57 def fbsFiles = layout.files { file(inputDir).listFiles() }.filter { File f -> f.name.endsWith(".fbs") }.toList()
58 ignoreExitValue(true)
59
60 standardOutput = new ByteArrayOutputStream()
61 errorOutput = new ByteArrayOutputStream()
James Kuszmaul8e62b022022-03-22 09:33:25 -070062 def commandLineArgs = ['flatc', '-o', outputCppDir, '--cpp']
63 fbsFiles.forEach{
64 commandLineArgs.add(it.path)
65 }
Austin Schuh2dd86a92022-09-14 21:19:23 -070066
James Kuszmaul8e62b022022-03-22 09:33:25 -070067 commandLine commandLineArgs
Austin Schuh272c6132020-11-14 16:37:52 -080068
69 doFirst {
70 delete "$outputCppDir/"
71 mkdir "$outputCppDir/"
72 }
Austin Schuh2dd86a92022-09-14 21:19:23 -070073
Austin Schuh272c6132020-11-14 16:37:52 -080074 doLast {
Austin Schuh2dd86a92022-09-14 21:19:23 -070075 if (executionResult.get().exitValue != 0) {
76 throw new GradleException("flatc failed with: ${executionResult.get().toString()}")
Austin Schuh272c6132020-11-14 16:37:52 -080077 }
78 }
79 }
80
81 task generateFbsKotlin(type: Exec) {
82 def inputDir = file("$projectDir/src/main/fbs")
83 def outputKotlinDir = file("$projectDir/src/main/java/generated/")
84 def fbsFiles = layout.files { file(inputDir).listFiles() }.filter { File f -> f.name.endsWith(".fbs") }.toList()
85 ignoreExitValue(true)
86
87 standardOutput = new ByteArrayOutputStream()
88 errorOutput = new ByteArrayOutputStream()
Austin Schuh2dd86a92022-09-14 21:19:23 -070089
90 setErrorOutput(errorOutput)
91 setStandardOutput(standardOutput)
92
James Kuszmaul8e62b022022-03-22 09:33:25 -070093 def commandLineArgs = ['flatc', '-o', outputKotlinDir, '--kotlin']
94 fbsFiles.forEach{
95 commandLineArgs.add(it.path)
96 }
97 commandLine commandLineArgs
Austin Schuh272c6132020-11-14 16:37:52 -080098
99 doFirst {
100 delete "$outputKotlinDir/"
101 mkdir "$outputKotlinDir/"
102 }
103 doLast {
Austin Schuh2dd86a92022-09-14 21:19:23 -0700104 if (executionResult.get().exitValue != 0) {
105 throw new GradleException("flatc failed with: ${executionResult.get().toString()}")
Austin Schuh272c6132020-11-14 16:37:52 -0800106 }
107 }
108 }
109
110 afterEvaluate {
Austin Schuh2dd86a92022-09-14 21:19:23 -0700111 tasks.named("preBuild") {
112 dependsOn(generateFbsKotlin)
113 dependsOn(generateFbsCpp)
Austin Schuh272c6132020-11-14 16:37:52 -0800114 }
115 }
116}
117
118dependencies {
119 implementation fileTree(dir: "libs", include: ["*.jar"])
120 implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
121 implementation 'androidx.core:core-ktx:1.3.2'
122 implementation 'androidx.appcompat:appcompat:1.2.0'
Austin Schuh2dd86a92022-09-14 21:19:23 -0700123
124 // If you using java runtime you can add its dependency as the example below
125 // implementation 'com.google.flatbuffers:flatbuffers-java:$latest_version'
Austin Schuh272c6132020-11-14 16:37:52 -0800126
127}