blob: 0f60c5e63044146fd8016f5f560179ab5db73274 [file] [log] [blame]
Alexander Dorokhineeb39d4d2020-04-06 16:10:36 -07001/*
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
Aurimas Liutikasbbbb1f62021-06-30 08:27:23 -070017
18import androidx.build.dependencies.DependenciesKt
Alexander Dorokhine5b9fa152020-07-13 15:18:50 -070019import static androidx.build.SupportConfig.*
Alexander Dorokhine5b9fa152020-07-13 15:18:50 -070020
Alexander Dorokhineeb39d4d2020-04-06 16:10:36 -070021buildscript {
Alexander Dorokhineeb39d4d2020-04-06 16:10:36 -070022 dependencies {
Aurimas Liutikasfd4f7962020-10-01 16:44:06 -070023 classpath('gradle.plugin.com.google.protobuf:protobuf-gradle-plugin:0.8.13')
Alexander Dorokhineeb39d4d2020-04-06 16:10:36 -070024 }
25}
26
Alexander Dorokhine5b9fa152020-07-13 15:18:50 -070027plugins {
28 id('com.android.library')
29 id('com.google.protobuf')
Alexander Dorokhine5b9fa152020-07-13 15:18:50 -070030}
Alexander Dorokhineeb39d4d2020-04-06 16:10:36 -070031
Alexander Dorokhine5b9fa152020-07-13 15:18:50 -070032android {
33 buildToolsVersion BUILD_TOOLS_VERSION
34 compileSdkVersion COMPILE_SDK_VERSION
35 defaultConfig {
36 minSdkVersion DEFAULT_MIN_SDK_VERSION
37 targetSdkVersion TARGET_SDK_VERSION
38 testInstrumentationRunner INSTRUMENTATION_RUNNER
39 }
40 compileOptions {
41 sourceCompatibility = JavaVersion.VERSION_1_8
42 targetCompatibility = JavaVersion.VERSION_1_8
43 }
44 sourceSets {
45 main {
Alexander Dorokhine032e9822020-07-13 17:33:11 -070046 java.srcDir 'java/src/'
47 manifest.srcFile 'AndroidManifest.xml'
48 proto.srcDir 'proto/'
Alexander Dorokhineeb39d4d2020-04-06 16:10:36 -070049 }
Alexander Dorokhine260b5e12020-07-14 02:11:40 -070050 // TODO(b/161205849): Re-enable this test once icing nativeLib is no longer being built
51 // inside appsearch:appsearch.
52 //androidTest.java.srcDir 'java/tests/instrumentation/'
Alexander Dorokhineeb39d4d2020-04-06 16:10:36 -070053 }
54}
55
56dependencies {
Alexander Dorokhine5b9fa152020-07-13 15:18:50 -070057 api('androidx.annotation:annotation:1.1.0')
58
Alexander Dorokhinefc49cb42020-04-06 16:17:09 -070059 implementation('com.google.protobuf:protobuf-javalite:3.10.0')
Alexander Dorokhine5b9fa152020-07-13 15:18:50 -070060
Aurimas Liutikas65982dc2021-06-23 11:32:24 -070061 androidTestImplementation(libs.testCore)
62 androidTestImplementation(libs.testRules)
63 androidTestImplementation(libs.truth)
Alexander Dorokhineeb39d4d2020-04-06 16:10:36 -070064}
65
66protobuf {
67 protoc {
Aurimas Liutikasbbbb1f62021-06-30 08:27:23 -070068 artifact = DependenciesKt.getDependencyAsString(libs.protobufCompiler)
Alexander Dorokhineeb39d4d2020-04-06 16:10:36 -070069 }
70
71 generateProtoTasks {
72 all().each { task ->
Aurimas Liutikas39ba9602021-06-01 15:03:21 -070073 project.tasks.named("extractReleaseAnnotations").configure {
74 it.dependsOn(task)
75 }
Alexander Dorokhineeb39d4d2020-04-06 16:10:36 -070076 task.builtins {
77 java {
78 option 'lite'
79 }
80 }
81 }
82 }
83}
Alexander Dorokhinefc49cb42020-04-06 16:17:09 -070084
Aurimas Liutikasc0f44382020-11-13 14:42:58 -080085// Create export artifact for all variants (debug/release) for JarJaring
Alexander Dorokhine5b9fa152020-07-13 15:18:50 -070086android.libraryVariants.all { variant ->
87 def variantName = variant.name
88 def suffix = variantName.capitalize()
Aurimas Liutikasc0f44382020-11-13 14:42:58 -080089 def exportJarTask = tasks.register("exportJar${suffix}", Jar) {
90 archiveBaseName.set("icing-${variantName}")
Rohit Sathyanarayana04d37662020-08-12 17:05:56 -070091
Aurimas Liutikasc0f44382020-11-13 14:42:58 -080092 // The proto-lite dependency includes .proto files, which are not used by icing. When apps
93 // depend on appsearch as well as proto-lite directly, these files conflict since jarjar
94 // only renames the java classes. Remove them here since they are unused.
95 // Expand the jar and remove any .proto files.
96 from(zipTree(configurations.detachedConfiguration(
Aurimas Liutikasbbbb1f62021-06-30 08:27:23 -070097 dependencies.create(libs.protobufLite.get())).getSingleFile())) {
Aurimas Liutikasc0f44382020-11-13 14:42:58 -080098 exclude("**/*.proto")
99 }
Rohit Sathyanarayana04d37662020-08-12 17:05:56 -0700100
Alexander Dorokhine5b9fa152020-07-13 15:18:50 -0700101 from files(variant.javaCompileProvider.get().destinationDir)
102 dependsOn variant.javaCompileProvider.get()
Alexander Dorokhine5b9fa152020-07-13 15:18:50 -0700103 }
Alexander Dorokhinefc49cb42020-04-06 16:17:09 -0700104
Aurimas Liutikasc0f44382020-11-13 14:42:58 -0800105 def exportConfiguration = configurations.register("export${suffix}")
106 artifacts.add(exportConfiguration.name, exportJarTask.flatMap { it.archiveFile })
Alexander Dorokhinefc49cb42020-04-06 16:17:09 -0700107}