1/* 2 * Copyright (C) 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17import androidx.build.SupportConfig 18 19plugins { 20 id('AndroidXPlugin') 21 id('com.android.library') 22 id('com.google.protobuf') 23} 24 25android { 26 buildToolsVersion SupportConfig.buildToolsVersion(project) 27 compileSdkVersion SupportConfig.COMPILE_SDK_VERSION 28 defaultConfig { 29 minSdkVersion SupportConfig.DEFAULT_MIN_SDK_VERSION 30 targetSdkVersion SupportConfig.TARGET_SDK_VERSION 31 testInstrumentationRunner SupportConfig.INSTRUMENTATION_RUNNER 32 } 33 compileOptions { 34 sourceCompatibility = JavaVersion.VERSION_1_8 35 targetCompatibility = JavaVersion.VERSION_1_8 36 } 37 sourceSets { 38 main { 39 java.srcDir 'java/src/' 40 proto.srcDir 'proto/' 41 } 42 // TODO(b/161205849): Re-enable this test once icing nativeLib is no longer being built 43 // inside appsearch:appsearch. 44 //androidTest.java.srcDir 'java/tests/instrumentation/' 45 } 46 namespace "com.google.android.icing" 47} 48 49// This project has no device tests, skip building it 50androidComponents { 51 beforeVariants(selector().withName("debug"), { variantBuilder -> 52 variantBuilder.enableAndroidTest = false 53 }) 54} 55 56dependencies { 57 api('androidx.annotation:annotation:1.1.0') 58 59 implementation('com.google.protobuf:protobuf-javalite:3.10.0') 60 61 androidTestImplementation(libs.testCore) 62 androidTestImplementation(libs.testRules) 63 androidTestImplementation(libs.truth) 64 androidTestImplementation(libs.kotlinBom) 65} 66 67protobuf { 68 protoc { 69 artifact = libs.protobufCompiler.get() 70 } 71 72 generateProtoTasks { 73 all().each { task -> 74 project.tasks.named("extractReleaseAnnotations").configure { 75 it.dependsOn(task) 76 } 77 task.builtins { 78 java { 79 option 'lite' 80 } 81 } 82 } 83 } 84} 85 86// Create export artifact for all variants (debug/release) for JarJaring 87android.libraryVariants.all { variant -> 88 def variantName = variant.name 89 def suffix = variantName.capitalize() 90 def exportJarTask = tasks.register("exportJar${suffix}", Jar) { 91 archiveBaseName.set("icing-${variantName}") 92 93 // The proto-lite dependency includes .proto files, which are not used by icing. When apps 94 // depend on appsearch as well as proto-lite directly, these files conflict since jarjar 95 // only renames the java classes. Remove them here since they are unused. 96 // Expand the jar and remove any .proto files. 97 from(zipTree(configurations.detachedConfiguration( 98 dependencies.create(libs.protobufLite.get())).getSingleFile())) { 99 exclude("**/*.proto") 100 } 101 102 from files(variant.javaCompileProvider.get().destinationDir) 103 dependsOn variant.javaCompileProvider.get() 104 } 105 106 def exportConfiguration = configurations.register("export${suffix}") 107 artifacts.add(exportConfiguration.name, exportJarTask.flatMap { it.archiveFile }) 108} 109 110androidx { 111 mavenVersion = LibraryVersions.APPSEARCH 112} 113