blob: 28112ab97797232934d8cbb2c981e30b413791d6 [file] [log] [blame]
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* This file was created using the `create_project.py` script located in the
* `<AndroidX root>/development/project-creator` directory.
*
* Please use that script when creating a new project, rather than copying an existing project and
* modifying its settings.
*/
import androidx.build.KotlinTarget
import androidx.build.SoftwareType
import androidx.build.PlatformIdentifier
import com.android.build.api.dsl.KotlinMultiplatformAndroidHostTestCompilation
import com.android.build.gradle.internal.lint.AndroidLintAnalysisTask
import com.android.build.gradle.internal.lint.LintModelWriterTask
import com.google.devtools.ksp.gradle.KspAATask
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlin.konan.target.Family
plugins {
id("AndroidXPlugin")
id("androidx.stableaidl")
id("com.google.devtools.ksp")
}
configurations {
// Configuration for resolving shared archive file of androidx's SQLite compilation
sqliteSharedArchive {
canBeConsumed = false
canBeResolved = true
attributes {
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, Usage.NATIVE_LINK))
}
}
}
androidXMultiplatform {
androidLibrary {
withJava()
namespace = "androidx.room3"
optimization {
it.consumerKeepRules.publish = true
it.consumerKeepRules.files.add(
new File(project.projectDir, "src/androidMain/proguard-rules.pro")
)
}
stableAidl {
version = 1
}
compilations.withType(KotlinMultiplatformAndroidHostTestCompilation) {
it.returnDefaultValues = true
}
// Needed for api tasks and docs generation
sourceSets {
androidMain {
kotlin.srcDirs += 'src/androidMain/java'
}
}
}
ios() {
// Link to sqlite3 available in iOS
binaries.configureEach {
linkerOpts += ["-lsqlite3"]
}
}
jvm()
linux()
mac()
tvos()
watchos()
defaultPlatform(PlatformIdentifier.ANDROID)
// Source set structure:
// ┌──────────────────┐
// │ commonMain │
// └──────────────────┘
// │
// ┌──────────────┴─────────────┐
// │ │
// ▼ ▼
// ┌──────────────────┐ ┌──────────────────┐
// │ jvmAndroidMain │ │ jvmNativeMain │
// └──────────────────┘ └──────────────────┘
// │ │
// ┌───────────┴──────────────┬─────────────┴───────────┐
// │ │ │
// ▼ ▼ ▼
// ┌──────────────────┐ ┌──────────────────┐ ┌──────────────────┐
// │ androidMain │ │ jvmMain │ │ nativeMain │
// └──────────────────┘ └──────────────────┘ └──────────────────┘
sourceSets {
commonMain {
dependencies {
api(project(":room3:room3-common"))
api(project(":sqlite:sqlite"))
api("androidx.collection:collection:1.5.0")
api("androidx.annotation:annotation:1.9.1")
api(libs.kotlinCoroutinesCore)
}
}
commonTest {
dependencies {
implementation(libs.kotlinTest)
implementation(libs.kotlinCoroutinesTest)
implementation(project(":kruth:kruth"))
}
}
jvmAndroidMain {
dependsOn(commonMain)
}
jvmNativeMain {
dependsOn(commonMain)
}
jvmMain {
dependsOn(jvmAndroidMain)
dependsOn(jvmNativeMain)
}
jvmTest {
dependsOn(commonTest)
dependencies {
implementation(project(":sqlite:sqlite-bundled"))
implementation(libs.kotlinTestJunit)
}
}
androidMain {
dependsOn(jvmAndroidMain)
dependencies {
api(libs.jspecify)
api(project(":sqlite:sqlite-framework"))
api(libs.kotlinCoroutinesAndroid)
compileOnly("androidx.lifecycle:lifecycle-livedata:2.9.4")
implementation("androidx.annotation:annotation-experimental:1.5.0")
}
}
androidHostTest {
dependsOn(commonTest)
dependencies {
implementation("androidx.arch.core:core-testing:2.2.0")
implementation(libs.junit)
implementation(libs.byteBuddy)
implementation(libs.mockitoCore4)
implementation(libs.mockitoKotlin4)
implementation("androidx.lifecycle:lifecycle-livedata-core:2.0.0")
implementation(libs.testRunner) // Needed for @FlakyTest and @Ignore
}
}
androidDeviceTest {
dependsOn(commonTest)
dependencies {
implementation(project(":sqlite:sqlite-bundled"))
implementation(libs.junit)
implementation(libs.testExtJunit)
implementation(libs.testCore)
implementation(libs.testRunner)
implementation(libs.espressoCore)
implementation(libs.mockitoCore)
implementation(libs.dexmakerMockito)
implementation(project(":internal-testutils-truth")) // for assertThrows
implementation(project(":kruth:kruth"))
implementation("androidx.arch.core:core-testing:2.2.0")
}
}
nativeMain {
dependsOn(jvmNativeMain)
dependencies {
api(project(":sqlite:sqlite-framework"))
implementation(libs.atomicFu)
}
}
nativeTest {
dependsOn(commonTest)
dependencies {
implementation(project(":sqlite:sqlite-bundled"))
implementation(libs.okio)
}
}
targets.configureEach { target ->
if (target.platformType == KotlinPlatformType.native) {
target.compilations["main"].defaultSourceSet {
dependsOn(nativeMain)
}
def test = target.compilations["test"]
test.defaultSourceSet {
dependsOn(nativeTest)
}
if (target.konanTarget.family == Family.LINUX) {
// For tests in Linux host, statically include androidx's compiled SQLite
// via a generated C interop definition
createCinteropFromArchiveConfiguration(test, configurations["sqliteSharedArchive"])
} else if (target.konanTarget.family == Family.OSX) {
// For tests in Mac host, link to shared SQLite library included in MacOS
test.kotlinOptions.freeCompilerArgs += [
"-linker-options", "-lsqlite3"
]
}
}
}
}
}
dependencies {
sqliteSharedArchive(project(":sqlite:sqlite-bundled"))
add("kspAndroidDeviceTest", project(":room3:room3-compiler"))
}
androidx {
name = "Room-Runtime"
type = SoftwareType.PUBLISHED_LIBRARY
inceptionYear = "2017"
description = "Android Room-Runtime"
kotlinTarget = KotlinTarget.KOTLIN_2_1
}
// TODO(https://github.com/google/ksp/issues/2250) Remove when KSP migrates to the new variants API
// Without this, dependency introduced between lintAnalyzeAndroidDeviceTest and kspAndroidDeviceTest
tasks.withType(AndroidLintAnalysisTask).configureEach {
mustRunAfter(tasks.withType(KspAATask))
}
// TODO(https://github.com/google/ksp/issues/2250) Remove when KSP migrates to the new variants API
// Without this, dependency introduced between lintAnalyzeAndroidDeviceTest and kspAndroidDeviceTest
tasks.withType(LintModelWriterTask).configureEach {
mustRunAfter(tasks.withType(KspAATask))
}
// TODO(b/430983364): Workaround KSP incremental issue
tasks.withType(KotlinCompile).configureEach {
incremental = false
}
tasks.withType(KspAATask).configureEach {
it.kspConfig.incremental.set(false)
}
// b/446711395
// IDE Sync only error:
// Reason: Task ':sqlite:sqlite-framework:linuxArm64TestCinterop-sqliteSharedArchiveKlib' uses this output of task ':sqlite:sqlite-framework:cinteropTestSqliteSharedArchiveLinuxArm64'
// without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.
tasks.withType(Zip).configureEach {
if (name == "linuxX64TestCinterop-sqliteSharedArchiveKlib") {
mustRunAfter(tasks.named("cinteropTestSqliteSharedArchiveLinuxX64"))
}
if (name == "linuxArm64TestCinterop-sqliteSharedArchiveKlib") {
mustRunAfter(tasks.named("cinteropTestSqliteSharedArchiveLinuxArm64"))
}
}