blob: 7f32c42256264eb14cd2fe3b23074f4d4c4997dd [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 org.anarres.gradle.plugin.jarjar.JarjarTask
18
19import static androidx.build.SupportConfig.*
20import static androidx.build.dependencies.DependenciesKt.*
21
Alexander Dorokhineeb39d4d2020-04-06 16:10:36 -070022buildscript {
Alexander Dorokhineeb39d4d2020-04-06 16:10:36 -070023 dependencies {
24 classpath('gradle.plugin.com.google.protobuf:protobuf-gradle-plugin:0.8.8')
Alexander Dorokhinefc49cb42020-04-06 16:17:09 -070025 classpath('org.anarres.jarjar:jarjar-gradle:1.0.1')
Alexander Dorokhineeb39d4d2020-04-06 16:10:36 -070026 }
27}
28
Alexander Dorokhine5b9fa152020-07-13 15:18:50 -070029plugins {
30 id('com.android.library')
31 id('com.google.protobuf')
32 id('org.anarres.jarjar')
33}
Alexander Dorokhineeb39d4d2020-04-06 16:10:36 -070034
Alexander Dorokhine5b9fa152020-07-13 15:18:50 -070035android {
36 buildToolsVersion BUILD_TOOLS_VERSION
37 compileSdkVersion COMPILE_SDK_VERSION
38 defaultConfig {
39 minSdkVersion DEFAULT_MIN_SDK_VERSION
40 targetSdkVersion TARGET_SDK_VERSION
41 testInstrumentationRunner INSTRUMENTATION_RUNNER
42 }
43 compileOptions {
44 sourceCompatibility = JavaVersion.VERSION_1_8
45 targetCompatibility = JavaVersion.VERSION_1_8
46 }
47 sourceSets {
48 main {
Alexander Dorokhine032e9822020-07-13 17:33:11 -070049 java.srcDir 'java/src/'
50 manifest.srcFile 'AndroidManifest.xml'
51 proto.srcDir 'proto/'
Alexander Dorokhineeb39d4d2020-04-06 16:10:36 -070052 }
Alexander Dorokhine260b5e12020-07-14 02:11:40 -070053 // TODO(b/161205849): Re-enable this test once icing nativeLib is no longer being built
54 // inside appsearch:appsearch.
55 //androidTest.java.srcDir 'java/tests/instrumentation/'
Alexander Dorokhineeb39d4d2020-04-06 16:10:36 -070056 }
57}
58
59dependencies {
Alexander Dorokhine5b9fa152020-07-13 15:18:50 -070060 api('androidx.annotation:annotation:1.1.0')
61
Alexander Dorokhinefc49cb42020-04-06 16:17:09 -070062 implementation('com.google.protobuf:protobuf-javalite:3.10.0')
Alexander Dorokhine5b9fa152020-07-13 15:18:50 -070063
64 androidTestImplementation(ANDROIDX_TEST_CORE)
65 androidTestImplementation(ANDROIDX_TEST_RULES)
66 androidTestImplementation(TRUTH)
Alexander Dorokhineeb39d4d2020-04-06 16:10:36 -070067}
68
69protobuf {
70 protoc {
71 artifact = 'com.google.protobuf:protoc:3.10.0'
72 }
73
74 generateProtoTasks {
75 all().each { task ->
76 task.builtins {
77 java {
78 option 'lite'
79 }
80 }
81 }
82 }
83}
Alexander Dorokhinefc49cb42020-04-06 16:17:09 -070084
Alexander Dorokhine5b9fa152020-07-13 15:18:50 -070085// Create jarjar artifact for all variants (debug/release)
86android.libraryVariants.all { variant ->
87 def variantName = variant.name
88 def suffix = variantName.capitalize()
89 def jarjarTask = tasks.create("jarjar${suffix}", JarjarTask) {
90 destinationName "icing-java-${variantName}-jarjar.jar"
Rohit Sathyanarayana04d37662020-08-12 17:05:56 -070091
92
93 dependsOn protoLiteJarWithoutProtoFiles
94 from files(protoLiteJarWithoutProtoFiles.archiveFile.get().getAsFile())
95
Alexander Dorokhine5b9fa152020-07-13 15:18:50 -070096 from files(variant.javaCompileProvider.get().destinationDir)
97 dependsOn variant.javaCompileProvider.get()
98 classRename 'com.google.protobuf.**', 'com.google.android.icing.protobuf.@1'
99 }
Alexander Dorokhinefc49cb42020-04-06 16:17:09 -0700100
Alexander Dorokhine5b9fa152020-07-13 15:18:50 -0700101 def jarjarConf = configurations.register("jarjar${suffix}")
102 artifacts.add("${jarjarConf.name}", jarjarTask.destinationPath) {
103 name "icing-java-${variantName}-jarjar"
Alexander Dorokhinefc49cb42020-04-06 16:17:09 -0700104 type 'jar'
105 builtBy jarjarTask
106 }
107}
Rohit Sathyanarayana04d37662020-08-12 17:05:56 -0700108
109// The proto-lite dependency includes .proto files, which are not used by icing. When apps depend on
110// appsearch as well as proto-lite directly, these files conflict since jarjar only renames the java
111// classes. Remove them here since they are unused.
112tasks.register("protoLiteJarWithoutProtoFiles", Jar){
113 // Get proto lite dependency as a jar file:
114 def jarFile = configurations.detachedConfiguration(
115 dependencies.create('com.google.protobuf:protobuf-javalite:3.10.0')).getSingleFile()
116
117 // Expand the jar and remove any .proto files.
118 from(zipTree(jarFile)) {
119 exclude("**/*.proto")
120 }
121
122 into 'icing-proto-lite-dep-stripped'
123}
124