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