1/*
2 * Copyright (C) 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/**
18 * This file was created using the `create_project.py` script located in the
19 * `<AndroidX root>/development/project-creator` directory.
20 *
21 * Please use that script when creating a new project, rather than copying an existing project and
22 * modifying its settings.
23 */
24import androidx.build.SoftwareType
25import javax.inject.Inject
26
27plugins {
28    id("AndroidXPlugin")
29    id("com.android.library")
30    id("org.jetbrains.kotlin.android")
31}
32
33abstract class BundleTestSdkDexTask extends DefaultTask {
34
35    @InputFiles
36    @PathSensitive(PathSensitivity.NAME_ONLY)
37    abstract ConfigurableFileCollection getTestSdkApkFolders()
38
39    @OutputDirectory
40    abstract DirectoryProperty getOutputDir()
41
42    @Inject
43    abstract FileSystemOperations getFileSystemOperations()
44
45    @Inject
46    abstract ArchiveOperations getArchiveOperations()
47
48    @TaskAction
49    def exec() {
50        for (File folder : testSdkApkFolders.files) {
51            for (File file : folder.listFiles()) {
52                String fileName = file.name
53                if (!fileName.endsWith(".apk")) {
54                    continue
55                }
56
57                int projectNameEnd = fileName.indexOf("-")
58                String projectName = projectNameEnd > 0 ? fileName.substring(0, projectNameEnd) : fileName
59
60                fileSystemOperations.copy {
61                    from(archiveOperations.zipTree(file))
62                    into(outputDir.dir("test-sdks/$projectName/"))
63                    include('*.dex')
64                }
65            }
66        }
67    }
68}
69
70def bundleTestSdkDexTaskProvider = tasks.register("bundleTestSdkDexTask", BundleTestSdkDexTask) {
71    description = "Bundle DEX from the androidTestBundleDex configuration into assets folder"
72
73    def configuration = configurations.getByName("androidTestBundleDex")
74    testSdkApkFolders.from(configuration.incoming.artifactView {}.files)
75}
76
77androidComponents {
78    onVariants(selector().withBuildType("release")) {
79        androidTest.sources.assets.addGeneratedSourceDirectory(
80                bundleTestSdkDexTaskProvider,
81                BundleTestSdkDexTask::getOutputDir
82        )
83    }
84}
85
86configurations {
87    androidTestBundleDex {
88        canBeConsumed = false
89        canBeResolved = true
90        attributes {
91            attribute(
92                    LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE,
93                    objects.named(LibraryElements, "testSdkApk")
94            )
95        }
96    }
97}
98
99dependencies {
100    api(libs.kotlinStdlib)
101    api(libs.kotlinCoroutinesCore)
102    implementation("androidx.core:core-ktx:1.15.0")
103
104    api(project(":privacysandbox:sdkruntime:sdkruntime-core"))
105
106    implementation("androidx.core:core:1.15.0")
107    implementation("androidx.activity:activity:1.9.3")
108    implementation("androidx.lifecycle:lifecycle-process:2.8.7")
109
110    testImplementation(libs.junit)
111    testImplementation(libs.truth)
112    testImplementation(project(":room:room-compiler-processing-testing"))
113
114    // TODO(b/249982004): cleanup dependencies
115    androidTestImplementation(libs.testCore)
116    androidTestImplementation(libs.testExtJunit)
117    androidTestImplementation(libs.testRunner)
118    androidTestImplementation(libs.testRules)
119    androidTestImplementation(libs.truth)
120    androidTestImplementation(libs.junit)
121    androidTestImplementation(project(":internal-testutils-runtime"))
122    androidTestImplementation(project(":internal-testutils-truth")) // for assertThrows
123
124    androidTestImplementation(libs.mockitoCore)
125    androidTestImplementation(libs.dexmakerMockitoInline)
126
127    androidTestBundleDex(project(":privacysandbox:sdkruntime:test-sdks:current"))
128    androidTestBundleDex(project(":privacysandbox:sdkruntime:test-sdks:v6"))
129    androidTestBundleDex(project(":privacysandbox:sdkruntime:test-sdks:v7"))
130}
131
132android {
133    sourceSets {
134        androidTest {
135            assets {
136                srcDirs += "src/androidTest/assets"
137            }
138        }
139    }
140
141    namespace = "androidx.privacysandbox.sdkruntime.client"
142    compileSdk = 35
143    compileSdkExtension = 14
144}
145
146androidx {
147    name = "SdkRuntime Client"
148    type = SoftwareType.PUBLISHED_LIBRARY
149    inceptionYear = "2022"
150    description = "Provides components for SdkRuntime aware Applications"
151    legacyDisableKotlinStrictApiMode = true
152}
153