@@ -39,6 +39,7 @@ import com.android.build.gradle.internal.dependency.AndroidXDependencySubstituti
39
39
import com.android.build.gradle.internal.dependency.AsmClassesTransform.Companion.registerAsmTransformForComponent
40
40
import com.android.build.gradle.internal.dependency.ClassesDirToClassesTransform
41
41
import com.android.build.gradle.internal.dependency.CollectClassesTransform
42
+ import com.android.build.gradle.internal.dependency.CollectPackagesForR8Transform
42
43
import com.android.build.gradle.internal.dependency.CollectResourceSymbolsTransform
43
44
import com.android.build.gradle.internal.dependency.DexingRegistration
44
45
import com.android.build.gradle.internal.dependency.EnumerateClassesTransform
@@ -133,7 +134,6 @@ class DependencyConfigurator(
133
134
}
134
135
return this
135
136
}
136
-
137
137
fun configureDependencyChecks (): DependencyConfigurator {
138
138
val useAndroidX = projectServices.projectOptions.get(BooleanOption .USE_ANDROID_X )
139
139
val enableJetifier = projectServices.projectOptions.get(BooleanOption .ENABLE_JETIFIER )
@@ -165,7 +165,6 @@ class DependencyConfigurator(
165
165
// used
166
166
val autoNamespaceDependencies =
167
167
namespacedAndroidResources && projectOptions[BooleanOption .CONVERT_NON_NAMESPACED_DEPENDENCIES ]
168
-
169
168
val jetifiedAarOutputType = if (autoNamespaceDependencies) {
170
169
AndroidArtifacts .ArtifactType .MAYBE_NON_NAMESPACED_PROCESSED_AAR
171
170
} else {
@@ -450,6 +449,19 @@ class DependencyConfigurator(
450
449
AndroidArtifacts .ArtifactType .JAR_CLASS_LIST
451
450
)
452
451
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
+
453
465
return this
454
466
}
455
467
@@ -472,7 +484,7 @@ class DependencyConfigurator(
472
484
compileSdkHashString : String ,
473
485
buildToolsRevision : Revision ,
474
486
bootstrapCreationConfig : BootClasspathConfig ,
475
- variants : List < VariantCreationConfig > = emptyList()
487
+ privacySandboxExperimentalProperties : Map < String , Any > ?
476
488
)
477
489
: DependencyConfigurator {
478
490
for (from in AsarTransform .supportedAsarTransformTypes) {
@@ -485,11 +497,11 @@ class DependencyConfigurator(
485
497
}
486
498
}
487
499
488
- fun configureExtractSdkShimTransforms (experimentalProperties : Map <String , Any >? ) {
500
+ fun configureExtractSdkShimTransforms (privacySandboxSdkProperties : Map <String , Any >? ) {
489
501
val extractSdkShimTransformParamConfig =
490
502
{ reg: TransformSpec <ExtractSdkShimTransform .Parameters > ->
491
503
val experimentalPropertiesApiGenerator: Dependency ? =
492
- experimentalProperties ?.let {
504
+ privacySandboxSdkProperties ?.let {
493
505
ModulePropertyKey .Dependencies .ANDROID_PRIVACY_SANDBOX_SDK_API_GENERATOR
494
506
.getValue(it)?.single()
495
507
}
@@ -501,7 +513,7 @@ class DependencyConfigurator(
501
513
) as Dependency
502
514
503
515
val experimentalPropertiesRuntimeApigeneratorDependencies =
504
- experimentalProperties ?.let {
516
+ privacySandboxSdkProperties ?.let {
505
517
ModulePropertyKey .Dependencies .ANDROID_PRIVACY_SANDBOX_SDK_API_GENERATOR_GENERATED_RUNTIME_DEPENDENCIES .getValue(
506
518
it
507
519
)
@@ -535,17 +547,18 @@ class DependencyConfigurator(
535
547
task = null ,
536
548
projectServices.buildServiceRegistry,
537
549
compileSdkHashString,
538
- buildToolsRevision)
550
+ buildToolsRevision
551
+ )
539
552
540
553
// For kotlin compilation
541
554
params.bootstrapClasspath.from(bootstrapCreationConfig.fullBootClasspath)
542
555
543
556
val kotlinEmbeddableCompiler =
544
- experimentalProperties ?.let {
557
+ privacySandboxSdkProperties ?.let {
545
558
ModulePropertyKey .Dependencies .ANDROID_PRIVACY_SANDBOX_SDK_KOTLIN_COMPILER_EMBEDDABLE .getValue(
546
559
it
547
560
)?.single()
548
- } as Dependency ?
561
+ }
549
562
val kotlinCompiler: Configuration =
550
563
project.configurations.detachedConfiguration(
551
564
kotlinEmbeddableCompiler ? : project.dependencies.create(
@@ -557,25 +570,34 @@ class DependencyConfigurator(
557
570
kotlinCompiler.isCanBeResolved = true
558
571
params.kotlinCompiler.from(kotlinCompiler)
559
572
params.requireServices.set(
560
- projectServices.projectOptions[BooleanOption .PRIVACY_SANDBOX_SDK_REQUIRE_SERVICES ])
573
+ projectServices.projectOptions[BooleanOption .PRIVACY_SANDBOX_SDK_REQUIRE_SERVICES ]
574
+ )
561
575
val configuration = project.configurations.detachedConfiguration(
562
- * runtimeDependenciesForShimSdk.toTypedArray())
576
+ * runtimeDependenciesForShimSdk.toTypedArray()
577
+ )
563
578
configuration.isCanBeConsumed = false
564
579
configuration.isCanBeResolved = true
565
580
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
+ }
579
601
}.artifacts.artifactFiles)
580
602
}
581
603
@@ -607,20 +629,7 @@ class DependencyConfigurator(
607
629
registerExtractSdkShimTransform(Usage .JAVA_RUNTIME )
608
630
}
609
631
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)
624
633
625
634
return this
626
635
}
0 commit comments