blob: 882a929b411b99225d94dee7cc2bbcef347b3b16 [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
Alexander Dorokhine5b9fa152020-07-13 15:18:50 -070017import static androidx.build.SupportConfig.*
18import static androidx.build.dependencies.DependenciesKt.*
19
Alexander Dorokhineeb39d4d2020-04-06 16:10:36 -070020buildscript {
Alexander Dorokhineeb39d4d2020-04-06 16:10:36 -070021 dependencies {
Aurimas Liutikasfd4f7962020-10-01 16:44:06 -070022 classpath('gradle.plugin.com.google.protobuf:protobuf-gradle-plugin:0.8.13')
Alexander Dorokhineeb39d4d2020-04-06 16:10:36 -070023 }
24}
25
Alexander Dorokhine5b9fa152020-07-13 15:18:50 -070026plugins {
27 id('com.android.library')
28 id('com.google.protobuf')
Alexander Dorokhine5b9fa152020-07-13 15:18:50 -070029}
Alexander Dorokhineeb39d4d2020-04-06 16:10:36 -070030
Alexander Dorokhine5b9fa152020-07-13 15:18:50 -070031android {
32 buildToolsVersion BUILD_TOOLS_VERSION
33 compileSdkVersion COMPILE_SDK_VERSION
34 defaultConfig {
35 minSdkVersion DEFAULT_MIN_SDK_VERSION
36 targetSdkVersion TARGET_SDK_VERSION
37 testInstrumentationRunner INSTRUMENTATION_RUNNER
38 }
39 compileOptions {
40 sourceCompatibility = JavaVersion.VERSION_1_8
41 targetCompatibility = JavaVersion.VERSION_1_8
42 }
43 sourceSets {
44 main {
Alexander Dorokhine032e9822020-07-13 17:33:11 -070045 java.srcDir 'java/src/'
46 manifest.srcFile 'AndroidManifest.xml'
47 proto.srcDir 'proto/'
Alexander Dorokhineeb39d4d2020-04-06 16:10:36 -070048 }
Alexander Dorokhine260b5e12020-07-14 02:11:40 -070049 // TODO(b/161205849): Re-enable this test once icing nativeLib is no longer being built
50 // inside appsearch:appsearch.
51 //androidTest.java.srcDir 'java/tests/instrumentation/'
Alexander Dorokhineeb39d4d2020-04-06 16:10:36 -070052 }
53}
54
55dependencies {
Alexander Dorokhine5b9fa152020-07-13 15:18:50 -070056 api('androidx.annotation:annotation:1.1.0')
57
Alexander Dorokhinefc49cb42020-04-06 16:17:09 -070058 implementation('com.google.protobuf:protobuf-javalite:3.10.0')
Alexander Dorokhine5b9fa152020-07-13 15:18:50 -070059
60 androidTestImplementation(ANDROIDX_TEST_CORE)
61 androidTestImplementation(ANDROIDX_TEST_RULES)
62 androidTestImplementation(TRUTH)
Alexander Dorokhineeb39d4d2020-04-06 16:10:36 -070063}
64
65protobuf {
66 protoc {
67 artifact = 'com.google.protobuf:protoc:3.10.0'
68 }
69
70 generateProtoTasks {
71 all().each { task ->
Aurimas Liutikas39ba9602021-06-01 15:03:21 -070072 project.tasks.named("extractReleaseAnnotations").configure {
73 it.dependsOn(task)
74 }
Alexander Dorokhineeb39d4d2020-04-06 16:10:36 -070075 task.builtins {
76 java {
77 option 'lite'
78 }
79 }
80 }
81 }
82}
Alexander Dorokhinefc49cb42020-04-06 16:17:09 -070083
Aurimas Liutikasc0f44382020-11-13 14:42:58 -080084// Create export artifact for all variants (debug/release) for JarJaring
Alexander Dorokhine5b9fa152020-07-13 15:18:50 -070085android.libraryVariants.all { variant ->
86 def variantName = variant.name
87 def suffix = variantName.capitalize()
Aurimas Liutikasc0f44382020-11-13 14:42:58 -080088 def exportJarTask = tasks.register("exportJar${suffix}", Jar) {
89 archiveBaseName.set("icing-${variantName}")
Rohit Sathyanarayana04d37662020-08-12 17:05:56 -070090
Aurimas Liutikasc0f44382020-11-13 14:42:58 -080091 // The proto-lite dependency includes .proto files, which are not used by icing. When apps
92 // depend on appsearch as well as proto-lite directly, these files conflict since jarjar
93 // only renames the java classes. Remove them here since they are unused.
94 // Expand the jar and remove any .proto files.
95 from(zipTree(configurations.detachedConfiguration(
96 dependencies.create(PROTOBUF_LITE)).getSingleFile())) {
97 exclude("**/*.proto")
98 }
Rohit Sathyanarayana04d37662020-08-12 17:05:56 -070099
Alexander Dorokhine5b9fa152020-07-13 15:18:50 -0700100 from files(variant.javaCompileProvider.get().destinationDir)
101 dependsOn variant.javaCompileProvider.get()
Alexander Dorokhine5b9fa152020-07-13 15:18:50 -0700102 }
Alexander Dorokhinefc49cb42020-04-06 16:17:09 -0700103
Aurimas Liutikasc0f44382020-11-13 14:42:58 -0800104 def exportConfiguration = configurations.register("export${suffix}")
105 artifacts.add(exportConfiguration.name, exportJarTask.flatMap { it.archiveFile })
Alexander Dorokhinefc49cb42020-04-06 16:17:09 -0700106}