@@ -39,6 +39,7 @@ import com.android.build.gradle.internal.dependency.AndroidXDependencySubstituti
3939import com.android.build.gradle.internal.dependency.AsmClassesTransform.Companion.registerAsmTransformForComponent
4040import com.android.build.gradle.internal.dependency.ClassesDirToClassesTransform
4141import com.android.build.gradle.internal.dependency.CollectClassesTransform
42+ import com.android.build.gradle.internal.dependency.CollectPackagesForR8Transform
4243import com.android.build.gradle.internal.dependency.CollectResourceSymbolsTransform
4344import com.android.build.gradle.internal.dependency.DexingRegistration
4445import com.android.build.gradle.internal.dependency.EnumerateClassesTransform
@@ -133,7 +134,6 @@ class DependencyConfigurator(
133134 }
134135 return this
135136 }
136-
137137 fun configureDependencyChecks (): DependencyConfigurator {
138138 val useAndroidX = projectServices.projectOptions.get(BooleanOption .USE_ANDROID_X )
139139 val enableJetifier = projectServices.projectOptions.get(BooleanOption .ENABLE_JETIFIER )
@@ -165,7 +165,6 @@ class DependencyConfigurator(
165165 // used
166166 val autoNamespaceDependencies =
167167 namespacedAndroidResources && projectOptions[BooleanOption .CONVERT_NON_NAMESPACED_DEPENDENCIES ]
168-
169168 val jetifiedAarOutputType = if (autoNamespaceDependencies) {
170169 AndroidArtifacts .ArtifactType .MAYBE_NON_NAMESPACED_PROCESSED_AAR
171170 } else {
@@ -450,6 +449,19 @@ class DependencyConfigurator(
450449 AndroidArtifacts .ArtifactType .JAR_CLASS_LIST
451450 )
452451
452+ if (projectOptions[BooleanOption .GRADUAL_R8_SHRINKING ]) {
453+ registerTransform(
454+ CollectPackagesForR8Transform ::class .java,
455+ AndroidArtifacts .ArtifactType .EXPLODED_AAR ,
456+ AndroidArtifacts .ArtifactType .PACKAGES_FOR_R8
457+ )
458+ registerTransform(
459+ CollectPackagesForR8Transform ::class .java,
460+ aarOrJarTypeToConsume.jar,
461+ AndroidArtifacts .ArtifactType .PACKAGES_FOR_R8
462+ )
463+ }
464+
453465 return this
454466 }
455467
@@ -472,7 +484,7 @@ class DependencyConfigurator(
472484 compileSdkHashString : String ,
473485 buildToolsRevision : Revision ,
474486 bootstrapCreationConfig : BootClasspathConfig ,
475- variants : List < VariantCreationConfig > = emptyList()
487+ privacySandboxExperimentalProperties : Map < String , Any > ?
476488 )
477489 : DependencyConfigurator {
478490 for (from in AsarTransform .supportedAsarTransformTypes) {
@@ -485,11 +497,11 @@ class DependencyConfigurator(
485497 }
486498 }
487499
488- fun configureExtractSdkShimTransforms (experimentalProperties : Map <String , Any >? ) {
500+ fun configureExtractSdkShimTransforms (privacySandboxSdkProperties : Map <String , Any >? ) {
489501 val extractSdkShimTransformParamConfig =
490502 { reg: TransformSpec <ExtractSdkShimTransform .Parameters > ->
491503 val experimentalPropertiesApiGenerator: Dependency ? =
492- experimentalProperties ?.let {
504+ privacySandboxSdkProperties ?.let {
493505 ModulePropertyKey .Dependencies .ANDROID_PRIVACY_SANDBOX_SDK_API_GENERATOR
494506 .getValue(it)?.single()
495507 }
@@ -501,7 +513,7 @@ class DependencyConfigurator(
501513 ) as Dependency
502514
503515 val experimentalPropertiesRuntimeApigeneratorDependencies =
504- experimentalProperties ?.let {
516+ privacySandboxSdkProperties ?.let {
505517 ModulePropertyKey .Dependencies .ANDROID_PRIVACY_SANDBOX_SDK_API_GENERATOR_GENERATED_RUNTIME_DEPENDENCIES .getValue(
506518 it
507519 )
@@ -535,17 +547,18 @@ class DependencyConfigurator(
535547 task = null ,
536548 projectServices.buildServiceRegistry,
537549 compileSdkHashString,
538- buildToolsRevision)
550+ buildToolsRevision
551+ )
539552
540553 // For kotlin compilation
541554 params.bootstrapClasspath.from(bootstrapCreationConfig.fullBootClasspath)
542555
543556 val kotlinEmbeddableCompiler =
544- experimentalProperties ?.let {
557+ privacySandboxSdkProperties ?.let {
545558 ModulePropertyKey .Dependencies .ANDROID_PRIVACY_SANDBOX_SDK_KOTLIN_COMPILER_EMBEDDABLE .getValue(
546559 it
547560 )?.single()
548- } as Dependency ?
561+ }
549562 val kotlinCompiler: Configuration =
550563 project.configurations.detachedConfiguration(
551564 kotlinEmbeddableCompiler ? : project.dependencies.create(
@@ -557,25 +570,34 @@ class DependencyConfigurator(
557570 kotlinCompiler.isCanBeResolved = true
558571 params.kotlinCompiler.from(kotlinCompiler)
559572 params.requireServices.set(
560- projectServices.projectOptions[BooleanOption .PRIVACY_SANDBOX_SDK_REQUIRE_SERVICES ])
573+ projectServices.projectOptions[BooleanOption .PRIVACY_SANDBOX_SDK_REQUIRE_SERVICES ]
574+ )
561575 val configuration = project.configurations.detachedConfiguration(
562- * runtimeDependenciesForShimSdk.toTypedArray())
576+ * runtimeDependenciesForShimSdk.toTypedArray()
577+ )
563578 configuration.isCanBeConsumed = false
564579 configuration.isCanBeResolved = true
565580
566- configuration.attributes {
567- it.attribute(BuildTypeAttr .ATTRIBUTE ,
568- project.objects.named(BuildTypeAttr ::class .java,
569- BuilderConstants .RELEASE ))
570- }
571- params.runtimeDependencies.from(configuration.incoming.artifactView {
572- config: ArtifactView .ViewConfiguration ->
573- config.attributes.apply {
574- attribute(Usage .USAGE_ATTRIBUTE ,
575- project.objects.named(Usage ::class .java, Usage .JAVA_API ))
576- attribute(AndroidArtifacts .ARTIFACT_TYPE ,
577- AndroidArtifacts .ArtifactType .CLASSES_JAR .type)
578- }
581+ configuration.attributes {
582+ it.attribute(
583+ BuildTypeAttr .ATTRIBUTE ,
584+ project.objects.named(
585+ BuildTypeAttr ::class .java,
586+ BuilderConstants .RELEASE
587+ )
588+ )
589+ }
590+ params.runtimeDependencies.from(configuration.incoming.artifactView { config: ArtifactView .ViewConfiguration ->
591+ config.attributes.apply {
592+ attribute(
593+ Usage .USAGE_ATTRIBUTE ,
594+ project.objects.named(Usage ::class .java, Usage .JAVA_API )
595+ )
596+ attribute(
597+ AndroidArtifacts .ARTIFACT_TYPE ,
598+ AndroidArtifacts .ArtifactType .CLASSES_JAR .type
599+ )
600+ }
579601 }.artifacts.artifactFiles)
580602 }
581603
@@ -607,20 +629,7 @@ class DependencyConfigurator(
607629 registerExtractSdkShimTransform(Usage .JAVA_RUNTIME )
608630 }
609631
610- val properties = variants.map { variant ->
611- variant.experimentalProperties.also { it.disallowChanges() }.get().filterKeys {
612- it == ModulePropertyKey .Dependencies .ANDROID_PRIVACY_SANDBOX_SDK_API_GENERATOR_GENERATED_RUNTIME_DEPENDENCIES .key ||
613- it == ModulePropertyKey .Dependencies .ANDROID_PRIVACY_SANDBOX_SDK_API_GENERATOR .key
614- }
615- }.distinct()
616-
617- if (properties.count() > 1 ) {
618- error(
619- " It is not possible to override Privacy Sandbox experimental properties per variant.\n " +
620- " Properties with different values defined across multiple variants: ${properties.joinToString()} "
621- )
622- }
623- configureExtractSdkShimTransforms(properties.singleOrNull())
632+ configureExtractSdkShimTransforms(privacySandboxExperimentalProperties)
624633
625634 return this
626635 }
0 commit comments