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 ndk { 22 abiFilters 'arm64-v8a', 'armeabi-v7a' 23 } 24 25 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 26 externalNativeBuild { 27 cmake { 28 arguments "-DFLATBUFFERS_SRC=${rootProject.projectDir}/.." 29 } 30 } 31 } 32 33 buildTypes { 34 release { 35 minifyEnabled false 36 proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 37 } 38 } 39 40 externalNativeBuild { 41 cmake { 42 path "src/main/cpp/CMakeLists.txt" 43 } 44 } 45 46 task generateFbsCpp(type: Exec) { 47 def inputDir = file("$projectDir/src/main/fbs") 48 def outputCppDir = file("$projectDir/src/main/cpp/generated/") 49 def fbsFiles = layout.files { file(inputDir).listFiles() }.filter { File f -> f.name.endsWith(".fbs") }.toList() 50 ignoreExitValue(true) 51 52 standardOutput = new ByteArrayOutputStream() 53 errorOutput = new ByteArrayOutputStream() 54 def commandLineArgs = ['flatc', '-o', outputCppDir, '--cpp'] 55 fbsFiles.forEach{ 56 commandLineArgs.add(it.path) 57 } 58 59 commandLine commandLineArgs 60 61 doFirst { 62 delete "$outputCppDir/" 63 mkdir "$outputCppDir/" 64 } 65 66 doLast { 67 if (executionResult.get().exitValue != 0) { 68 throw new GradleException("flatc failed with: ${executionResult.get().toString()}") 69 } 70 } 71 } 72 73 task generateFbsKotlin(type: Exec) { 74 def inputDir = file("$projectDir/src/main/fbs") 75 def outputKotlinDir = file("$projectDir/src/main/java/generated/") 76 def fbsFiles = layout.files { file(inputDir).listFiles() }.filter { File f -> f.name.endsWith(".fbs") }.toList() 77 ignoreExitValue(true) 78 79 standardOutput = new ByteArrayOutputStream() 80 errorOutput = new ByteArrayOutputStream() 81 82 setErrorOutput(errorOutput) 83 setStandardOutput(standardOutput) 84 85 def commandLineArgs = ['flatc', '-o', outputKotlinDir, '--kotlin'] 86 fbsFiles.forEach{ 87 commandLineArgs.add(it.path) 88 } 89 commandLine commandLineArgs 90 91 doFirst { 92 delete "$outputKotlinDir/" 93 mkdir "$outputKotlinDir/" 94 } 95 doLast { 96 if (executionResult.get().exitValue != 0) { 97 throw new GradleException("flatc failed with: ${executionResult.get().toString()}") 98 } 99 } 100 } 101 102 afterEvaluate { 103 tasks.named("preBuild") { 104 dependsOn(generateFbsKotlin) 105 dependsOn(generateFbsCpp) 106 } 107 } 108 109// flavorDimensions "stl-variant" 110// productFlavors { 111// gnustl { 112// dimension "stl-variant" 113// applicationIdSuffix ".gnustl" 114// versionNameSuffix "-gnustl" 115// externalNativeBuild { 116// ndkBuild { 117// arguments "APP_STL=gnustl_static" 118// } 119// } 120// } 121// libcpp { 122// dimension "stl-variant" 123// applicationIdSuffix ".libcpp" 124// versionNameSuffix "-libcpp" 125// externalNativeBuild { 126// ndkBuild { 127// arguments "APP_STL=c++_static" 128// } 129// } 130// } 131// } 132} 133 134dependencies { 135 implementation fileTree(dir: "libs", include: ["*.jar"]) 136 implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 137 implementation 'androidx.core:core-ktx:1.3.2' 138 implementation 'androidx.appcompat:appcompat:1.2.0' 139 implementation 'com.google.flatbuffers:flatbuffers-java:2.0.0' 140 141} 142