Alexander Dorokhine | eb39d4d | 2020-04-06 16:10:36 -0700 | [diff] [blame] | 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 | |
Alexander Dorokhine | 5b9fa15 | 2020-07-13 15:18:50 -0700 | [diff] [blame] | 17 | import static androidx.build.SupportConfig.* |
| 18 | import static androidx.build.dependencies.DependenciesKt.* |
| 19 | |
Alexander Dorokhine | eb39d4d | 2020-04-06 16:10:36 -0700 | [diff] [blame] | 20 | buildscript { |
Alexander Dorokhine | eb39d4d | 2020-04-06 16:10:36 -0700 | [diff] [blame] | 21 | dependencies { |
Aurimas Liutikas | fd4f796 | 2020-10-01 16:44:06 -0700 | [diff] [blame] | 22 | classpath('gradle.plugin.com.google.protobuf:protobuf-gradle-plugin:0.8.13') |
Alexander Dorokhine | eb39d4d | 2020-04-06 16:10:36 -0700 | [diff] [blame] | 23 | } |
| 24 | } |
| 25 | |
Alexander Dorokhine | 5b9fa15 | 2020-07-13 15:18:50 -0700 | [diff] [blame] | 26 | plugins { |
| 27 | id('com.android.library') |
| 28 | id('com.google.protobuf') |
Alexander Dorokhine | 5b9fa15 | 2020-07-13 15:18:50 -0700 | [diff] [blame] | 29 | } |
Alexander Dorokhine | eb39d4d | 2020-04-06 16:10:36 -0700 | [diff] [blame] | 30 | |
Alexander Dorokhine | 5b9fa15 | 2020-07-13 15:18:50 -0700 | [diff] [blame] | 31 | android { |
| 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 Dorokhine | 032e982 | 2020-07-13 17:33:11 -0700 | [diff] [blame] | 45 | java.srcDir 'java/src/' |
| 46 | manifest.srcFile 'AndroidManifest.xml' |
| 47 | proto.srcDir 'proto/' |
Alexander Dorokhine | eb39d4d | 2020-04-06 16:10:36 -0700 | [diff] [blame] | 48 | } |
Alexander Dorokhine | 260b5e1 | 2020-07-14 02:11:40 -0700 | [diff] [blame] | 49 | // 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 Dorokhine | eb39d4d | 2020-04-06 16:10:36 -0700 | [diff] [blame] | 52 | } |
| 53 | } |
| 54 | |
| 55 | dependencies { |
Alexander Dorokhine | 5b9fa15 | 2020-07-13 15:18:50 -0700 | [diff] [blame] | 56 | api('androidx.annotation:annotation:1.1.0') |
| 57 | |
Alexander Dorokhine | fc49cb4 | 2020-04-06 16:17:09 -0700 | [diff] [blame] | 58 | implementation('com.google.protobuf:protobuf-javalite:3.10.0') |
Alexander Dorokhine | 5b9fa15 | 2020-07-13 15:18:50 -0700 | [diff] [blame] | 59 | |
| 60 | androidTestImplementation(ANDROIDX_TEST_CORE) |
| 61 | androidTestImplementation(ANDROIDX_TEST_RULES) |
| 62 | androidTestImplementation(TRUTH) |
Alexander Dorokhine | eb39d4d | 2020-04-06 16:10:36 -0700 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | protobuf { |
| 66 | protoc { |
| 67 | artifact = 'com.google.protobuf:protoc:3.10.0' |
| 68 | } |
| 69 | |
| 70 | generateProtoTasks { |
| 71 | all().each { task -> |
Aurimas Liutikas | 39ba960 | 2021-06-01 15:03:21 -0700 | [diff] [blame] | 72 | project.tasks.named("extractReleaseAnnotations").configure { |
| 73 | it.dependsOn(task) |
| 74 | } |
Alexander Dorokhine | eb39d4d | 2020-04-06 16:10:36 -0700 | [diff] [blame] | 75 | task.builtins { |
| 76 | java { |
| 77 | option 'lite' |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | } |
Alexander Dorokhine | fc49cb4 | 2020-04-06 16:17:09 -0700 | [diff] [blame] | 83 | |
Aurimas Liutikas | c0f4438 | 2020-11-13 14:42:58 -0800 | [diff] [blame] | 84 | // Create export artifact for all variants (debug/release) for JarJaring |
Alexander Dorokhine | 5b9fa15 | 2020-07-13 15:18:50 -0700 | [diff] [blame] | 85 | android.libraryVariants.all { variant -> |
| 86 | def variantName = variant.name |
| 87 | def suffix = variantName.capitalize() |
Aurimas Liutikas | c0f4438 | 2020-11-13 14:42:58 -0800 | [diff] [blame] | 88 | def exportJarTask = tasks.register("exportJar${suffix}", Jar) { |
| 89 | archiveBaseName.set("icing-${variantName}") |
Rohit Sathyanarayana | 04d3766 | 2020-08-12 17:05:56 -0700 | [diff] [blame] | 90 | |
Aurimas Liutikas | c0f4438 | 2020-11-13 14:42:58 -0800 | [diff] [blame] | 91 | // 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 Sathyanarayana | 04d3766 | 2020-08-12 17:05:56 -0700 | [diff] [blame] | 99 | |
Alexander Dorokhine | 5b9fa15 | 2020-07-13 15:18:50 -0700 | [diff] [blame] | 100 | from files(variant.javaCompileProvider.get().destinationDir) |
| 101 | dependsOn variant.javaCompileProvider.get() |
Alexander Dorokhine | 5b9fa15 | 2020-07-13 15:18:50 -0700 | [diff] [blame] | 102 | } |
Alexander Dorokhine | fc49cb4 | 2020-04-06 16:17:09 -0700 | [diff] [blame] | 103 | |
Aurimas Liutikas | c0f4438 | 2020-11-13 14:42:58 -0800 | [diff] [blame] | 104 | def exportConfiguration = configurations.register("export${suffix}") |
| 105 | artifacts.add(exportConfiguration.name, exportJarTask.flatMap { it.archiveFile }) |
Alexander Dorokhine | fc49cb4 | 2020-04-06 16:17:09 -0700 | [diff] [blame] | 106 | } |