...
1apply plugin: 'com.android.application'
2apply plugin: 'kotlin-android'
3
4android {
5 compileSdk 33
6
7 defaultConfig {
8 applicationId "com.flatbuffers.app"
9 minSdkVersion 26
10 targetSdkVersion 33
11 versionCode 1
12 versionName "1.0"
13
14 compileOptions {
15 sourceCompatibility JavaVersion.VERSION_1_8
16 targetCompatibility JavaVersion.VERSION_1_8
17 }
18
19 sourceSets {
20 main {
21 java {
22 srcDir '../../java/src/main/java/'
23 }
24 }
25 }
26
27 ndk {
28 abiFilters 'arm64-v8a', 'armeabi-v7a'
29 }
30
31 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
32 externalNativeBuild {
33 cmake {
34 arguments "-DFLATBUFFERS_SRC=${rootProject.projectDir}/.."
35 }
36 }
37 }
38
39 buildTypes {
40 release {
41 minifyEnabled false
42 proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
43 }
44 }
45
46 externalNativeBuild {
47 cmake {
48 path "src/main/cpp/CMakeLists.txt"
49 }
50 }
51
52 task generateFbsCpp(type: Exec) {
53 def inputDir = file("$projectDir/src/main/fbs")
54 def outputCppDir = file("$projectDir/src/main/cpp/generated/")
55 def fbsFiles = layout.files { file(inputDir).listFiles() }.filter { File f -> f.name.endsWith(".fbs") }.toList()
56 ignoreExitValue(true)
57
58 standardOutput = new ByteArrayOutputStream()
59 errorOutput = new ByteArrayOutputStream()
60 def commandLineArgs = ['flatc', '-o', outputCppDir, '--cpp']
61 fbsFiles.forEach{
62 commandLineArgs.add(it.path)
63 }
64
65 commandLine commandLineArgs
66
67 doFirst {
68 delete "$outputCppDir/"
69 mkdir "$outputCppDir/"
70 }
71
72 doLast {
73 if (executionResult.get().exitValue != 0) {
74 throw new GradleException("flatc failed with: ${executionResult.get().toString()}")
75 }
76 }
77 }
78
79 task generateFbsKotlin(type: Exec) {
80 def inputDir = file("$projectDir/src/main/fbs")
81 def outputKotlinDir = file("$projectDir/src/main/java/generated/")
82 def fbsFiles = layout.files { file(inputDir).listFiles() }.filter { File f -> f.name.endsWith(".fbs") }.toList()
83 ignoreExitValue(true)
84
85 standardOutput = new ByteArrayOutputStream()
86 errorOutput = new ByteArrayOutputStream()
87
88 setErrorOutput(errorOutput)
89 setStandardOutput(standardOutput)
90
91 def commandLineArgs = ['flatc', '-o', outputKotlinDir, '--kotlin']
92 fbsFiles.forEach{
93 commandLineArgs.add(it.path)
94 }
95 commandLine commandLineArgs
96
97 doFirst {
98 delete "$outputKotlinDir/"
99 mkdir "$outputKotlinDir/"
100 }
101 doLast {
102 if (executionResult.get().exitValue != 0) {
103 throw new GradleException("flatc failed with: ${executionResult.get().toString()}")
104 }
105 }
106 }
107
108 afterEvaluate {
109 tasks.named("preBuild") {
110 dependsOn(generateFbsKotlin)
111 dependsOn(generateFbsCpp)
112 }
113 }
114 namespace 'com.flatbuffers.app'
115}
116
117dependencies {
118 implementation fileTree(dir: "libs", include: ["*.jar"])
119 implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
120 implementation 'androidx.appcompat:appcompat:1.6.1'
121
122 // If you using java runtime you can add its dependency as the example below
123 // implementation 'com.google.flatbuffers:flatbuffers-java:$latest_version'
124
125}
View as plain text