• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1apply 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    def commandLineArgs = ['flatc', '-o', outputCppDir, '--cpp']
52    fbsFiles.forEach{
53      commandLineArgs.add(it.path)
54    }
55    commandLine commandLineArgs
56
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()
77    def commandLineArgs = ['flatc', '-o', outputKotlinDir, '--kotlin']
78    fbsFiles.forEach{
79      commandLineArgs.add(it.path)
80    }
81    commandLine commandLineArgs
82
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 {
104    stlport {
105      dimension "stl-variant"
106      applicationIdSuffix ".stlport"
107      versionNameSuffix "-stlport"
108      externalNativeBuild {
109        ndkBuild {
110          arguments "APP_STL=stlport_static"
111        }
112      }
113    }
114    gnustl {
115      dimension "stl-variant"
116      applicationIdSuffix ".gnustl"
117      versionNameSuffix "-gnustl"
118      externalNativeBuild {
119        ndkBuild {
120          arguments "APP_STL=gnustl_static"
121        }
122      }
123    }
124    libcpp {
125      dimension "stl-variant"
126      applicationIdSuffix ".libcpp"
127      versionNameSuffix "-libcpp"
128      externalNativeBuild {
129        ndkBuild {
130          arguments "APP_STL=c++_static"
131        }
132      }
133    }
134  }
135}
136
137dependencies {
138  implementation fileTree(dir: "libs", include: ["*.jar"])
139  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
140  implementation 'androidx.core:core-ktx:1.3.2'
141  implementation 'androidx.appcompat:appcompat:1.2.0'
142  implementation 'com.google.flatbuffers:flatbuffers-java:2.0.0'
143
144}
145