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 org.anarres.gradle.plugin.jarjar.JarjarTask |
| 18 | |
| 19 | import static androidx.build.SupportConfig.* |
| 20 | import static androidx.build.dependencies.DependenciesKt.* |
| 21 | |
Alexander Dorokhine | eb39d4d | 2020-04-06 16:10:36 -0700 | [diff] [blame] | 22 | buildscript { |
Alexander Dorokhine | eb39d4d | 2020-04-06 16:10:36 -0700 | [diff] [blame] | 23 | dependencies { |
| 24 | classpath('gradle.plugin.com.google.protobuf:protobuf-gradle-plugin:0.8.8') |
Alexander Dorokhine | fc49cb4 | 2020-04-06 16:17:09 -0700 | [diff] [blame] | 25 | classpath('org.anarres.jarjar:jarjar-gradle:1.0.1') |
Alexander Dorokhine | eb39d4d | 2020-04-06 16:10:36 -0700 | [diff] [blame] | 26 | } |
| 27 | } |
| 28 | |
Alexander Dorokhine | 5b9fa15 | 2020-07-13 15:18:50 -0700 | [diff] [blame] | 29 | plugins { |
| 30 | id('com.android.library') |
| 31 | id('com.google.protobuf') |
| 32 | id('org.anarres.jarjar') |
| 33 | } |
Alexander Dorokhine | eb39d4d | 2020-04-06 16:10:36 -0700 | [diff] [blame] | 34 | |
Alexander Dorokhine | 5b9fa15 | 2020-07-13 15:18:50 -0700 | [diff] [blame] | 35 | android { |
| 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 Dorokhine | 032e982 | 2020-07-13 17:33:11 -0700 | [diff] [blame^] | 49 | java.srcDir 'java/src/' |
| 50 | manifest.srcFile 'AndroidManifest.xml' |
| 51 | proto.srcDir 'proto/' |
Alexander Dorokhine | eb39d4d | 2020-04-06 16:10:36 -0700 | [diff] [blame] | 52 | } |
Alexander Dorokhine | 032e982 | 2020-07-13 17:33:11 -0700 | [diff] [blame^] | 53 | androidTest.java.srcDir 'java/tests/instrumentation/' |
Alexander Dorokhine | eb39d4d | 2020-04-06 16:10:36 -0700 | [diff] [blame] | 54 | } |
| 55 | } |
| 56 | |
| 57 | dependencies { |
Alexander Dorokhine | 5b9fa15 | 2020-07-13 15:18:50 -0700 | [diff] [blame] | 58 | api('androidx.annotation:annotation:1.1.0') |
| 59 | |
| 60 | implementation project(':icing:nativeLib') |
Alexander Dorokhine | fc49cb4 | 2020-04-06 16:17:09 -0700 | [diff] [blame] | 61 | implementation('com.google.protobuf:protobuf-javalite:3.10.0') |
Alexander Dorokhine | 5b9fa15 | 2020-07-13 15:18:50 -0700 | [diff] [blame] | 62 | |
| 63 | androidTestImplementation(ANDROIDX_TEST_CORE) |
| 64 | androidTestImplementation(ANDROIDX_TEST_RULES) |
| 65 | androidTestImplementation(TRUTH) |
Alexander Dorokhine | eb39d4d | 2020-04-06 16:10:36 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | protobuf { |
| 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 Dorokhine | fc49cb4 | 2020-04-06 16:17:09 -0700 | [diff] [blame] | 83 | |
Alexander Dorokhine | 5b9fa15 | 2020-07-13 15:18:50 -0700 | [diff] [blame] | 84 | // Create jarjar artifact for all variants (debug/release) |
| 85 | android.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 Dorokhine | fc49cb4 | 2020-04-06 16:17:09 -0700 | [diff] [blame] | 95 | |
Alexander Dorokhine | 5b9fa15 | 2020-07-13 15:18:50 -0700 | [diff] [blame] | 96 | def jarjarConf = configurations.register("jarjar${suffix}") |
| 97 | artifacts.add("${jarjarConf.name}", jarjarTask.destinationPath) { |
| 98 | name "icing-java-${variantName}-jarjar" |
Alexander Dorokhine | fc49cb4 | 2020-04-06 16:17:09 -0700 | [diff] [blame] | 99 | type 'jar' |
| 100 | builtBy jarjarTask |
| 101 | } |
| 102 | } |