Strip .proto files from appsearch proto-lite dependency using jar task
The datastore sample app fails to build with a direct proto lite dependency and dependency on appsearch because these .proto files are duplicated but unecessary.
See failure here: aosp/1394341
Bug: 163897667
Test: Built DataStore sample app. I've added a test in a follow up cl here: aosp/1399613
Relnote: Fixing dependency issue
Change-Id: If68a7a5dc1369baa552140feff0913de64cba98d
diff --git a/build.gradle b/build.gradle
index 3901078..7f32c42 100644
--- a/build.gradle
+++ b/build.gradle
@@ -88,7 +88,11 @@
def suffix = variantName.capitalize()
def jarjarTask = tasks.create("jarjar${suffix}", JarjarTask) {
destinationName "icing-java-${variantName}-jarjar.jar"
- from 'com.google.protobuf:protobuf-javalite:3.10.0'
+
+
+ dependsOn protoLiteJarWithoutProtoFiles
+ from files(protoLiteJarWithoutProtoFiles.archiveFile.get().getAsFile())
+
from files(variant.javaCompileProvider.get().destinationDir)
dependsOn variant.javaCompileProvider.get()
classRename 'com.google.protobuf.**', 'com.google.android.icing.protobuf.@1'
@@ -101,3 +105,20 @@
builtBy jarjarTask
}
}
+
+// The proto-lite dependency includes .proto files, which are not used by icing. When apps depend on
+// appsearch as well as proto-lite directly, these files conflict since jarjar only renames the java
+// classes. Remove them here since they are unused.
+tasks.register("protoLiteJarWithoutProtoFiles", Jar){
+ // Get proto lite dependency as a jar file:
+ def jarFile = configurations.detachedConfiguration(
+ dependencies.create('com.google.protobuf:protobuf-javalite:3.10.0')).getSingleFile()
+
+ // Expand the jar and remove any .proto files.
+ from(zipTree(jarFile)) {
+ exclude("**/*.proto")
+ }
+
+ into 'icing-proto-lite-dep-stripped'
+}
+