blob: 3ee9ba2fd9c4c26b89fb5274d939a980248a41ef [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()
51 commandLine 'flatc', '-o', outputCppDir, '--cpp', "${fbsFiles.join(" ")}"
52
53 doFirst {
54 delete "$outputCppDir/"
55 mkdir "$outputCppDir/"
56 }
57 doLast {
58 if (execResult.getExitValue() != 0) {
59 println(standardOutput.toString())
60 throw new GradleException("flatc command line failed")
61 }
62 }
63 }
64
65 task generateFbsKotlin(type: Exec) {
66 def inputDir = file("$projectDir/src/main/fbs")
67 def outputKotlinDir = file("$projectDir/src/main/java/generated/")
68 def fbsFiles = layout.files { file(inputDir).listFiles() }.filter { File f -> f.name.endsWith(".fbs") }.toList()
69 ignoreExitValue(true)
70
71 standardOutput = new ByteArrayOutputStream()
72 errorOutput = new ByteArrayOutputStream()
73 commandLine 'flatc', '-o', outputKotlinDir, '--kotlin', "${fbsFiles.join(" ")}"
74
75 doFirst {
76 delete "$outputKotlinDir/"
77 mkdir "$outputKotlinDir/"
78 }
79 doLast {
80 if (execResult.getExitValue() != 0) {
81 println(standardOutput.toString())
82 throw new GradleException("flatc command line failed")
83 }
84 }
85 }
86
87 afterEvaluate {
88 android.applicationVariants.all { variant ->
89 variant.javaCompiler.dependsOn(generateFbsKotlin)
90 variant.javaCompiler.dependsOn(generateFbsCpp)
91 }
92 }
93
94 flavorDimensions "stl-variant"
95 productFlavors {
96 stlport {
97 dimension "stl-variant"
98 applicationIdSuffix ".stlport"
99 versionNameSuffix "-stlport"
100 externalNativeBuild {
101 ndkBuild {
102 arguments "APP_STL=stlport_static"
103 }
104 }
105 }
106 gnustl {
107 dimension "stl-variant"
108 applicationIdSuffix ".gnustl"
109 versionNameSuffix "-gnustl"
110 externalNativeBuild {
111 ndkBuild {
112 arguments "APP_STL=gnustl_static"
113 }
114 }
115 }
116 libcpp {
117 dimension "stl-variant"
118 applicationIdSuffix ".libcpp"
119 versionNameSuffix "-libcpp"
120 externalNativeBuild {
121 ndkBuild {
122 arguments "APP_STL=c++_static"
123 }
124 }
125 }
126 }
127}
128
129dependencies {
130 implementation fileTree(dir: "libs", include: ["*.jar"])
131 implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
132 implementation 'androidx.core:core-ktx:1.3.2'
133 implementation 'androidx.appcompat:appcompat:1.2.0'
134 implementation 'com.google.flatbuffers:flatbuffers-java:1.12.0'
135
136}