blob: 437f57fc03684d2c89cb356c53f7bd892db04e2d [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 ->
72 task.builtins {
73 java {
74 option 'lite'
75 }
76 }
77 }
78 }
79}
Alexander Dorokhinefc49cb42020-04-06 16:17:09 -070080
Aurimas Liutikasc0f44382020-11-13 14:42:58 -080081// Create export artifact for all variants (debug/release) for JarJaring
Alexander Dorokhine5b9fa152020-07-13 15:18:50 -070082android.libraryVariants.all { variant ->
83 def variantName = variant.name
84 def suffix = variantName.capitalize()
Aurimas Liutikasc0f44382020-11-13 14:42:58 -080085 def exportJarTask = tasks.register("exportJar${suffix}", Jar) {
86 archiveBaseName.set("icing-${variantName}")
Rohit Sathyanarayana04d37662020-08-12 17:05:56 -070087
Aurimas Liutikasc0f44382020-11-13 14:42:58 -080088 // The proto-lite dependency includes .proto files, which are not used by icing. When apps
89 // depend on appsearch as well as proto-lite directly, these files conflict since jarjar
90 // only renames the java classes. Remove them here since they are unused.
91 // Expand the jar and remove any .proto files.
92 from(zipTree(configurations.detachedConfiguration(
93 dependencies.create(PROTOBUF_LITE)).getSingleFile())) {
94 exclude("**/*.proto")
95 }
Rohit Sathyanarayana04d37662020-08-12 17:05:56 -070096
Alexander Dorokhine5b9fa152020-07-13 15:18:50 -070097 from files(variant.javaCompileProvider.get().destinationDir)
98 dependsOn variant.javaCompileProvider.get()
Alexander Dorokhine5b9fa152020-07-13 15:18:50 -070099 }
Alexander Dorokhinefc49cb42020-04-06 16:17:09 -0700100
Aurimas Liutikasc0f44382020-11-13 14:42:58 -0800101 def exportConfiguration = configurations.register("export${suffix}")
102 artifacts.add(exportConfiguration.name, exportJarTask.flatMap { it.archiveFile })
Alexander Dorokhinefc49cb42020-04-06 16:17:09 -0700103}