1/* 2 * Copyright (C) 2016 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 */ 24 25 26import androidx.build.SoftwareType 27import androidx.build.PlatformIdentifier 28import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType 29import org.jetbrains.kotlin.konan.target.Family 30 31plugins { 32 id("AndroidXPlugin") 33 id("com.android.library") 34 id("androidx.stableaidl") 35 id("com.google.devtools.ksp") 36} 37 38 39configurations { 40 // Configuration for resolving shared archive file of androidx's SQLite compilation 41 sqliteSharedArchive { 42 canBeConsumed = false 43 canBeResolved = true 44 attributes { 45 attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, Usage.NATIVE_LINK)) 46 } 47 } 48} 49 50android { 51 sourceSets { 52 main { 53 // Align AGP main source set root with KMP 54 root = 'src/androidMain' 55 } 56 } 57 buildFeatures { 58 aidl = true 59 } 60 buildTypes.configureEach { 61 consumerProguardFiles("src/androidMain/proguard-rules.pro") 62 stableAidl { 63 version = 1 64 } 65 } 66 namespace = "androidx.room" 67 // TODO(b/345531033) 68 experimentalProperties["android.lint.useK2Uast"] = false 69} 70 71androidXMultiplatform { 72 androidTarget() 73 ios() { 74 // Link to sqlite3 available in iOS 75 binaries.configureEach { 76 linkerOpts += ["-lsqlite3"] 77 } 78 } 79 jvm() 80 linux() 81 mac() 82 83 defaultPlatform(PlatformIdentifier.ANDROID) 84 85 // Source set structure: 86 // ┌──────────────────┐ 87 // │ commonMain │ 88 // └──────────────────┘ 89 // │ 90 // ┌──────────────┴─────────────┐ 91 // │ │ 92 // ▼ ▼ 93 // ┌──────────────────┐ ┌──────────────────┐ 94 // │ jvmAndroidMain │ │ jvmNativeMain │ 95 // └──────────────────┘ └──────────────────┘ 96 // │ │ 97 // ┌───────────┴──────────────┬─────────────┴───────────┐ 98 // │ │ │ 99 // ▼ ▼ ▼ 100 // ┌──────────────────┐ ┌──────────────────┐ ┌──────────────────┐ 101 // │ androidMain │ │ jvmMain │ │ nativeMain │ 102 // └──────────────────┘ └──────────────────┘ └──────────────────┘ 103 sourceSets { 104 commonMain { 105 dependencies { 106 api(libs.kotlinStdlib) 107 api(project(":room:room-common")) 108 api(project(":sqlite:sqlite")) 109 api("androidx.collection:collection:1.4.2") 110 api("androidx.annotation:annotation:1.8.1") 111 api(libs.kotlinCoroutinesCore) 112 } 113 } 114 commonTest { 115 dependencies { 116 implementation(libs.kotlinTest) 117 implementation(libs.kotlinCoroutinesTest) 118 implementation(project(":kruth:kruth")) 119 } 120 } 121 jvmAndroidMain { 122 dependsOn(commonMain) 123 } 124 jvmNativeMain { 125 dependsOn(commonMain) 126 } 127 jvmMain { 128 dependsOn(jvmAndroidMain) 129 dependsOn(jvmNativeMain) 130 } 131 jvmTest { 132 dependsOn(commonTest) 133 dependencies { 134 implementation(project(":sqlite:sqlite-bundled")) 135 implementation(libs.kotlinTestJunit) 136 } 137 } 138 androidMain { 139 dependsOn(jvmAndroidMain) 140 dependencies { 141 api(libs.jspecify) 142 api(project(":sqlite:sqlite-framework")) 143 api(libs.kotlinCoroutinesAndroid) 144 implementation("androidx.arch.core:core-runtime:2.2.0") 145 compileOnly("androidx.lifecycle:lifecycle-livedata-core:2.0.0") 146 compileOnly("androidx.paging:paging-common:2.0.0") 147 implementation("androidx.annotation:annotation-experimental:1.4.1") 148 } 149 } 150 androidUnitTest { 151 dependsOn(commonTest) 152 dependencies { 153 implementation("androidx.arch.core:core-testing:2.2.0") 154 implementation(libs.junit) 155 implementation(libs.byteBuddy) 156 implementation(libs.mockitoCore4) 157 implementation(libs.mockitoKotlin4) 158 implementation("androidx.lifecycle:lifecycle-livedata-core:2.0.0") 159 implementation(libs.testRunner) // Needed for @FlakyTest and @Ignore 160 } 161 } 162 androidInstrumentedTest { 163 dependsOn(commonTest) 164 dependencies { 165 implementation(project(":sqlite:sqlite-bundled")) 166 implementation(libs.junit) 167 implementation(libs.testExtJunit) 168 implementation(libs.testCore) 169 implementation(libs.testRunner) 170 implementation(libs.espressoCore) 171 implementation(libs.mockitoCore) 172 implementation(libs.dexmakerMockito) 173 implementation(project(":internal-testutils-truth")) // for assertThrows 174 implementation(project(":kruth:kruth")) 175 implementation("androidx.arch.core:core-testing:2.2.0") 176 } 177 } 178 nativeMain { 179 dependsOn(jvmNativeMain) 180 dependencies { 181 api(project(":sqlite:sqlite-framework")) 182 implementation(libs.atomicFu) 183 } 184 } 185 nativeTest { 186 dependsOn(commonTest) 187 dependencies { 188 implementation(project(":sqlite:sqlite-bundled")) 189 implementation(libs.okio) 190 } 191 } 192 targets.configureEach { target -> 193 if (target.platformType == KotlinPlatformType.native) { 194 target.compilations["main"].defaultSourceSet { 195 dependsOn(nativeMain) 196 } 197 def test = target.compilations["test"] 198 test.defaultSourceSet { 199 dependsOn(nativeTest) 200 } 201 if (target.konanTarget.family == Family.LINUX) { 202 // For tests in Linux host, statically include androidx's compiled SQLite 203 // via a generated C interop definition 204 createCinteropFromArchiveConfiguration(test, configurations["sqliteSharedArchive"]) 205 } else if (target.konanTarget.family == Family.OSX) { 206 // For tests in Mac host, link to shared SQLite library included in MacOS 207 test.kotlinOptions.freeCompilerArgs += [ 208 "-linker-options", "-lsqlite3" 209 ] 210 } 211 } 212 } 213 } 214} 215 216dependencies { 217 lintChecks(project(":room:room-runtime-lint")) 218 sqliteSharedArchive(project(":sqlite:sqlite-bundled")) 219 add("kspAndroidAndroidTest", project(":room:room-compiler")) 220} 221 222androidx { 223 name = "Room-Runtime" 224 type = SoftwareType.PUBLISHED_LIBRARY 225 inceptionYear = "2017" 226 description = "Android Room-Runtime" 227 legacyDisableKotlinStrictApiMode = true 228 metalavaK2UastEnabled = false 229} 230 231