Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ import com.android.build.gradle.internal.packaging.getDefaultDebugKeystoreSignin
import com.android.build.gradle.internal.profile.AnalyticsService
import com.android.build.gradle.internal.publishing.AarOrJarTypeToConsume
import com.android.build.gradle.internal.publishing.AndroidArtifacts
import com.android.build.gradle.internal.res.namespaced.AutoNamespacePreProcessTransform
import com.android.build.gradle.internal.res.namespaced.AutoNamespaceTransform
import com.android.build.gradle.internal.scope.InternalArtifactType
import com.android.build.gradle.internal.services.AndroidLocationsBuildService
import com.android.build.gradle.internal.services.ProjectServices
Expand Down Expand Up @@ -155,22 +153,14 @@ class DependencyConfigurator(
}

fun configureGeneralTransforms(
namespacedAndroidResources: Boolean,
aarOrJarTypeToConsume: AarOrJarTypeToConsume
): DependencyConfigurator {
val dependencies: DependencyHandler = project.dependencies

val projectOptions = projectServices.projectOptions

// The aars/jars may need to be processed (e.g., jetified to AndroidX) before they can be
// used
val autoNamespaceDependencies =
namespacedAndroidResources && projectOptions[BooleanOption.CONVERT_NON_NAMESPACED_DEPENDENCIES]
val jetifiedAarOutputType = if (autoNamespaceDependencies) {
AndroidArtifacts.ArtifactType.MAYBE_NON_NAMESPACED_PROCESSED_AAR
} else {
AndroidArtifacts.ArtifactType.PROCESSED_AAR
}
val jetifiedAarOutputType = AndroidArtifacts.ArtifactType.PROCESSED_AAR

// Arguments passed to an ArtifactTransform must not be null
val jetifierIgnoreList = projectOptions[StringOption.JETIFIER_IGNORE_LIST] ?: ""
if (projectOptions.get(BooleanOption.ENABLE_JETIFIER)) {
Expand All @@ -188,17 +178,10 @@ class DependencyConfigurator(
) { params ->
params.ignoreListOption.setDisallowChanges(jetifierIgnoreList)
}
} else if (autoNamespaceDependencies) {
// Namespaced resources code path is not optimized. Identity transforms are removed
// otherwise.
} else if (projectOptions[BooleanOption.ENABLE_IDENTITY_TRANSFORMS_FOR_PROCESSED_ARTIFACTS]) {
// These should not be needed in most scenarios now, but keeping the option for
// backwards compatibility.
registerIdentityTransformWhenJetifierIsDisabled(jetifiedAarOutputType)
} else {
// Still register the transform if/when dagger plugin is applied
// TODO(b/288221106): Dagger plugin depends on our internal implementation,
// we need to eliminate their dependency on this to be able to remove the following.
project.plugins.withId("dagger.hilt.android.plugin") {
registerIdentityTransformWhenJetifierIsDisabled(jetifiedAarOutputType)
}
}

registerTransform(
Expand Down Expand Up @@ -281,6 +264,9 @@ class DependencyConfigurator(
spec.parameters.projectName.setDisallowChanges(project.name)
spec.parameters.targetType.setDisallowChanges(transformTarget)
spec.parameters.namespacedSharedLibSupport.setDisallowChanges(namespacedSharedLibSupport)
spec.parameters.filterOutGlobalRules.setDisallowChanges(
projectOptions[BooleanOption.R8_GLOBAL_OPTIONS_IN_CONSUMER_RULES_DISALLOWED]
)
}
}
if (projectOptions[BooleanOption.PRECOMPILE_DEPENDENCIES_RESOURCES]) {
Expand Down Expand Up @@ -353,37 +339,19 @@ class DependencyConfigurator(
ExtractProGuardRulesTransform::class.java,
aarOrJarTypeToConsume.jar,
AndroidArtifacts.ArtifactType.UNFILTERED_PROGUARD_RULES
)
) { params ->
params.filterOutGlobalRules.set(
projectServices.projectOptions.get(
BooleanOption.R8_GLOBAL_OPTIONS_IN_CONSUMER_RULES_DISALLOWED
)
)
}
}
registerTransform(
LibrarySymbolTableTransform::class.java,
AndroidArtifacts.ArtifactType.EXPLODED_AAR,
AndroidArtifacts.ArtifactType.SYMBOL_LIST_WITH_PACKAGE_NAME
)
if (autoNamespaceDependencies) {
registerTransform(
AutoNamespacePreProcessTransform::class.java,
AndroidArtifacts.ArtifactType.MAYBE_NON_NAMESPACED_PROCESSED_AAR,
AndroidArtifacts.ArtifactType.PREPROCESSED_AAR_FOR_AUTO_NAMESPACE
) { params ->
projectServices.initializeAapt2Input(params.aapt2, task = null)
}
registerTransform(
AutoNamespacePreProcessTransform::class.java,
AndroidArtifacts.ArtifactType.JAR,
AndroidArtifacts.ArtifactType.PREPROCESSED_AAR_FOR_AUTO_NAMESPACE
) { params ->
projectServices.initializeAapt2Input(params.aapt2, task = null)
}

registerTransform(
AutoNamespaceTransform::class.java,
AndroidArtifacts.ArtifactType.PREPROCESSED_AAR_FOR_AUTO_NAMESPACE,
AndroidArtifacts.ArtifactType.PROCESSED_AAR
) { params ->
projectServices.initializeAapt2Input(params.aapt2, task = null)
}
}
// Transform to go from external jars to CLASSES and JAVA_RES artifacts. This returns the
// same exact file but with different types, since a jar file can contain both.
for (classesOrResources in arrayOf(
Expand Down
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
plugins {
alias(libs.plugins.android.library) apply false
alias(libs.plugins.kotlin.jvm) apply false
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.publish)
alias(libs.plugins.spotless)
alias(libs.plugins.wire) apply false
Expand Down
2 changes: 2 additions & 0 deletions gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import com.google.devtools.ksp.gradle.KspAATask
import com.google.devtools.ksp.gradle.KspTaskJvm
import com.squareup.wire.gradle.WireTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
Expand Down Expand Up @@ -73,6 +74,7 @@ val KOTLIN_VERSION = "${libs.versions.kotlin.get()}"

tasks.withType(KotlinCompile).configureEach { dependsOn(pluginVersion) }
tasks.withType(KspTaskJvm).configureEach { dependsOn(pluginVersion) }
tasks.withType(KspAATask).configureEach { dependsOn(pluginVersion) }

wire {
kotlin {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import org.gradle.api.attributes.Attribute
import org.gradle.api.attributes.Usage
import org.gradle.api.file.Directory
import org.gradle.api.tasks.TaskProvider
import org.gradle.configurationcache.extensions.capitalized
import org.gradle.internal.extensions.stdlib.capitalized
import org.gradle.process.CommandLineArgumentProvider

@Suppress("UnstableApiUsage")
Expand Down Expand Up @@ -190,7 +190,7 @@ class BetterDynamicFeaturesPlugin : Plugin<Project> {

private fun Project.createSharedBaseConfiguration(): Configuration = configurations.create(CONFIGURATION_BDF).apply {
isCanBeConsumed = true
isCanBeResolved = true
isCanBeResolved = false
isVisible = false

attributes.apply {
Expand Down Expand Up @@ -226,6 +226,21 @@ class BetterDynamicFeaturesPlugin : Plugin<Project> {
// This allows us to access artifacts created in this project's tasks via the artifactView APIs
dependencies.add(CONFIGURATION_BDF, this)

// Create a separate resolvable configuration for consuming the dependency graphs
val resolvableConfiguration = configurations.create("${CONFIGURATION_BDF}Resolvable").apply {
isCanBeConsumed = false
isCanBeResolved = true
isVisible = false
extendsFrom(configuration)

attributes.apply {
attribute(
Usage.USAGE_ATTRIBUTE,
project.objects.named(Usage::class.java, ATTRIBUTE_USAGE_METADATA),
)
}
}

androidComponents.onVariants { variant ->
val task = configureDependencyGraphTask(variant)
configuration.outgoing.variants.getByName(VARIANT_DEPENDENCY_GRAPHS) { configurationVariant ->
Expand All @@ -236,13 +251,13 @@ class BetterDynamicFeaturesPlugin : Plugin<Project> {
}
}

val featureDependencyArtifacts = configuration.incoming.artifactView { config ->
val featureDependencyArtifacts = resolvableConfiguration.incoming.artifactView { config ->
config.attributes { container ->
container.attribute(ARTIFACT_TYPE, ARTIFACT_TYPE_FEATURE_DEPENDENCY_GRAPH)
}
}.artifacts.artifactFiles

val baseDependencyArtifacts = configuration.incoming.artifactView { config ->
val baseDependencyArtifacts = resolvableConfiguration.incoming.artifactView { config ->
config.attributes { container ->
container.attribute(ARTIFACT_TYPE, ARTIFACT_TYPE_BASE_DEPENDENCY_GRAPH)
}
Expand Down Expand Up @@ -455,7 +470,7 @@ class BetterDynamicFeaturesPlugin : Plugin<Project> {
) { task ->
task.generatedSources.set(implementationsTask.flatMap { it.generatedFilesDirectory })
val compileConfiguration = setupVariantCodegenDependencies(androidVariant.buildType!!)
task.compileClasspath.setFrom(project.provider { compileConfiguration.resolvedConfiguration.files })
task.compileClasspath.setFrom(project.provider { compileConfiguration.files })
task.kotlinCompiler.from(resolvableKotlinCompilerConfiguration)
}

Expand Down
10 changes: 4 additions & 6 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[versions]
agp = "8.13.0" # keep in sync with android-tools
android-tools = "31.13.0" # = 23.0.0 + agp
agp = "9.0.0-alpha14" # keep in sync with android-tools
android-tools = "32.0.0-alpha14" # = 23.0.0 + agp
compilerTesting = "0.7.1"
kotlin = "2.1.20"
kotlin = "2.2.20"
kotlinPoet = "1.13.1"
ksp = "2.1.20-1.0.32"
ksp = "2.2.20-2.0.4"
ktlint = "1.7.1"
moshi = "1.15.2"

Expand Down Expand Up @@ -51,8 +51,6 @@ android-application = { id = "com.android.application", version.ref = "agp" }
android-dynamic-feature = { id = "com.android.dynamic-feature", version.ref = "agp" }
android-library = { id = "com.android.library", version.ref = "agp" }
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
publish = { id = "com.vanniktech.maven.publish", version = "0.34.0" }
spotless = { id = "com.diffplug.spotless", version = "8.0.0" }
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.0-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
1 change: 0 additions & 1 deletion runtime/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.publish)
alias(libs.plugins.spotless)
}
Expand Down
Loading