1
+ // Copyright 2020 Google LLC
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ buildscript {
16
+ repositories {
17
+ google()
18
+ jcenter()
19
+ }
20
+ dependencies {
21
+ classpath ' com.android.tools.build:gradle:3.2.1'
22
+ classpath ' com.google.gms:google-services:4.2.0'
23
+ // This uses Flatbuffers at 1.9 because the 1.10 version added a feature
24
+ // that requires using a newer version of the JDK and at least Android N.
25
+ // This has already been fixed at head, but a tagged release is not yet
26
+ // available with that fix.
27
+ classpath ' com.google.flatbuffers:flatbuffers-java:1.9.0'
28
+ }
29
+ }
30
+
31
+ allprojects {
32
+ repositories {
33
+ google()
34
+ jcenter()
35
+ }
36
+ }
37
+
38
+ apply plugin : ' com.android.library'
39
+
40
+ android {
41
+ compileSdkVersion 28
42
+ buildToolsVersion ' 28.0.3'
43
+
44
+ sourceSets {
45
+ main {
46
+ manifest. srcFile ' ../android_build_files/AndroidManifest.xml'
47
+ java {
48
+ srcDirs = [' ../TickerExample.java' ,
49
+ " $buildDir /flatbuffer_generated" ]
50
+ }
51
+ }
52
+ }
53
+
54
+ defaultConfig {
55
+ // This is the platform API where NativeActivity was introduced.
56
+ minSdkVersion 9
57
+ targetSdkVersion 28
58
+ versionCode 1
59
+ versionName " 1.0"
60
+
61
+ buildTypes {
62
+ release {
63
+ minifyEnabled false
64
+ }
65
+ }
66
+ }
67
+
68
+ lintOptions {
69
+ abortOnError false
70
+ }
71
+ }
72
+
73
+ dependencies {
74
+ implementation ' com.google.flatbuffers:flatbuffers-java:1.9.0'
75
+ }
76
+
77
+ afterEvaluate { project ->
78
+ // Define a Task that will add a Flatbuffers dependency, downloading
79
+ // the source from GitHub if needed.
80
+ task generateFlatbufferFiles {
81
+ // Locate or download flatbuffers.
82
+ def flatbuffersDir = " $buildDir /flatbuffers"
83
+ def flatbuffersFolder = new File (flatbuffersDir)
84
+ if (! flatbuffersFolder. exists()) {
85
+ exec {
86
+ executable ' git'
87
+ args ' clone' ,
88
+ ' --branch' ,
89
+ ' v1.10.0' ,
90
+ ' --depth' ,
91
+ ' 1' ,
92
+ ' https://github.com/google/flatbuffers.git' ,
93
+ flatbuffersDir
94
+ }
95
+ }
96
+
97
+ // Locate or build flatc.
98
+ String flatcDirPath = " $flatbuffersDir /flatc_build"
99
+ def flatcDir = new File (flatcDirPath)
100
+ flatcDir. mkdir()
101
+
102
+ String flatcExecDirPath = flatcDirPath
103
+ String flatcFilename = " flatc"
104
+ if (org.gradle.internal.os.OperatingSystem . current(). isWindows()) {
105
+ flatcFilename + = " .exe"
106
+ flatcExecDirPath = " $flatcDirPath /Debug"
107
+ }
108
+
109
+ def flatcExecDir = new File (flatcExecDirPath)
110
+
111
+ def flatcExec = new File (flatcExecDir, flatcFilename)
112
+ if (! flatcExec. exists()) {
113
+ exec {
114
+ executable ' cmake'
115
+ args ' ..'
116
+ workingDir " ${ flatcDir.getPath()} "
117
+ }
118
+ exec {
119
+ executable ' cmake'
120
+ args ' --build' ,
121
+ ' .' ,
122
+ ' --target' ,
123
+ ' flatc'
124
+ workingDir " ${ flatcDir.getPath()} "
125
+ }
126
+ }
127
+
128
+ // Generate the java files from the schema files.
129
+ def schemaFile = new File (" ./testdata_config_android.fbs" )
130
+ exec {
131
+ executable " ${ flatcExec.getPath()} "
132
+ args ' --java' ,
133
+ ' -o' ,
134
+ " $buildDir /flatbuffer_generated" ,
135
+ " ${ schemaFile.getPath()} "
136
+ }
137
+ }
138
+ preBuild. dependsOn generateFlatbufferFiles
139
+ }
140
+
141
+ apply from : " $rootDir /android_build_files/extract_and_dex.gradle"
142
+ extractAndDexAarFile(' testing' )
0 commit comments