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 static androidx.build.SupportConfig.* 18 19buildscript { 20 dependencies { 21 classpath('gradle.plugin.com.google.protobuf:protobuf-gradle-plugin:0.8.13') 22 } 23} 24 25plugins { 26 id('com.android.library') 27 id('com.google.protobuf') 28} 29 30android { 31 buildToolsVersion BUILD_TOOLS_VERSION 32 compileSdkVersion COMPILE_SDK_VERSION 33 defaultConfig { 34 minSdkVersion DEFAULT_MIN_SDK_VERSION 35 targetSdkVersion TARGET_SDK_VERSION 36 testInstrumentationRunner INSTRUMENTATION_RUNNER 37 } 38 compileOptions { 39 sourceCompatibility = JavaVersion.VERSION_1_8 40 targetCompatibility = JavaVersion.VERSION_1_8 41 } 42 sourceSets { 43 main { 44 java.srcDir 'java/src/' 45 manifest.srcFile 'AndroidManifest.xml' 46 proto.srcDir 'proto/' 47 } 48 // TODO(b/161205849): Re-enable this test once icing nativeLib is no longer being built 49 // inside appsearch:appsearch. 50 //androidTest.java.srcDir 'java/tests/instrumentation/' 51 } 52} 53 54dependencies { 55 api('androidx.annotation:annotation:1.1.0') 56 57 implementation('com.google.protobuf:protobuf-javalite:3.10.0') 58 59 androidTestImplementation(libs.testCore) 60 androidTestImplementation(libs.testRules) 61 androidTestImplementation(libs.truth) 62} 63 64protobuf { 65 protoc { 66 artifact = libs.protobufCompiler.get() 67 } 68 69 generateProtoTasks { 70 all().each { task -> 71 project.tasks.named("extractReleaseAnnotations").configure { 72 it.dependsOn(task) 73 } 74 task.builtins { 75 java { 76 option 'lite' 77 } 78 } 79 } 80 } 81} 82 83// Create export artifact for all variants (debug/release) for JarJaring 84android.libraryVariants.all { variant -> 85 def variantName = variant.name 86 def suffix = variantName.capitalize() 87 def exportJarTask = tasks.register("exportJar${suffix}", Jar) { 88 archiveBaseName.set("icing-${variantName}") 89 90 // The proto-lite dependency includes .proto files, which are not used by icing. When apps 91 // depend on appsearch as well as proto-lite directly, these files conflict since jarjar 92 // only renames the java classes. Remove them here since they are unused. 93 // Expand the jar and remove any .proto files. 94 from(zipTree(configurations.detachedConfiguration( 95 dependencies.create(libs.protobufLite.get())).getSingleFile())) { 96 exclude("**/*.proto") 97 } 98 99 from files(variant.javaCompileProvider.get().destinationDir) 100 dependsOn variant.javaCompileProvider.get() 101 } 102 103 def exportConfiguration = configurations.register("export${suffix}") 104 artifacts.add(exportConfiguration.name, exportJarTask.flatMap { it.archiveFile }) 105} 106