From c557f74ad371d4dd7802a092a2f13a7da3aa02a3 Mon Sep 17 00:00:00 2001 From: Eric Labelle <2840799+eric-labelle@users.noreply.github.com> Date: Tue, 2 Jul 2024 16:02:41 -0400 Subject: [PATCH] Bump to AGP 8.5.x (#123) * Bump to AGP 8.5.x * Update copy of DexingTransform.kt * Update copy of DependencyConfigurator.kt --- .../gradle/internal/DependencyConfigurator.kt | 18 +++-- .../internal/dependency/DexingTransform.kt | 81 +++++++++++++------ gradle/libs.versions.toml | 4 +- 3 files changed, 71 insertions(+), 32 deletions(-) diff --git a/agp-patch/src/main/kotlin/com/android/build/gradle/internal/DependencyConfigurator.kt b/agp-patch/src/main/kotlin/com/android/build/gradle/internal/DependencyConfigurator.kt index 11b0421..a4c66d4 100644 --- a/agp-patch/src/main/kotlin/com/android/build/gradle/internal/DependencyConfigurator.kt +++ b/agp-patch/src/main/kotlin/com/android/build/gradle/internal/DependencyConfigurator.kt @@ -137,7 +137,7 @@ class DependencyConfigurator( val enableJetifier = projectServices.projectOptions.get(BooleanOption.ENABLE_JETIFIER) if (!useAndroidX && !enableJetifier) { - project.configurations.all { configuration -> + project.configurations.configureEach { configuration -> if (configuration.isCanBeResolved) { configuration.incoming.afterResolve( AndroidXDependencyCheck.AndroidXDisabledJetifierDisabled( @@ -401,7 +401,7 @@ class DependencyConfigurator( // The Kotlin Kapt plugin should query for PROCESSED_JAR, but it is currently querying for // JAR, so we need to have the workaround below to make it get PROCESSED_JAR. See // http://issuetracker.google.com/111009645. - project.configurations.all { configuration: Configuration -> + project.configurations.configureEach { configuration: Configuration -> if (configuration.name.startsWith("kapt")) { configuration .attributes @@ -495,7 +495,7 @@ class DependencyConfigurator( experimentalPropertiesApiGenerator ?: project.dependencies.create( projectServices.projectOptions.get(StringOption.ANDROID_PRIVACY_SANDBOX_SDK_API_GENERATOR) - ?: MavenCoordinates.ANDROIDX_PRIVACY_SANDBOX_SDK_API_GENERATOR.toString() + ?: MavenCoordinates.ANDROIDX_PRIVACYSANDBOX_TOOLS_TOOLS_APIGENERATOR.toString() ) as Dependency val experimentalPropertiesRuntimeApigeneratorDependencies = @@ -505,8 +505,14 @@ class DependencyConfigurator( ?: (projectServices.projectOptions .get(StringOption.ANDROID_PRIVACY_SANDBOX_SDK_API_GENERATOR_GENERATED_RUNTIME_DEPENDENCIES) ?.split(",") - ?: listOf(MavenCoordinates.ORG_JETBRAINS_KOTLINX_KOTLINX_COROUTINES_ANDROID.toString())).map { - project.dependencies.create(it) + ?: listOf( + MavenCoordinates.ORG_JETBRAINS_KOTLIN_KOTLIN_STDLIB.toString(), + MavenCoordinates.ORG_JETBRAINS_KOTLINX_KOTLINX_COROUTINES_ANDROID.toString(), + MavenCoordinates.ANDROIDX_PRIVACYSANDBOX_UI_UI_CORE.toString(), + MavenCoordinates.ANDROIDX_PRIVACYSANDBOX_UI_UI_CLIENT.toString(), + )) + .map { + project.dependencies.create(it) } val params = reg.parameters @@ -524,7 +530,7 @@ class DependencyConfigurator( params.bootstrapClasspath.from(bootstrapCreationConfig.fullBootClasspath) val kotlinCompiler = project.configurations.detachedConfiguration( - project.dependencies.create(MavenCoordinates.KOTLIN_COMPILER.toString()) + project.dependencies.create(MavenCoordinates.ORG_JETBRAINS_KOTLIN_KOTLIN_COMPILER_EMBEDDABLE.toString()) ) kotlinCompiler.isCanBeConsumed = false kotlinCompiler.isCanBeResolved = true diff --git a/agp-patch/src/main/kotlin/com/android/build/gradle/internal/dependency/DexingTransform.kt b/agp-patch/src/main/kotlin/com/android/build/gradle/internal/dependency/DexingTransform.kt index 06030b1..e4ce01e 100644 --- a/agp-patch/src/main/kotlin/com/android/build/gradle/internal/dependency/DexingTransform.kt +++ b/agp-patch/src/main/kotlin/com/android/build/gradle/internal/dependency/DexingTransform.kt @@ -22,8 +22,6 @@ package com.android.build.gradle.internal.dependency import com.android.build.gradle.internal.LoggerWrapper import com.android.build.gradle.internal.component.ApkCreationConfig import com.android.build.gradle.internal.component.ComponentCreationConfig -import com.android.build.gradle.internal.dexing.readDesugarGraph -import com.android.build.gradle.internal.dexing.writeDesugarGraph import com.android.build.gradle.internal.errors.MessageReceiverImpl import com.android.build.gradle.internal.publishing.AndroidArtifacts import com.android.build.gradle.internal.scope.Java8LangSupport @@ -42,6 +40,7 @@ import com.android.builder.dexing.isJarFile import com.android.builder.dexing.r8.ClassFileProviderFactory import com.android.builder.files.SerializableFileChanges import com.android.utils.FileUtils +import com.google.common.annotations.VisibleForTesting import com.google.common.hash.Hashing import com.google.common.io.Closer import org.gradle.api.artifacts.dsl.DependencyHandler @@ -69,6 +68,8 @@ import org.gradle.work.Incremental import org.gradle.work.InputChanges import org.slf4j.LoggerFactory import java.io.File +import java.io.ObjectInputStream +import java.io.ObjectOutputStream import java.nio.charset.StandardCharsets import javax.inject.Inject @@ -300,52 +301,70 @@ abstract class BaseDexingTransform : Transfo /** * Desugaring graph used for incremental dexing. It contains class files and their dependencies. * - * This graph handles files with absolute paths. To make it relocatable, it requires that all files - * in the graph share one single root directory ([rootDir]) so that they can be converted to - * relative paths. + * This graph handles files with absolute paths. To make it relocatable, this graph internally + * maintains a [relocatableDesugarGraph] which contains Unix-style relative paths of the files + * (the paths need to be *relative* and in *Unix style* so that they can be used across + * filesystems). When writing this graph to disk, we will write the [relocatableDesugarGraph]. * - * Internally, this graph maintains a [relocatableDesugarGraph] containing relative paths of the - * files. When writing this graph to disk, we will write the [relocatableDesugarGraph]. + * To make it easier to convert absolute paths to relative paths, we currently require that all + * files in the graph share one single root directory ([rootDir]). */ -private class DesugarGraph( +@VisibleForTesting +internal class DesugarGraph( /** The root directory that is shared among all files in the desugaring graph. */ private val rootDir: File, - /** The relocatable desugaring graph, which contains relative paths of the files. */ - private val relocatableDesugarGraph: MutableDependencyGraph = MutableDependencyGraph() + /** The relocatable desugaring graph, which contains Unix-style relative paths of the files. */ + private val relocatableDesugarGraph: MutableDependencyGraph = MutableDependencyGraph() ) : DependencyGraphUpdater { override fun addEdge(dependent: File, dependency: File) { relocatableDesugarGraph.addEdge( - dependent.relativeTo(rootDir), - dependency.relativeTo(rootDir) + dependent.toUnixStyleRelativePath(), + dependency.toUnixStyleRelativePath() ) } fun removeNode(nodeToRemove: File) { - relocatableDesugarGraph.removeNode(nodeToRemove.relativeTo(rootDir)) + relocatableDesugarGraph.removeNode(nodeToRemove.toUnixStyleRelativePath()) } fun getAllDependents(nodes: Collection): Set { - val relativePaths = nodes.mapTo(mutableSetOf()) { it.relativeTo(rootDir) } + val relativePaths = nodes.mapTo(mutableSetOf()) { it.toUnixStyleRelativePath() } val dependents = relocatableDesugarGraph.getAllDependents(relativePaths) return dependents.mapTo(mutableSetOf()) { rootDir.resolve(it) } } - fun write(relocatableDesugarGraphFile: File) { - writeDesugarGraph(relocatableDesugarGraphFile, relocatableDesugarGraph) + private fun File.toUnixStyleRelativePath(): String { + val unixStyleRelativePath = relativeTo(rootDir).invariantSeparatorsPath + + check(!unixStyleRelativePath.startsWith("..")) { + "The given file '$path' is located outside the root directory '${rootDir.path}'" + } + + return unixStyleRelativePath + } + + fun write(desugarGraphFile: File) { + ObjectOutputStream(desugarGraphFile.outputStream().buffered()).use { + it.writeObject(relocatableDesugarGraph) + } } companion object { - fun read(relocatableDesugarGraphFile: File, rootDir: File): DesugarGraph { + fun read(desugarGraphFile: File, rootDir: File): DesugarGraph { return DesugarGraph( - rootDir = rootDir, - relocatableDesugarGraph = readDesugarGraph(relocatableDesugarGraphFile) + rootDir = rootDir, + relocatableDesugarGraph = + ObjectInputStream(desugarGraphFile.inputStream().buffered()).use { + @Suppress("UNCHECKED_CAST") + it.readObject() as MutableDependencyGraph + } ) } } @@ -370,10 +389,21 @@ abstract class DexingWithClasspathTransform : BaseDexingTransform