From ec9c4f473d9b5b6d316405f5057eeeddbaa27ff5 Mon Sep 17 00:00:00 2001 From: Aurimas Liutikas Date: Wed, 23 Aug 2023 15:32:13 -0700 Subject: Move icing to be a simple java project Since icing is only bundled inside of appsearch:appsearch-local-storage there is no need to use an android project as at the end of the day we end up only including the jar of icing anyway. Moving to a java project simplifies is as now we no longer need to add special export configurations. We are also moving the dropping of *.proto files to the projects that bundle the libraries. This is a step towards making it easier to resolve what artifact coordinates were actually bundled inside. Test: ./gradlew appsearch:appsearch-local-storage:publish comparing out/androidx/build/support_repo/androidx/appsearch/appsearch-local-storage/1.1.0-alpha04/appsearch-local-storage-1.1.0-alpha04.aar before and after the change, libs/repackaged.jar is identical Bug: 296864329 Change-Id: Ibba769f71ecdb58cb20df0ea0c37364cf579eddf --- build.gradle | 79 ++++++---------------- .../google/android/icing/IcingSearchEngine.java | 1 + .../android/icing/IcingSearchEngineImpl.java | 1 + 3 files changed, 22 insertions(+), 59 deletions(-) diff --git a/build.gradle b/build.gradle index dde0637..d0d1a39 100644 --- a/build.gradle +++ b/build.gradle @@ -14,57 +14,42 @@ * limitations under the License. */ +import androidx.build.SdkHelperKt + plugins { - id('AndroidXPlugin') - id('com.android.library') - id('com.google.protobuf') + id("AndroidXPlugin") + id("java-library") + id("com.google.protobuf") } -android { - compileOptions { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 - } - sourceSets { - main { - java.srcDir 'java/src/' - proto.srcDir 'proto/' - } - // TODO(b/161205849): Re-enable this test once icing nativeLib is no longer being built - // inside appsearch:appsearch. - //androidTest.java.srcDir 'java/tests/instrumentation/' +sourceSets { + main { + java.srcDir 'java/src/' + proto.srcDir 'proto/' } - namespace "com.google.android.icing" -} - -// This project has no device tests, skip building it -androidComponents { - beforeVariants(selector().withName("debug"), { variantBuilder -> - variantBuilder.enableAndroidTest = false - }) } dependencies { - api('androidx.annotation:annotation:1.1.0') - - implementation('com.google.protobuf:protobuf-javalite:3.10.0') + compileOnly("androidx.annotation:annotation:1.1.0") + compileOnly(SdkHelperKt.getSdkDependency(project)) + implementation(libs.protobufLite) +} - androidTestImplementation(libs.testCore) - androidTestImplementation(libs.testRules) - androidTestImplementation(libs.truth) - androidTestImplementation(libs.kotlinBom) +afterEvaluate { + lint { + lintOptions { + // protobuf generates unannotated methods + disable("UnknownNullness") + } + } } protobuf { protoc { artifact = libs.protobufCompiler.get() } - generateProtoTasks { all().each { task -> - project.tasks.named("extractReleaseAnnotations").configure { - it.dependsOn(task) - } task.builtins { java { option 'lite' @@ -74,30 +59,6 @@ protobuf { } } -// Create export artifact for all variants (debug/release) for JarJaring -android.libraryVariants.all { variant -> - def variantName = variant.name - def suffix = variantName.capitalize() - def exportJarTask = tasks.register("exportJar${suffix}", Jar) { - archiveBaseName.set("icing-${variantName}") - - // 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. - // Expand the jar and remove any .proto files. - from(zipTree(configurations.detachedConfiguration( - dependencies.create(libs.protobufLite.get())).getSingleFile())) { - exclude("**/*.proto") - } - - from files(variant.javaCompileProvider.get().destinationDir) - dependsOn variant.javaCompileProvider.get() - } - - def exportConfiguration = configurations.register("export${suffix}") - artifacts.add(exportConfiguration.name, exportJarTask.flatMap { it.archiveFile }) -} - androidx { mavenVersion = LibraryVersions.APPSEARCH } diff --git a/java/src/com/google/android/icing/IcingSearchEngine.java b/java/src/com/google/android/icing/IcingSearchEngine.java index 47b94a5..79fcdb8 100644 --- a/java/src/com/google/android/icing/IcingSearchEngine.java +++ b/java/src/com/google/android/icing/IcingSearchEngine.java @@ -77,6 +77,7 @@ public class IcingSearchEngine implements IcingSearchEngineInterface { icingSearchEngineImpl.close(); } + @SuppressWarnings("deprecation") @Override protected void finalize() throws Throwable { icingSearchEngineImpl.close(); diff --git a/java/src/com/google/android/icing/IcingSearchEngineImpl.java b/java/src/com/google/android/icing/IcingSearchEngineImpl.java index 8e79a88..57744c4 100644 --- a/java/src/com/google/android/icing/IcingSearchEngineImpl.java +++ b/java/src/com/google/android/icing/IcingSearchEngineImpl.java @@ -71,6 +71,7 @@ public class IcingSearchEngineImpl implements Closeable { closed = true; } + @SuppressWarnings("deprecation") @Override protected void finalize() throws Throwable { close(); -- cgit v1.2.3