Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 1 | apply plugin: 'com.android.application' |
| 2 | apply plugin: 'kotlin-android' |
| 3 | apply plugin: 'kotlin-android-extensions' |
| 4 | |
| 5 | android { |
| 6 | compileSdkVersion 30 |
| 7 | buildToolsVersion "30.0.2" |
| 8 | |
| 9 | defaultConfig { |
| 10 | applicationId "com.flatbuffers.app" |
Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 11 | minSdkVersion 26 |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 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 | |
Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 21 | 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 Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 33 | 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 Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 48 | 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 Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 62 | def commandLineArgs = ['flatc', '-o', outputCppDir, '--cpp'] |
| 63 | fbsFiles.forEach{ |
| 64 | commandLineArgs.add(it.path) |
| 65 | } |
Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 66 | |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 67 | commandLine commandLineArgs |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 68 | |
| 69 | doFirst { |
| 70 | delete "$outputCppDir/" |
| 71 | mkdir "$outputCppDir/" |
| 72 | } |
Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 73 | |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 74 | doLast { |
Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 75 | if (executionResult.get().exitValue != 0) { |
| 76 | throw new GradleException("flatc failed with: ${executionResult.get().toString()}") |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 77 | } |
| 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 Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 89 | |
| 90 | setErrorOutput(errorOutput) |
| 91 | setStandardOutput(standardOutput) |
| 92 | |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 93 | def commandLineArgs = ['flatc', '-o', outputKotlinDir, '--kotlin'] |
| 94 | fbsFiles.forEach{ |
| 95 | commandLineArgs.add(it.path) |
| 96 | } |
| 97 | commandLine commandLineArgs |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 98 | |
| 99 | doFirst { |
| 100 | delete "$outputKotlinDir/" |
| 101 | mkdir "$outputKotlinDir/" |
| 102 | } |
| 103 | doLast { |
Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 104 | if (executionResult.get().exitValue != 0) { |
| 105 | throw new GradleException("flatc failed with: ${executionResult.get().toString()}") |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 106 | } |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | afterEvaluate { |
Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 111 | tasks.named("preBuild") { |
| 112 | dependsOn(generateFbsKotlin) |
| 113 | dependsOn(generateFbsCpp) |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 114 | } |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | dependencies { |
| 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 Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 123 | |
| 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 Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 126 | |
| 127 | } |