You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

222 lines
7.0 KiB

import kotlinx.validation.ExperimentalBCVApi
import org.jetbrains.compose.ExperimentalComposeLibrary
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
plugins {
kotlin("multiplatform")
id("org.jetbrains.compose")
id("maven-publish")
id("com.android.library")
id("org.jetbrains.kotlinx.binary-compatibility-validator")
}
kotlin {
jvm("desktop")
androidTarget {
publishLibraryVariants("release")
compilations.all {
kotlinOptions {
jvmTarget = "11"
}
}
}
iosX64()
iosArm64()
iosSimulatorArm64()
js {
browser {
testTask(Action {
enabled = false
})
}
}
@OptIn(ExperimentalWasmDsl::class)
wasmJs {
browser {
testTask(Action {
useKarma {
useChromeHeadless()
useConfigDirectory(project.projectDir.resolve("karma.config.d").resolve("wasm"))
}
})
}
binaries.executable()
}
macosX64()
macosArm64()
applyDefaultHierarchyTemplate()
sourceSets {
all {
languageSettings {
optIn("kotlin.RequiresOptIn")
optIn("kotlinx.cinterop.ExperimentalForeignApi")
optIn("kotlin.experimental.ExperimentalNativeApi")
optIn("org.jetbrains.compose.resources.InternalResourceApi")
optIn("org.jetbrains.compose.resources.ExperimentalResourceApi")
}
}
// common
// ┌────┴────┐
// skiko blocking
// │ ┌─────┴────────┐
// ┌───┴───┬──│────────┐ │
// │ native │ jvmAndAndroid
// │ ┌───┴───┐ │ ┌───┴───┐
// web ios macos desktop android
val commonMain by getting {
dependencies {
implementation(compose.runtime)
implementation(compose.foundation)
implementation(libs.kotlinx.coroutines.core)
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
implementation(libs.kotlinx.coroutines.test)
implementation(compose.material3)
@OptIn(ExperimentalComposeLibrary::class)
implementation(compose.uiTest)
}
}
val blockingMain by creating {
dependsOn(commonMain)
}
val blockingTest by creating {
dependsOn(commonTest)
}
val skikoMain by creating {
dependsOn(commonMain)
}
val skikoTest by creating {
dependsOn(commonTest)
}
val jvmAndAndroidMain by creating {
dependsOn(blockingMain)
}
val jvmAndAndroidTest by creating {
dependsOn(blockingTest)
}
val desktopMain by getting {
dependsOn(skikoMain)
dependsOn(jvmAndAndroidMain)
}
val desktopTest by getting {
dependsOn(skikoTest)
dependsOn(jvmAndAndroidTest)
dependencies {
implementation(compose.desktop.currentOs)
}
}
val androidMain by getting {
dependsOn(jvmAndAndroidMain)
dependencies {
//it will be called only in android instrumented tests where the library should be available
compileOnly(libs.androidx.test.monitor)
}
}
val androidInstrumentedTest by getting {
dependsOn(jvmAndAndroidTest)
dependencies {
implementation(libs.androidx.test.core)
implementation(libs.androidx.compose.ui.test)
implementation(libs.androidx.compose.ui.test.manifest)
implementation(libs.androidx.compose.ui.test.junit4)
}
}
val androidUnitTest by getting {
dependsOn(jvmAndAndroidTest)
}
val nativeMain by getting {
dependsOn(skikoMain)
dependsOn(blockingMain)
}
val nativeTest by getting {
dependsOn(skikoTest)
dependsOn(blockingTest)
}
val webMain by creating {
dependsOn(skikoMain)
}
val jsMain by getting {
dependsOn(webMain)
}
val wasmJsMain by getting {
dependsOn(webMain)
}
val webTest by creating {
dependsOn(skikoTest)
}
val jsTest by getting {
dependsOn(webTest)
}
val wasmJsTest by getting {
dependsOn(webTest)
}
}
}
android {
compileSdk = 34
namespace = "org.jetbrains.compose.components.resources"
defaultConfig {
minSdk = 21
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
@Suppress("UnstableApiUsage")
testOptions {
managedDevices {
devices {
maybeCreate<com.android.build.api.dsl.ManagedVirtualDevice>("pixel5").apply {
device = "Pixel 5"
apiLevel = 31
systemImageSource = "aosp"
}
}
}
}
sourceSets {
val commonTestResources = "src/commonTest/resources"
named("androidTest") {
resources.srcDir(commonTestResources)
assets.srcDir("src/androidInstrumentedTest/assets")
}
named("test") { resources.srcDir(commonTestResources) }
Pack all resources to assets on the android target. (#4965) The PR changes the android resources packaging. Now all resources are packed to the android assets (not only fonts). It unblocks usage android URIs to the resources in a WebView or other external resource consumers. Additionally the PR fixes Android Studio Compose Previews work with multiplatform resources: ![](https://private-user-images.githubusercontent.com/3532155/341182790-ef26b667-ad0d-4efd-b7f9-23cff92ab49d.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTg4Nzg0MTgsIm5iZiI6MTcxODg3ODExOCwicGF0aCI6Ii8zNTMyMTU1LzM0MTE4Mjc5MC1lZjI2YjY2Ny1hZDBkLTRlZmQtYjdmOS0yM2NmZjkyYWI0OWQucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDYyMCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA2MjBUMTAwODM4WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9OTY1MzdhMTAxMjNmZDRhMDA4ZjdjODBjYzg3M2MyNDg0ZTA5OWFkZGZkZjk1ZDUwOWFkZDk3MmQ2YjIzNzJiYiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.xgUAr_2--ZHo6txhdAANRbe8ju2SQ5EACvK96gaGJnY) For a backward compatibility the resources library tries to read resources in java resources if assets were not found. Fixes https://github.com/JetBrains/compose-multiplatform/issues/4877 Fixes https://github.com/JetBrains/compose-multiplatform/issues/4503 Fixes https://github.com/JetBrains/compose-multiplatform/issues/4932 Fixes https://github.com/JetBrains/compose-multiplatform/issues/4476 ## Release Notes ### Features - Resources - Android Studio Preview works with Compose Multiplatform resources now - Compose Multiplatform resources are stored in the android assets now. This fixes such cases as a rendering resource files in WebViews or Media Players
6 months ago
named("main") { manifest.srcFile("src/androidMain/AndroidManifest.xml") }
}
}
configureMavenPublication(
groupId = "org.jetbrains.compose.components",
artifactId = "components-resources",
name = "Resources for Compose JB"
)
apiValidation {
@OptIn(ExperimentalBCVApi::class)
klib { enabled = true }
nonPublicMarkers.add("org.jetbrains.compose.resources.InternalResourceApi")
}
//utility task to generate CLDRPluralRuleLists.kt file by 'CLDRPluralRules/plurals.xml'
tasks.register<GeneratePluralRuleListsTask>("generatePluralRuleLists") {
val projectDir = project.layout.projectDirectory
pluralsFile = projectDir.file("CLDRPluralRules/plurals.xml")
outputFile = projectDir.file("src/commonMain/kotlin/org/jetbrains/compose/resources/plural/CLDRPluralRuleLists.kt")
samplesOutputFile = projectDir.file("src/commonTest/kotlin/org/jetbrains/compose/resources/CLDRPluralRuleLists.test.kt")
}
afterEvaluate {
// TODO(o.k.): remove this after we refactor jsAndWasmMain source set in skiko to get rid of broken "common" js-interop
tasks.configureEach {
if (name == "compileWebMainKotlinMetadata") enabled = false
}
}