blob: d6aea25c699ca2525ecd820c120d2a3e799e4926 [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 Dorokhine032e9822020-07-13 17:33:11 -070053 androidTest.java.srcDir 'java/tests/instrumentation/'
Alexander Dorokhineeb39d4d2020-04-06 16:10:36 -070054 }
55}
56
57dependencies {
Alexander Dorokhine5b9fa152020-07-13 15:18:50 -070058 api('androidx.annotation:annotation:1.1.0')
59
60 implementation project(':icing:nativeLib')
Alexander Dorokhinefc49cb42020-04-06 16:17:09 -070061 implementation('com.google.protobuf:protobuf-javalite:3.10.0')
Alexander Dorokhine5b9fa152020-07-13 15:18:50 -070062
63 androidTestImplementation(ANDROIDX_TEST_CORE)
64 androidTestImplementation(ANDROIDX_TEST_RULES)
65 androidTestImplementation(TRUTH)
Alexander Dorokhineeb39d4d2020-04-06 16:10:36 -070066}
67
68protobuf {
69 protoc {
70 artifact = 'com.google.protobuf:protoc:3.10.0'
71 }
72
73 generateProtoTasks {
74 all().each { task ->
75 task.builtins {
76 java {
77 option 'lite'
78 }
79 }
80 }
81 }
82}
Alexander Dorokhinefc49cb42020-04-06 16:17:09 -070083
Alexander Dorokhine5b9fa152020-07-13 15:18:50 -070084// Create jarjar artifact for all variants (debug/release)
85android.libraryVariants.all { variant ->
86 def variantName = variant.name
87 def suffix = variantName.capitalize()
88 def jarjarTask = tasks.create("jarjar${suffix}", JarjarTask) {
89 destinationName "icing-java-${variantName}-jarjar.jar"
90 from 'com.google.protobuf:protobuf-javalite:3.10.0'
91 from files(variant.javaCompileProvider.get().destinationDir)
92 dependsOn variant.javaCompileProvider.get()
93 classRename 'com.google.protobuf.**', 'com.google.android.icing.protobuf.@1'
94 }
Alexander Dorokhinefc49cb42020-04-06 16:17:09 -070095
Alexander Dorokhine5b9fa152020-07-13 15:18:50 -070096 def jarjarConf = configurations.register("jarjar${suffix}")
97 artifacts.add("${jarjarConf.name}", jarjarTask.destinationPath) {
98 name "icing-java-${variantName}-jarjar"
Alexander Dorokhinefc49cb42020-04-06 16:17:09 -070099 type 'jar'
100 builtBy jarjarTask
101 }
102}