From c2099c7d4e107b3fb71387ff3b5e3d084df45052 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Mon, 9 Aug 2021 19:13:28 +0700 Subject: [PATCH 01/21] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 5f18828..0d1c2b1 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ +![moko-javascript](https://user-images.githubusercontent.com/5010169/128704305-df9c8e9e-200c-4d34-801e-a5b01c80f0cb.png) [![GitHub license](https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg?style=flat)](http://www.apache.org/licenses/LICENSE-2.0) [![Download](https://img.shields.io/maven-central/v/dev.icerock.moko/javascript) ](https://repo1.maven.org/maven2/dev/icerock/moko/javascript) ![kotlin-version](https://kotlin-version.aws.icerock.dev/kotlin-version?group=dev.icerock.moko&name=javascript) # Mobile Kotlin javascript From 5f98b6529d0727c33d5be34a8c209daf6392463c Mon Sep 17 00:00:00 2001 From: Kolchurin Konstantin Date: Mon, 15 Sep 2025 18:50:26 +0700 Subject: [PATCH 02/21] updated gradle, agp, quickjs-android replaced on zipline-android, targetSdk = 36 --- README.md | 2 +- gradle.properties | 4 +- gradle/libs.versions.toml | 22 +++++------ gradle/wrapper/gradle-wrapper.properties | 3 +- javascript-build-logic/build.gradle.kts | 4 +- .../kotlin/android-app-convention.gradle.kts | 16 ++++---- .../kotlin/android-base-convention.gradle.kts | 6 +-- ...ultiplatform-library-convention.gradle.kts | 37 +++++++++++++------ javascript/build.gradle.kts | 6 +-- .../src/androidMain/AndroidManifest.xml | 2 - .../moko/javascript/ContextProvider.kt | 4 +- .../moko/javascript/ContextProviderDynamic.kt | 2 + .../moko/javascript/JavaScriptEngine.kt | 26 +++++++------ .../moko/javascript/JavaScriptEngine.kt | 8 +++- .../JavaScriptEngineCrossTypesTests.kt | 1 - sample/android-app/build.gradle.kts | 1 + .../android-app/src/main/AndroidManifest.xml | 6 +-- sample/mpp-library/build.gradle.kts | 10 ++++- .../src/androidMain/AndroidManifest.xml | 2 - settings.gradle.kts | 1 - 20 files changed, 95 insertions(+), 68 deletions(-) delete mode 100644 javascript/src/androidMain/AndroidManifest.xml delete mode 100644 sample/mpp-library/src/androidMain/AndroidManifest.xml diff --git a/README.md b/README.md index 24ff88f..a8bbf83 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ allprojects { project build.gradle ```groovy dependencies { - commonMainApi("dev.icerock.moko:javascript:0.3.0") + commonMainApi("dev.icerock.moko:javascript:0.4.0") } ``` diff --git a/gradle.properties b/gradle.properties index 48b050a..cb8a3c6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,10 +3,8 @@ org.gradle.configureondemand=false org.gradle.parallel=true kotlin.code.style=official -kotlin.native.enableDependencyPropagation=false -kotlin.mpp.enableGranularSourceSetsMetadata=true -kotlin.mpp.enableCompatibilityMetadataVariant=true android.useAndroidX=true mobile.multiplatform.iosTargetWarning=false +kotlin.mpp.defaultHierarchies.template.enabled=false diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index bffb1ff..df2a8a9 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,15 +1,15 @@ [versions] -kotlinTestVersion = "1.6.21" -androidAppCompatVersion = "1.2.0" -materialDesignVersion = "1.0.0" -androidLifecycleVersion = "2.1.0" -androidCoreTestingVersion = "1.3.0" -testJUnitExtVersion = "1.1.2" -quickjsVersion = "0.9.2" -coroutinesVersion = "1.6.0-native-mt" -kotlinxSerializationVersion = "1.3.3" +kotlinTestVersion = "1.9.25" +androidAppCompatVersion = "1.7.1" +materialDesignVersion = "1.13.0" +androidLifecycleVersion = "2.2.0" +androidCoreTestingVersion = "1.7.0" +testJUnitExtVersion = "1.3.0" +coroutinesVersion = "1.8.1" +kotlinxSerializationVersion = "1.6.3" mokoTestVersion = "0.6.1" -mokoJavascriptVersion = "0.3.0" +mokoJavascriptVersion = "0.4.0" +ziplineVersion = "1.23.0" [libraries] @@ -21,7 +21,7 @@ testRunner = { module = "androidx.test:runner", version.ref = "androidCoreTestin testRules = { module = "androidx.test:rules", version.ref = "androidCoreTestingVersion" } testJUnitExt = { module = "androidx.test.ext:junit", version.ref = "testJUnitExtVersion" } testJUnitExtKtx = { module = "androidx.test.ext:junit-ktx", version.ref = "testJUnitExtVersion" } -quickjs = { module = "app.cash.quickjs:quickjs-android", version.ref = "quickjsVersion" } +ziplineAndroid = { module = "app.cash.zipline:zipline-android", version.ref = "ziplineVersion" } coroutines = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutinesVersion" } kotlinSerialization = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinxSerializationVersion" } kotlinTest = { module = "org.jetbrains.kotlin:kotlin-test-common", version.ref = "kotlinTestVersion" } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 0f80bbf..7bcf456 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ +#Mon Sep 15 18:35:34 NOVT 2025 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/javascript-build-logic/build.gradle.kts b/javascript-build-logic/build.gradle.kts index c7206d5..fddd3cb 100644 --- a/javascript-build-logic/build.gradle.kts +++ b/javascript-build-logic/build.gradle.kts @@ -11,7 +11,7 @@ repositories { dependencies { api("dev.icerock:mobile-multiplatform:0.14.1") - api("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21") - api("com.android.tools.build:gradle:7.0.1") + api("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.25") + api("com.android.tools.build:gradle:8.12.3") api("io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.15.0") } diff --git a/javascript-build-logic/src/main/kotlin/android-app-convention.gradle.kts b/javascript-build-logic/src/main/kotlin/android-app-convention.gradle.kts index 2859874..a744cb3 100644 --- a/javascript-build-logic/src/main/kotlin/android-app-convention.gradle.kts +++ b/javascript-build-logic/src/main/kotlin/android-app-convention.gradle.kts @@ -9,10 +9,6 @@ plugins { } android { - dexOptions { - javaMaxHeapSize = "2g" - } - buildTypes { getByName("release") { isMinifyEnabled = true @@ -24,9 +20,13 @@ android { } } - packagingOptions { - exclude("META-INF/*.kotlin_module") - exclude("META-INF/AL2.0") - exclude("META-INF/LGPL2.1") + packaging { + resources { + excludes += listOf( + "META-INF/*.kotlin_module", + "META-INF/AL2.0", + "META-INF/LGPL2.1" + ) + } } } diff --git a/javascript-build-logic/src/main/kotlin/android-base-convention.gradle.kts b/javascript-build-logic/src/main/kotlin/android-base-convention.gradle.kts index 5f97e66..b02b27d 100644 --- a/javascript-build-logic/src/main/kotlin/android-base-convention.gradle.kts +++ b/javascript-build-logic/src/main/kotlin/android-base-convention.gradle.kts @@ -5,10 +5,10 @@ import com.android.build.gradle.BaseExtension configure { - compileSdkVersion(30) + compileSdkVersion(36) defaultConfig { - minSdkVersion(18) - targetSdkVersion(30) + minSdk = 18 + targetSdk = 36 } } diff --git a/javascript-build-logic/src/main/kotlin/multiplatform-library-convention.gradle.kts b/javascript-build-logic/src/main/kotlin/multiplatform-library-convention.gradle.kts index 1b29c1a..770a978 100644 --- a/javascript-build-logic/src/main/kotlin/multiplatform-library-convention.gradle.kts +++ b/javascript-build-logic/src/main/kotlin/multiplatform-library-convention.gradle.kts @@ -10,29 +10,44 @@ plugins { } kotlin { - ios() + iosX64() + iosArm64() iosSimulatorArm64() - android { + androidTarget { publishLibraryVariants("release", "debug") } + sourceSets { + val mobileDeviceTest by creating + + val commonMain by getting + val iosX64Main by getting + val iosArm64Main by getting val iosSimulatorArm64Main by getting + + val iosMain by creating { + iosX64Main.dependsOn(this) + iosArm64Main.dependsOn(this) + iosSimulatorArm64Main.dependsOn(this) + } + iosMain.dependsOn(commonMain) + + val iosX64Test by getting + val iosArm64Test by getting val iosSimulatorArm64Test by getting - val mobileDeviceTest by creating + val iosTest by creating { + iosX64Test.dependsOn(this) + iosArm64Test.dependsOn(this) + iosSimulatorArm64Test.dependsOn(this) + } + val androidUnitTest by getting val commonTest by getting - val iosMain by getting - val iosTest by getting - val androidAndroidTest by getting - - iosSimulatorArm64Main.dependsOn(iosMain) - iosSimulatorArm64Test.dependsOn(iosTest) mobileDeviceTest.dependsOn(commonTest) iosTest.dependsOn(mobileDeviceTest) - androidAndroidTest.dependsOn(mobileDeviceTest) - + androidUnitTest.dependsOn(mobileDeviceTest) } } diff --git a/javascript/build.gradle.kts b/javascript/build.gradle.kts index 787677f..cf2ba8b 100644 --- a/javascript/build.gradle.kts +++ b/javascript/build.gradle.kts @@ -7,18 +7,18 @@ import org.gradle.api.tasks.testing.logging.TestLogEvent plugins { id("multiplatform-library-convention") - id("dev.icerock.mobile.multiplatform.android-manifest") id("publication-convention") } android { + namespace = "dev.icerock.moko.javascript" testOptions.unitTests.isIncludeAndroidResources = true defaultConfig { testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } sourceSets { - getByName("androidTest").java.srcDirs( + getByName("test").java.srcDirs( file("src/androidAndroidTest/kotlin"), file("src/mobileDeviceTest/kotlin") ) @@ -26,7 +26,7 @@ android { } dependencies { - androidMainImplementation(libs.quickjs) + androidMainImplementation(libs.ziplineAndroid) commonMainImplementation(libs.kotlinSerialization) commonTestImplementation(libs.kotlinTest) commonTestImplementation(libs.kotlinTestAnnotations) diff --git a/javascript/src/androidMain/AndroidManifest.xml b/javascript/src/androidMain/AndroidManifest.xml deleted file mode 100644 index 309ebc8..0000000 --- a/javascript/src/androidMain/AndroidManifest.xml +++ /dev/null @@ -1,2 +0,0 @@ - - diff --git a/javascript/src/androidMain/kotlin/dev/icerock/moko/javascript/ContextProvider.kt b/javascript/src/androidMain/kotlin/dev/icerock/moko/javascript/ContextProvider.kt index 678b674..5311102 100644 --- a/javascript/src/androidMain/kotlin/dev/icerock/moko/javascript/ContextProvider.kt +++ b/javascript/src/androidMain/kotlin/dev/icerock/moko/javascript/ContextProvider.kt @@ -4,7 +4,9 @@ package dev.icerock.moko.javascript -internal interface ContextProvider { +import app.cash.zipline.ZiplineService + +internal interface ContextProvider : ZiplineService { fun getBool(name: String): Boolean fun getDouble(name: String): Double diff --git a/javascript/src/androidMain/kotlin/dev/icerock/moko/javascript/ContextProviderDynamic.kt b/javascript/src/androidMain/kotlin/dev/icerock/moko/javascript/ContextProviderDynamic.kt index 281fe05..17ba05e 100644 --- a/javascript/src/androidMain/kotlin/dev/icerock/moko/javascript/ContextProviderDynamic.kt +++ b/javascript/src/androidMain/kotlin/dev/icerock/moko/javascript/ContextProviderDynamic.kt @@ -4,6 +4,8 @@ package dev.icerock.moko.javascript +import java.util.Collections.emptyMap + internal class ContextProviderDynamic : ContextProvider { var context: Map = emptyMap() var activeScript: String = "" diff --git a/javascript/src/androidMain/kotlin/dev/icerock/moko/javascript/JavaScriptEngine.kt b/javascript/src/androidMain/kotlin/dev/icerock/moko/javascript/JavaScriptEngine.kt index be92142..69664fd 100644 --- a/javascript/src/androidMain/kotlin/dev/icerock/moko/javascript/JavaScriptEngine.kt +++ b/javascript/src/androidMain/kotlin/dev/icerock/moko/javascript/JavaScriptEngine.kt @@ -4,26 +4,30 @@ package dev.icerock.moko.javascript -import app.cash.quickjs.QuickJs -import app.cash.quickjs.QuickJsException +import app.cash.zipline.EngineApi +import app.cash.zipline.QuickJsException +import app.cash.zipline.Zipline +import kotlinx.coroutines.Dispatchers import kotlinx.serialization.SerializationException import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonArray import kotlinx.serialization.json.JsonElement import kotlinx.serialization.json.JsonObject +@OptIn(EngineApi::class) actual class JavaScriptEngine actual constructor() { - private val quickJs: QuickJs = QuickJs.create() - private val json: Json = Json.Default + + private val json: Json = Json private val jsContext: ContextProviderDynamic = ContextProviderDynamic() + private val zipline: Zipline = Zipline.create(dispatcher = Dispatchers.IO) @Volatile var isClosed = false private set init { - quickJs.set("mokoJsContext", ContextProvider::class.java, jsContext) - quickJs.evaluate( + zipline.bind("mokoJsContext", jsContext) + zipline.quickJs.evaluate( """ function mokoJavaScriptProcessResult(result) { if (typeof result === 'object') return JSON.stringify(result); @@ -41,7 +45,7 @@ actual class JavaScriptEngine actual constructor() { val scriptWithContext: String = buildString { fillContext(scriptContext) } - quickJs.evaluate(scriptWithContext) + zipline.quickJs.evaluate(scriptWithContext) } actual fun evaluate(context: Map, script: String): JsType { @@ -56,7 +60,7 @@ actual class JavaScriptEngine actual constructor() { actual fun close() { if (isClosed) return - quickJs.close() + zipline.quickJs.close() isClosed = true } @@ -71,7 +75,7 @@ actual class JavaScriptEngine actual constructor() { fillContext(context) append("mokoJavaScriptProcessResult(eval(mokoJsContext.getScript()));") } - val result: Any? = quickJs.evaluate(scriptWithContext) + val result: Any? = zipline.quickJs.evaluate(scriptWithContext) return handleQuickJsResult(result) } @@ -104,9 +108,9 @@ actual class JavaScriptEngine actual constructor() { val jsonElement: JsonElement = json.parseToJsonElement(result) if (jsonElement is JsonObject || jsonElement is JsonArray) JsType.Json(jsonElement) else JsType.Str(result) - } catch (ex: SerializationException) { + } catch (_: SerializationException) { JsType.Str(result) - } catch (ex: IllegalStateException) { + } catch (_: IllegalStateException) { JsType.Str(result) } else -> throw JavaScriptEvaluationException( diff --git a/javascript/src/iosMain/kotlin/dev/icerock/moko/javascript/JavaScriptEngine.kt b/javascript/src/iosMain/kotlin/dev/icerock/moko/javascript/JavaScriptEngine.kt index 42e4a0f..d66b279 100644 --- a/javascript/src/iosMain/kotlin/dev/icerock/moko/javascript/JavaScriptEngine.kt +++ b/javascript/src/iosMain/kotlin/dev/icerock/moko/javascript/JavaScriptEngine.kt @@ -4,6 +4,8 @@ package dev.icerock.moko.javascript +import kotlinx.cinterop.BetaInteropApi +import kotlinx.cinterop.ExperimentalForeignApi import kotlinx.serialization.SerializationException import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonArray @@ -94,22 +96,24 @@ actual class JavaScriptEngine actual constructor() { } } +@OptIn(ExperimentalForeignApi::class, BetaInteropApi::class) private fun JsonObject.toNSDictionary(): NSDictionary { val data = NSString.create(string = this.toString()).dataUsingEncoding(NSUTF8StringEncoding) ?: return NSDictionary() return (NSJSONSerialization.JSONObjectWithData( data = data, - options = 0, + options = 0u, error = null ) as? NSDictionary) ?: NSDictionary() } +@OptIn(ExperimentalForeignApi::class, BetaInteropApi::class) private fun JsonArray.toNSArray(): NSArray { val data = NSString.create(string = this.toString()).dataUsingEncoding(NSUTF8StringEncoding) ?: return NSArray() return (NSJSONSerialization.JSONObjectWithData( data = data, - options = 0, + options = 0u, error = null ) as? NSArray) ?: NSArray() } diff --git a/javascript/src/mobileDeviceTest/kotlin/dev/icerock/moko/javascript/JavaScriptEngineCrossTypesTests.kt b/javascript/src/mobileDeviceTest/kotlin/dev/icerock/moko/javascript/JavaScriptEngineCrossTypesTests.kt index bba83f5..226dbd4 100644 --- a/javascript/src/mobileDeviceTest/kotlin/dev/icerock/moko/javascript/JavaScriptEngineCrossTypesTests.kt +++ b/javascript/src/mobileDeviceTest/kotlin/dev/icerock/moko/javascript/JavaScriptEngineCrossTypesTests.kt @@ -8,7 +8,6 @@ import kotlinx.serialization.json.Json import kotlinx.serialization.json.encodeToJsonElement import kotlin.test.AfterTest import kotlin.test.BeforeTest -import kotlin.test.Ignore import kotlin.test.Test import kotlin.test.assertEquals diff --git a/sample/android-app/build.gradle.kts b/sample/android-app/build.gradle.kts index 24459bf..5d8307b 100644 --- a/sample/android-app/build.gradle.kts +++ b/sample/android-app/build.gradle.kts @@ -8,6 +8,7 @@ plugins { } android { + namespace = "com.icerockdev.app" defaultConfig { applicationId = "dev.icerock.moko.samples.javascript" diff --git a/sample/android-app/src/main/AndroidManifest.xml b/sample/android-app/src/main/AndroidManifest.xml index adf12eb..2ff1829 100644 --- a/sample/android-app/src/main/AndroidManifest.xml +++ b/sample/android-app/src/main/AndroidManifest.xml @@ -1,7 +1,6 @@ + xmlns:tools="http://schemas.android.com/tools"> @@ -10,7 +9,8 @@ android:theme="@style/Theme.AppCompat.DayNight" tools:ignore="GoogleAppIndexingWarning"> - + diff --git a/sample/mpp-library/build.gradle.kts b/sample/mpp-library/build.gradle.kts index ac7d979..aaf5d6f 100644 --- a/sample/mpp-library/build.gradle.kts +++ b/sample/mpp-library/build.gradle.kts @@ -12,8 +12,14 @@ plugins { } kotlin { - android() - ios() + androidTarget() + iosArm64() + iosSimulatorArm64() + iosX64() +} + +android { + namespace = "com.icerockdev.library" } dependencies { diff --git a/sample/mpp-library/src/androidMain/AndroidManifest.xml b/sample/mpp-library/src/androidMain/AndroidManifest.xml deleted file mode 100644 index 42af3a2..0000000 --- a/sample/mpp-library/src/androidMain/AndroidManifest.xml +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index c6ccb10..55c2e17 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -2,7 +2,6 @@ * Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -enableFeaturePreview("VERSION_CATALOGS") enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") dependencyResolutionManagement { From 0ab215fa15a67799c79c3b550c0da815a183dbfc Mon Sep 17 00:00:00 2001 From: Kolchurin Konstantin Date: Mon, 15 Sep 2025 19:07:03 +0700 Subject: [PATCH 03/21] kotlin 2.2.10, minSdk 21, jdk 17 --- .gitignore | 1 + gradle/libs.versions.toml | 6 +++--- javascript-build-logic/build.gradle.kts | 2 +- .../src/main/kotlin/android-base-convention.gradle.kts | 7 ++++++- .../kotlin/dev/icerock/moko/javascript/JavaScriptEngine.kt | 6 ++++-- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index da38b27..0c89de0 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ .classpath .vscode .idea +.kotlin build *.iml Pods diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index df2a8a9..f5ae816 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,12 +1,12 @@ [versions] -kotlinTestVersion = "1.9.25" +kotlinTestVersion = "2.2.10" androidAppCompatVersion = "1.7.1" materialDesignVersion = "1.13.0" androidLifecycleVersion = "2.2.0" androidCoreTestingVersion = "1.7.0" testJUnitExtVersion = "1.3.0" -coroutinesVersion = "1.8.1" -kotlinxSerializationVersion = "1.6.3" +coroutinesVersion = "1.10.2" +kotlinxSerializationVersion = "1.9.0" mokoTestVersion = "0.6.1" mokoJavascriptVersion = "0.4.0" ziplineVersion = "1.23.0" diff --git a/javascript-build-logic/build.gradle.kts b/javascript-build-logic/build.gradle.kts index fddd3cb..605718a 100644 --- a/javascript-build-logic/build.gradle.kts +++ b/javascript-build-logic/build.gradle.kts @@ -11,7 +11,7 @@ repositories { dependencies { api("dev.icerock:mobile-multiplatform:0.14.1") - api("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.25") + api("org.jetbrains.kotlin:kotlin-gradle-plugin:2.2.10") api("com.android.tools.build:gradle:8.12.3") api("io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.15.0") } diff --git a/javascript-build-logic/src/main/kotlin/android-base-convention.gradle.kts b/javascript-build-logic/src/main/kotlin/android-base-convention.gradle.kts index b02b27d..c23cbbb 100644 --- a/javascript-build-logic/src/main/kotlin/android-base-convention.gradle.kts +++ b/javascript-build-logic/src/main/kotlin/android-base-convention.gradle.kts @@ -8,7 +8,12 @@ configure { compileSdkVersion(36) defaultConfig { - minSdk = 18 + minSdk = 21 targetSdk = 36 } + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + } } diff --git a/javascript/src/iosMain/kotlin/dev/icerock/moko/javascript/JavaScriptEngine.kt b/javascript/src/iosMain/kotlin/dev/icerock/moko/javascript/JavaScriptEngine.kt index d66b279..3504f9a 100644 --- a/javascript/src/iosMain/kotlin/dev/icerock/moko/javascript/JavaScriptEngine.kt +++ b/javascript/src/iosMain/kotlin/dev/icerock/moko/javascript/JavaScriptEngine.kt @@ -45,6 +45,7 @@ actual class JavaScriptEngine actual constructor() { ) } + @OptIn(BetaInteropApi::class) actual fun setContextObjects(vararg context: Pair) { context.forEach { (key, value) -> val contextObject: Any? = prepareValueForJsContext(value) @@ -55,6 +56,7 @@ actual class JavaScriptEngine actual constructor() { } } + @OptIn(BetaInteropApi::class) actual fun evaluate(context: Map, script: String): JsType { context.forEach { (key, value) -> jsContext.setObject( @@ -132,9 +134,9 @@ private fun JSValue.toMokoJSType(): JsType { val jsonElement: JsonElement = json.parseToJsonElement(toString_().orEmpty()) if (jsonElement is JsonObject || jsonElement is JsonArray) JsType.Json(jsonElement) else JsType.Str(toString_().orEmpty()) - } catch (ex: SerializationException) { + } catch (_: SerializationException) { JsType.Str(toString_().orEmpty()) - } catch (ex: IllegalStateException) { + } catch (_: IllegalStateException) { JsType.Str(toString_().orEmpty()) } isNumber -> JsType.DoubleNum(toDouble()) From 52cbc0f6b1e272d1c0374fd86ea059a2187c1b0c Mon Sep 17 00:00:00 2001 From: Kolchurin Konstantin Date: Tue, 16 Sep 2025 00:55:40 +0700 Subject: [PATCH 04/21] added settings.gradle.kts in convention plugins, jitpack config --- javascript-build-logic/build.gradle.kts | 3 +-- javascript-build-logic/settings.gradle.kts | 18 ++++++++++++++++++ jitpack.yml | 4 ++++ 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 javascript-build-logic/settings.gradle.kts create mode 100644 jitpack.yml diff --git a/javascript-build-logic/build.gradle.kts b/javascript-build-logic/build.gradle.kts index 605718a..4f80650 100644 --- a/javascript-build-logic/build.gradle.kts +++ b/javascript-build-logic/build.gradle.kts @@ -3,10 +3,9 @@ plugins { } repositories { + gradlePluginPortal() mavenCentral() google() - - gradlePluginPortal() } dependencies { diff --git a/javascript-build-logic/settings.gradle.kts b/javascript-build-logic/settings.gradle.kts new file mode 100644 index 0000000..ac13609 --- /dev/null +++ b/javascript-build-logic/settings.gradle.kts @@ -0,0 +1,18 @@ +/* + * Copyright 2025 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +rootProject.name = "javascript-build-logic" + +dependencyResolutionManagement { + repositories { + mavenCentral() + google() + } + + versionCatalogs { + create("libs") { + from(files("../gradle/libs.versions.toml")) + } + } +} diff --git a/jitpack.yml b/jitpack.yml new file mode 100644 index 0000000..6686503 --- /dev/null +++ b/jitpack.yml @@ -0,0 +1,4 @@ +jdk: + - openjdk17 +install: + - ./gradlew clean -Pgroup=$GROUP -Pversion=$VERSION -xtest -xlint -xsignMavenPublication publishToMavenLocal From a7c251dff8dd6ee886ed14f6dd7fb6f537f17388 Mon Sep 17 00:00:00 2001 From: Kolchurin Konstantin Date: Tue, 16 Sep 2025 14:20:37 +0700 Subject: [PATCH 05/21] update config --- build.gradle => build.gradle.kts | 4 ++-- gradle/moko.versions.toml | 2 ++ javascript-build-logic/build.gradle.kts | 10 +++++----- settings.gradle.kts | 11 +++++++++-- 4 files changed, 18 insertions(+), 9 deletions(-) rename build.gradle => build.gradle.kts (84%) create mode 100644 gradle/moko.versions.toml diff --git a/build.gradle b/build.gradle.kts similarity index 84% rename from build.gradle rename to build.gradle.kts index 32a15eb..8e576c8 100644 --- a/build.gradle +++ b/build.gradle.kts @@ -1,11 +1,11 @@ /* - * Copyright 2019 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + * Copyright 2025 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ buildscript { repositories { - mavenCentral() google() + mavenCentral() } dependencies { classpath(":javascript-build-logic") diff --git a/gradle/moko.versions.toml b/gradle/moko.versions.toml new file mode 100644 index 0000000..165aa55 --- /dev/null +++ b/gradle/moko.versions.toml @@ -0,0 +1,2 @@ +[versions] +mokoJavascriptVersion = "0.4.0" \ No newline at end of file diff --git a/javascript-build-logic/build.gradle.kts b/javascript-build-logic/build.gradle.kts index 4f80650..5d91873 100644 --- a/javascript-build-logic/build.gradle.kts +++ b/javascript-build-logic/build.gradle.kts @@ -3,14 +3,14 @@ plugins { } repositories { + google() gradlePluginPortal() mavenCentral() - google() } dependencies { - api("dev.icerock:mobile-multiplatform:0.14.1") - api("org.jetbrains.kotlin:kotlin-gradle-plugin:2.2.10") - api("com.android.tools.build:gradle:8.12.3") - api("io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.15.0") + implementation("dev.icerock:mobile-multiplatform:0.14.1") + implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:2.2.10") + implementation("com.android.tools.build:gradle:8.12.3") + implementation("io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.15.0") } diff --git a/settings.gradle.kts b/settings.gradle.kts index 55c2e17..b22c1f9 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,6 +1,7 @@ /* * Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ +rootProject.name = "moko-javascript" enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") @@ -8,12 +9,18 @@ dependencyResolutionManagement { repositories { mavenCentral() google() + } - jcenter() + versionCatalogs { + create("moko") { + from(files("gradle/moko.versions.toml")) + } } } -includeBuild("javascript-build-logic") +if (gradle.parent == null) { + includeBuild("javascript-build-logic") +} include(":javascript") include(":sample:android-app") From 6ed829ce1ee5767b906c25bcda4fdbd41144a905 Mon Sep 17 00:00:00 2001 From: Kolchurin Konstantin Date: Tue, 16 Sep 2025 14:32:16 +0700 Subject: [PATCH 06/21] added includeBuild in repository --- settings.gradle.kts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/settings.gradle.kts b/settings.gradle.kts index b22c1f9..ecf9ee7 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -9,6 +9,8 @@ dependencyResolutionManagement { repositories { mavenCentral() google() + + includeBuild("javascript-build-logic") } versionCatalogs { From 67d746c3741ad4bdb751802e8b75b5f650c459d4 Mon Sep 17 00:00:00 2001 From: Kolchurin Konstantin Date: Wed, 17 Sep 2025 13:49:08 +0700 Subject: [PATCH 07/21] update libs config --- build.gradle.kts | 11 +++++-- gradle/libs.versions.toml | 19 ++++++++---- javascript-build-logic/build.gradle.kts | 18 +++++++---- javascript-build-logic/settings.gradle.kts | 9 +++++- .../kotlin/android-base-convention.gradle.kts | 2 +- .../main/kotlin/detekt-convention.gradle.kts | 4 +-- .../src/main/kotlin/utils.kt | 30 +++++++++++++++++++ sample/android-app/build.gradle.kts | 1 - settings.gradle.kts | 15 ++++++---- 9 files changed, 85 insertions(+), 24 deletions(-) create mode 100644 javascript-build-logic/src/main/kotlin/utils.kt diff --git a/build.gradle.kts b/build.gradle.kts index 8e576c8..ce97238 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,8 +4,15 @@ buildscript { repositories { - google() + google { + content { + includeGroupByRegex("com\\.android.*") + includeGroupByRegex("com\\.google.*") + includeGroupByRegex("androidx.*") + } + } mavenCentral() + gradlePluginPortal() } dependencies { classpath(":javascript-build-logic") @@ -15,6 +22,6 @@ buildscript { allprojects { plugins.withId("org.gradle.maven-publish") { group = "dev.icerock.moko" - version = libs.versions.mokoJavascriptVersion.get() + version = moko.versions.mokoJavascriptVersion.get() } } \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index f5ae816..d628463 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,5 +1,5 @@ [versions] -kotlinTestVersion = "2.2.10" +kotlinVersion = "2.2.10" androidAppCompatVersion = "1.7.1" materialDesignVersion = "1.13.0" androidLifecycleVersion = "2.2.0" @@ -8,15 +8,16 @@ testJUnitExtVersion = "1.3.0" coroutinesVersion = "1.10.2" kotlinxSerializationVersion = "1.9.0" mokoTestVersion = "0.6.1" -mokoJavascriptVersion = "0.4.0" ziplineVersion = "1.23.0" - +mokoMultiplatformVersion = "0.14.4" +androidGradleVersion = "8.12.3" +detektVersion = "1.23.8" [libraries] appCompat = { module = "androidx.appcompat:appcompat", version.ref = "androidAppCompatVersion" } material = { module = "com.google.android.material:material", version.ref = "materialDesignVersion" } lifecycle = { module = "androidx.lifecycle:lifecycle-extensions", version.ref = "androidLifecycleVersion" } -kotlinTestJUnit = { module = "org.jetbrains.kotlin:kotlin-test-junit", version.ref = "kotlinTestVersion" } +kotlinTestJUnit = { module = "org.jetbrains.kotlin:kotlin-test-junit", version.ref = "kotlinVersion" } testRunner = { module = "androidx.test:runner", version.ref = "androidCoreTestingVersion" } testRules = { module = "androidx.test:rules", version.ref = "androidCoreTestingVersion" } testJUnitExt = { module = "androidx.test.ext:junit", version.ref = "testJUnitExtVersion" } @@ -24,6 +25,12 @@ testJUnitExtKtx = { module = "androidx.test.ext:junit-ktx", version.ref = "testJ ziplineAndroid = { module = "app.cash.zipline:zipline-android", version.ref = "ziplineVersion" } coroutines = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutinesVersion" } kotlinSerialization = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinxSerializationVersion" } -kotlinTest = { module = "org.jetbrains.kotlin:kotlin-test-common", version.ref = "kotlinTestVersion" } -kotlinTestAnnotations = { module = "org.jetbrains.kotlin:kotlin-test-annotations-common", version.ref = "kotlinTestVersion" } +kotlinTest = { module = "org.jetbrains.kotlin:kotlin-test-common", version.ref = "kotlinVersion" } +kotlinTestAnnotations = { module = "org.jetbrains.kotlin:kotlin-test-annotations-common", version.ref = "kotlinVersion" } mokoTest = { module = "dev.icerock.moko:test-core", version.ref = "mokoTestVersion" } + +mokoMultiplatform = { module = "dev.icerock:mobile-multiplatform", version.ref = "mokoMultiplatformVersion" } +kotlinGradlePlugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlinVersion" } +androidGradlePlugin = { module = "com.android.tools.build:gradle", version.ref = "androidGradleVersion" } +detekt-formatting = { module = "io.gitlab.arturbosch.detekt:detekt-formatting", version.ref = "detektVersion" } +detektPlugin = { module = "io.gitlab.arturbosch.detekt:detekt-gradle-plugin", version.ref = "detektVersion" } diff --git a/javascript-build-logic/build.gradle.kts b/javascript-build-logic/build.gradle.kts index 5d91873..1290f29 100644 --- a/javascript-build-logic/build.gradle.kts +++ b/javascript-build-logic/build.gradle.kts @@ -3,14 +3,20 @@ plugins { } repositories { - google() - gradlePluginPortal() + google { + content { + includeGroupByRegex("com\\.android.*") + includeGroupByRegex("com\\.google.*") + includeGroupByRegex("androidx.*") + } + } mavenCentral() + gradlePluginPortal() } dependencies { - implementation("dev.icerock:mobile-multiplatform:0.14.1") - implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:2.2.10") - implementation("com.android.tools.build:gradle:8.12.3") - implementation("io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.15.0") + implementation(libs.mokoMultiplatform) + implementation(libs.kotlinGradlePlugin) + implementation(libs.androidGradlePlugin) + implementation(libs.detektPlugin) } diff --git a/javascript-build-logic/settings.gradle.kts b/javascript-build-logic/settings.gradle.kts index ac13609..7862700 100644 --- a/javascript-build-logic/settings.gradle.kts +++ b/javascript-build-logic/settings.gradle.kts @@ -6,8 +6,15 @@ rootProject.name = "javascript-build-logic" dependencyResolutionManagement { repositories { + google { + content { + includeGroupByRegex("com\\.android.*") + includeGroupByRegex("com\\.google.*") + includeGroupByRegex("androidx.*") + } + } + mavenCentral() - google() } versionCatalogs { diff --git a/javascript-build-logic/src/main/kotlin/android-base-convention.gradle.kts b/javascript-build-logic/src/main/kotlin/android-base-convention.gradle.kts index c23cbbb..c4735ec 100644 --- a/javascript-build-logic/src/main/kotlin/android-base-convention.gradle.kts +++ b/javascript-build-logic/src/main/kotlin/android-base-convention.gradle.kts @@ -8,7 +8,7 @@ configure { compileSdkVersion(36) defaultConfig { - minSdk = 21 + minSdk = 24 targetSdk = 36 } diff --git a/javascript-build-logic/src/main/kotlin/detekt-convention.gradle.kts b/javascript-build-logic/src/main/kotlin/detekt-convention.gradle.kts index 68343a8..1bdf5e4 100644 --- a/javascript-build-logic/src/main/kotlin/detekt-convention.gradle.kts +++ b/javascript-build-logic/src/main/kotlin/detekt-convention.gradle.kts @@ -7,9 +7,9 @@ plugins { } detekt { - input.setFrom("src/commonMain/kotlin", "src/androidMain/kotlin", "src/iosMain/kotlin", "src/main/kotlin") + source.setFrom("src/commonMain/kotlin", "src/androidMain/kotlin", "src/iosMain/kotlin", "src/main/kotlin") } dependencies { - "detektPlugins"("io.gitlab.arturbosch.detekt:detekt-formatting:1.15.0") + detektPlugins(libs.safeLibrary("detekt-formatting")) } diff --git a/javascript-build-logic/src/main/kotlin/utils.kt b/javascript-build-logic/src/main/kotlin/utils.kt new file mode 100644 index 0000000..09a85f1 --- /dev/null +++ b/javascript-build-logic/src/main/kotlin/utils.kt @@ -0,0 +1,30 @@ +/* + * Copyright 2025 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +import org.gradle.api.GradleException +import org.gradle.api.Project +import org.gradle.api.artifacts.ExternalModuleDependencyBundle +import org.gradle.api.artifacts.MinimalExternalModuleDependency +import org.gradle.api.artifacts.VersionCatalog +import org.gradle.api.artifacts.VersionCatalogsExtension +import org.gradle.api.provider.Provider + +internal val Project.libs: VersionCatalog + get() = this.extensions.getByType(VersionCatalogsExtension::class.java).named("libs") + +internal fun VersionCatalog.safeLibrary(alias: String): Provider { + try { + return findLibrary(alias).get() + } catch (_: Exception) { + throw GradleException("library $alias not found in libs.versions.toml") + } +} + +internal fun VersionCatalog.safeBundle(alias: String): Provider { + try { + return findBundle(alias).get() + } catch (_: Exception) { + throw GradleException("bundle $alias not found in libs.versions.toml") + } +} diff --git a/sample/android-app/build.gradle.kts b/sample/android-app/build.gradle.kts index 5d8307b..3db250f 100644 --- a/sample/android-app/build.gradle.kts +++ b/sample/android-app/build.gradle.kts @@ -4,7 +4,6 @@ plugins { id("android-app-convention") - id("kotlin-android") } android { diff --git a/settings.gradle.kts b/settings.gradle.kts index ecf9ee7..c0fdc25 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,16 +1,19 @@ /* - * Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + * Copyright 2025 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ -rootProject.name = "moko-javascript" enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") dependencyResolutionManagement { repositories { + google { + content { + includeGroupByRegex("com\\.android.*") + includeGroupByRegex("com\\.google.*") + includeGroupByRegex("androidx.*") + } + } mavenCentral() - google() - - includeBuild("javascript-build-logic") } versionCatalogs { @@ -20,6 +23,8 @@ dependencyResolutionManagement { } } +rootProject.name = "moko-javascript" + if (gradle.parent == null) { includeBuild("javascript-build-logic") } From ea0884fdeb8702f6ef608720c4e53e57c15bc08b Mon Sep 17 00:00:00 2001 From: Kolchurin Konstantin Date: Wed, 17 Sep 2025 13:49:59 +0700 Subject: [PATCH 08/21] update compilation check --- .github/workflows/compilation-check.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/compilation-check.yml b/.github/workflows/compilation-check.yml index a0d4c0e..3726409 100644 --- a/.github/workflows/compilation-check.yml +++ b/.github/workflows/compilation-check.yml @@ -12,10 +12,10 @@ jobs: steps: - uses: actions/checkout@v1 - - name: Set up JDK 11 + - name: Set up JDK 17 uses: actions/setup-java@v1 with: - java-version: 11 + java-version: 17 - name: Build and test run: ./gradlew build publishToMavenLocal syncMultiPlatformLibraryDebugFrameworkIosX64 - name: Install pods with kotlin From e89b304f2acd8c71c936bc8447ece6559c0e30a9 Mon Sep 17 00:00:00 2001 From: Kolchurin Konstantin Date: Wed, 17 Sep 2025 13:52:11 +0700 Subject: [PATCH 09/21] update publish config --- .github/workflows/publish.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 219f43b..d0d142e 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -21,12 +21,15 @@ jobs: steps: - uses: actions/checkout@v1 - - name: Set up JDK 11 + - name: Set up JDK 17 uses: actions/setup-java@v1 with: - java-version: 11 - - name: Publish library - run: ./gradlew publish + java-version: 17 + - name: Prebuild library + run: ./gradlew publishToMavenLocal + - name: Publish + run: ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository + release: name: Create release needs: publish From 088907b163b2ffbd78bb65a4632867972a4732dd Mon Sep 17 00:00:00 2001 From: Kolchurin Konstantin Date: Wed, 17 Sep 2025 14:17:24 +0700 Subject: [PATCH 10/21] update project config --- build.gradle.kts | 16 ++++++--- gradle/libs.versions.toml | 1 + .../kotlin/publication-convention.gradle.kts | 34 ++++++++----------- javascript/build.gradle.kts | 15 +++++--- 4 files changed, 37 insertions(+), 29 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index ce97238..54c4572 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,6 +1,7 @@ /* * Copyright 2025 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ +apply(plugin = "dev.icerock.moko.gradle.publication.nexus") buildscript { repositories { @@ -15,13 +16,18 @@ buildscript { gradlePluginPortal() } dependencies { + classpath(libs.mokoGradlePlugin) classpath(":javascript-build-logic") } } +val mokoVersion = moko.versions.mokoJavascriptVersion.get() allprojects { - plugins.withId("org.gradle.maven-publish") { - group = "dev.icerock.moko" - version = moko.versions.mokoJavascriptVersion.get() - } -} \ No newline at end of file + group = "dev.icerock.moko" + version = mokoVersion +} + +tasks.register("clean", Delete::class).configure { + group = "build" + delete(rootProject.layout.buildDirectory) +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d628463..2c36814 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -34,3 +34,4 @@ kotlinGradlePlugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", ver androidGradlePlugin = { module = "com.android.tools.build:gradle", version.ref = "androidGradleVersion" } detekt-formatting = { module = "io.gitlab.arturbosch.detekt:detekt-formatting", version.ref = "detektVersion" } detektPlugin = { module = "io.gitlab.arturbosch.detekt:detekt-gradle-plugin", version.ref = "detektVersion" } +mokoGradlePlugin = { module = "dev.icerock.moko:moko-gradle-plugin", version = "0.5.1" } diff --git a/javascript-build-logic/src/main/kotlin/publication-convention.gradle.kts b/javascript-build-logic/src/main/kotlin/publication-convention.gradle.kts index 9307b13..d85d6c6 100644 --- a/javascript-build-logic/src/main/kotlin/publication-convention.gradle.kts +++ b/javascript-build-logic/src/main/kotlin/publication-convention.gradle.kts @@ -1,25 +1,14 @@ /* - * Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + * Copyright 2025 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. */ import java.util.Base64 plugins { - id("javadoc-stub-convention") id("org.gradle.maven-publish") - id("signing") } publishing { - repositories.maven("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/") { - name = "OSSRH" - - credentials { - username = System.getenv("OSSRH_USER") - password = System.getenv("OSSRH_KEY") - } - } - publications.withType { // Provide artifacts information requited by Maven Central pom { @@ -61,15 +50,22 @@ publishing { } } +val signingKeyId: String? = System.getenv("SIGNING_KEY_ID") +if (signingKeyId != null) { + apply(plugin = "signing") + + configure { + val signingPassword: String? = System.getenv("SIGNING_PASSWORD") + val signingKey: String? = System.getenv("SIGNING_KEY")?.let { base64Key -> + String(Base64.getDecoder().decode(base64Key)) + } -signing { - val signingKeyId: String? = System.getenv("SIGNING_KEY_ID") - val signingPassword: String? = System.getenv("SIGNING_PASSWORD") - val signingKey: String? = System.getenv("SIGNING_KEY")?.let { base64Key -> - String(Base64.getDecoder().decode(base64Key)) - } - if (signingKeyId != null) { useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword) sign(publishing.publications) } + + val signingTasks = tasks.withType() + tasks.withType().configureEach { + dependsOn(signingTasks) + } } diff --git a/javascript/build.gradle.kts b/javascript/build.gradle.kts index cf2ba8b..4b774ef 100644 --- a/javascript/build.gradle.kts +++ b/javascript/build.gradle.kts @@ -12,16 +12,21 @@ plugins { android { namespace = "dev.icerock.moko.javascript" - testOptions.unitTests.isIncludeAndroidResources = true + defaultConfig { testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } + testOptions { + unitTests.isIncludeAndroidResources = true + } + sourceSets { - getByName("test").java.srcDirs( - file("src/androidAndroidTest/kotlin"), - file("src/mobileDeviceTest/kotlin") - ) + getByName("test") { + java.srcDirs( + "src/mobileDeviceTest/kotlin" + ) + } } } From dfc8d0b6bf99344fb3feaeafe3b97001e0607d3b Mon Sep 17 00:00:00 2001 From: Kolchurin Konstantin Date: Wed, 17 Sep 2025 14:58:32 +0700 Subject: [PATCH 11/21] removed jitpack config, update readme --- README.md | 4 ++-- jitpack.yml | 4 ---- 2 files changed, 2 insertions(+), 6 deletions(-) delete mode 100644 jitpack.yml diff --git a/README.md b/README.md index a8bbf83..9016c9a 100644 --- a/README.md +++ b/README.md @@ -19,8 +19,8 @@ This is a Kotlin MultiPlatform library that allows you to run JavaScript code fr - Pass objects to JavaScript as global vars ## Requirements -- Gradle version 6.0+ -- Android API 16+ +- Gradle version 8.0+ +- Android API 21+ - iOS version 9.0+ ## Installation diff --git a/jitpack.yml b/jitpack.yml deleted file mode 100644 index 6686503..0000000 --- a/jitpack.yml +++ /dev/null @@ -1,4 +0,0 @@ -jdk: - - openjdk17 -install: - - ./gradlew clean -Pgroup=$GROUP -Pversion=$VERSION -xtest -xlint -xsignMavenPublication publishToMavenLocal From 4a451b6dcb6fe7d90553c4136f32c5170c36a31b Mon Sep 17 00:00:00 2001 From: Kolchurin Konstantin Date: Wed, 17 Sep 2025 15:28:27 +0700 Subject: [PATCH 12/21] fix tests --- ...ultiplatform-library-convention.gradle.kts | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/javascript-build-logic/src/main/kotlin/multiplatform-library-convention.gradle.kts b/javascript-build-logic/src/main/kotlin/multiplatform-library-convention.gradle.kts index 770a978..d042fab 100644 --- a/javascript-build-logic/src/main/kotlin/multiplatform-library-convention.gradle.kts +++ b/javascript-build-logic/src/main/kotlin/multiplatform-library-convention.gradle.kts @@ -18,8 +18,6 @@ kotlin { } sourceSets { - val mobileDeviceTest by creating - val commonMain by getting val iosX64Main by getting val iosArm64Main by getting @@ -36,18 +34,25 @@ kotlin { val iosArm64Test by getting val iosSimulatorArm64Test by getting + val commonTest by getting + + val mobileDeviceTest by creating { + dependsOn(commonTest) + kotlin.srcDir("src/mobileDeviceTest/kotlin") + } val iosTest by creating { iosX64Test.dependsOn(this) iosArm64Test.dependsOn(this) iosSimulatorArm64Test.dependsOn(this) + dependsOn(mobileDeviceTest) } - val androidUnitTest by getting - - val commonTest by getting - - mobileDeviceTest.dependsOn(commonTest) - iosTest.dependsOn(mobileDeviceTest) - androidUnitTest.dependsOn(mobileDeviceTest) } } +android { + sourceSets { + getByName("androidTest") { + java.srcDirs("src/mobileDeviceTest/kotlin") // instrumented tests + } + } +} From 62d43f9279f676a20f88e3c375fde1e9f77980eb Mon Sep 17 00:00:00 2001 From: Kolchurin Konstantin Date: Wed, 17 Sep 2025 16:36:59 +0700 Subject: [PATCH 13/21] fix plugins api --- javascript-build-logic/build.gradle.kts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/javascript-build-logic/build.gradle.kts b/javascript-build-logic/build.gradle.kts index 1290f29..d104cc4 100644 --- a/javascript-build-logic/build.gradle.kts +++ b/javascript-build-logic/build.gradle.kts @@ -15,8 +15,8 @@ repositories { } dependencies { - implementation(libs.mokoMultiplatform) - implementation(libs.kotlinGradlePlugin) - implementation(libs.androidGradlePlugin) - implementation(libs.detektPlugin) + api(libs.mokoMultiplatform) + api(libs.kotlinGradlePlugin) + api(libs.androidGradlePlugin) + api(libs.detektPlugin) } From e4d4b7ac497a80588cbcf78a23452e8bd5f9392e Mon Sep 17 00:00:00 2001 From: Kolchurin Konstantin Date: Thu, 18 Sep 2025 14:16:37 +0700 Subject: [PATCH 14/21] android min sdk 21 --- .../src/main/kotlin/android-base-convention.gradle.kts | 2 +- .../src/main/kotlin/detekt-convention.gradle.kts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/javascript-build-logic/src/main/kotlin/android-base-convention.gradle.kts b/javascript-build-logic/src/main/kotlin/android-base-convention.gradle.kts index c4735ec..c23cbbb 100644 --- a/javascript-build-logic/src/main/kotlin/android-base-convention.gradle.kts +++ b/javascript-build-logic/src/main/kotlin/android-base-convention.gradle.kts @@ -8,7 +8,7 @@ configure { compileSdkVersion(36) defaultConfig { - minSdk = 24 + minSdk = 21 targetSdk = 36 } diff --git a/javascript-build-logic/src/main/kotlin/detekt-convention.gradle.kts b/javascript-build-logic/src/main/kotlin/detekt-convention.gradle.kts index 1bdf5e4..b4c2900 100644 --- a/javascript-build-logic/src/main/kotlin/detekt-convention.gradle.kts +++ b/javascript-build-logic/src/main/kotlin/detekt-convention.gradle.kts @@ -11,5 +11,5 @@ detekt { } dependencies { - detektPlugins(libs.safeLibrary("detekt-formatting")) + detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.23.8") } From 800df75a8d71fef16fef8fa645d6c18e02a660fa Mon Sep 17 00:00:00 2001 From: Kolchurin Konstantin Date: Thu, 18 Sep 2025 14:17:27 +0700 Subject: [PATCH 15/21] removed utils --- .../src/main/kotlin/utils.kt | 30 ------------------- 1 file changed, 30 deletions(-) delete mode 100644 javascript-build-logic/src/main/kotlin/utils.kt diff --git a/javascript-build-logic/src/main/kotlin/utils.kt b/javascript-build-logic/src/main/kotlin/utils.kt deleted file mode 100644 index 09a85f1..0000000 --- a/javascript-build-logic/src/main/kotlin/utils.kt +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2025 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. - */ - -import org.gradle.api.GradleException -import org.gradle.api.Project -import org.gradle.api.artifacts.ExternalModuleDependencyBundle -import org.gradle.api.artifacts.MinimalExternalModuleDependency -import org.gradle.api.artifacts.VersionCatalog -import org.gradle.api.artifacts.VersionCatalogsExtension -import org.gradle.api.provider.Provider - -internal val Project.libs: VersionCatalog - get() = this.extensions.getByType(VersionCatalogsExtension::class.java).named("libs") - -internal fun VersionCatalog.safeLibrary(alias: String): Provider { - try { - return findLibrary(alias).get() - } catch (_: Exception) { - throw GradleException("library $alias not found in libs.versions.toml") - } -} - -internal fun VersionCatalog.safeBundle(alias: String): Provider { - try { - return findBundle(alias).get() - } catch (_: Exception) { - throw GradleException("bundle $alias not found in libs.versions.toml") - } -} From d3cc30858d7ff8d89492ac9ad580d2a7ac3b0463 Mon Sep 17 00:00:00 2001 From: Kolchurin Konstantin Date: Thu, 18 Sep 2025 14:20:20 +0700 Subject: [PATCH 16/21] separate android and native tests --- ...ultiplatform-library-convention.gradle.kts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/javascript-build-logic/src/main/kotlin/multiplatform-library-convention.gradle.kts b/javascript-build-logic/src/main/kotlin/multiplatform-library-convention.gradle.kts index d042fab..d1d5085 100644 --- a/javascript-build-logic/src/main/kotlin/multiplatform-library-convention.gradle.kts +++ b/javascript-build-logic/src/main/kotlin/multiplatform-library-convention.gradle.kts @@ -36,23 +36,24 @@ kotlin { val commonTest by getting - val mobileDeviceTest by creating { - dependsOn(commonTest) + val mobileDeviceTestNative by creating { kotlin.srcDir("src/mobileDeviceTest/kotlin") + dependsOn(commonTest) } + val iosTest by creating { iosX64Test.dependsOn(this) iosArm64Test.dependsOn(this) iosSimulatorArm64Test.dependsOn(this) - dependsOn(mobileDeviceTest) + dependsOn(mobileDeviceTestNative) } - } -} -android { - sourceSets { - getByName("androidTest") { - java.srcDirs("src/mobileDeviceTest/kotlin") // instrumented tests + val mobileDeviceTestAndroid by creating { + kotlin.srcDir("src/mobileDeviceTest/kotlin") + } + + val androidInstrumentedTest by getting { + dependsOn(mobileDeviceTestAndroid) } } } From 9501f6f7d6eeb138ae9e784b80fcae94c714cbf0 Mon Sep 17 00:00:00 2001 From: Kolchurin Konstantin Date: Thu, 18 Sep 2025 14:23:20 +0700 Subject: [PATCH 17/21] removed useless imports, simplify constructor --- javascript/build.gradle.kts | 1 + .../kotlin/dev/icerock/moko/javascript/JavaScriptEngine.kt | 2 +- .../kotlin/dev/icerock/moko/javascript/JavaScriptEngine.kt | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/javascript/build.gradle.kts b/javascript/build.gradle.kts index 4b774ef..905f128 100644 --- a/javascript/build.gradle.kts +++ b/javascript/build.gradle.kts @@ -33,6 +33,7 @@ android { dependencies { androidMainImplementation(libs.ziplineAndroid) commonMainImplementation(libs.kotlinSerialization) + commonTestImplementation(libs.kotlinTest) commonTestImplementation(libs.kotlinTestAnnotations) commonTestImplementation(libs.mokoTest) diff --git a/javascript/src/androidMain/kotlin/dev/icerock/moko/javascript/JavaScriptEngine.kt b/javascript/src/androidMain/kotlin/dev/icerock/moko/javascript/JavaScriptEngine.kt index 69664fd..fba299d 100644 --- a/javascript/src/androidMain/kotlin/dev/icerock/moko/javascript/JavaScriptEngine.kt +++ b/javascript/src/androidMain/kotlin/dev/icerock/moko/javascript/JavaScriptEngine.kt @@ -15,7 +15,7 @@ import kotlinx.serialization.json.JsonElement import kotlinx.serialization.json.JsonObject @OptIn(EngineApi::class) -actual class JavaScriptEngine actual constructor() { +actual class JavaScriptEngine { private val json: Json = Json private val jsContext: ContextProviderDynamic = ContextProviderDynamic() diff --git a/javascript/src/iosMain/kotlin/dev/icerock/moko/javascript/JavaScriptEngine.kt b/javascript/src/iosMain/kotlin/dev/icerock/moko/javascript/JavaScriptEngine.kt index 3504f9a..b8553bb 100644 --- a/javascript/src/iosMain/kotlin/dev/icerock/moko/javascript/JavaScriptEngine.kt +++ b/javascript/src/iosMain/kotlin/dev/icerock/moko/javascript/JavaScriptEngine.kt @@ -26,7 +26,7 @@ import platform.JavaScriptCore.JSContext import platform.JavaScriptCore.JSValue import platform.JavaScriptCore.setObject -actual class JavaScriptEngine actual constructor() { +actual class JavaScriptEngine { private val jsContext = JSContext().apply { exceptionHandler = { exceptionContext, exception -> @@ -162,7 +162,7 @@ private fun Any?.toJsonElement(): JsonElement { is NSString -> JsonPrimitive(this as String) is NSNumber -> JsonPrimitive(this.doubleValue) is NSDictionary -> (this as Map).toJson() - is NSArray -> (this as List<*>).map { it.toJsonElement() }.let { JsonArray(it) } + is NSArray -> JsonArray((this as List<*>).map { it.toJsonElement() }) else -> throw IllegalArgumentException("unknown JSValue type $this") } } From 04ba5d490a9f40e69f807945dc4d9c6433723cfc Mon Sep 17 00:00:00 2001 From: Kolchurin Konstantin Date: Thu, 18 Sep 2025 14:27:31 +0700 Subject: [PATCH 18/21] removed tests config --- javascript/build.gradle.kts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/javascript/build.gradle.kts b/javascript/build.gradle.kts index 905f128..45fe53b 100644 --- a/javascript/build.gradle.kts +++ b/javascript/build.gradle.kts @@ -20,14 +20,6 @@ android { testOptions { unitTests.isIncludeAndroidResources = true } - - sourceSets { - getByName("test") { - java.srcDirs( - "src/mobileDeviceTest/kotlin" - ) - } - } } dependencies { From b79bdcf9f013bb20710cd77b493a43b61e46d4be Mon Sep 17 00:00:00 2001 From: Kolchurin Konstantin Date: Thu, 18 Sep 2025 14:43:48 +0700 Subject: [PATCH 19/21] rollback test config --- javascript/build.gradle.kts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/javascript/build.gradle.kts b/javascript/build.gradle.kts index 45fe53b..905f128 100644 --- a/javascript/build.gradle.kts +++ b/javascript/build.gradle.kts @@ -20,6 +20,14 @@ android { testOptions { unitTests.isIncludeAndroidResources = true } + + sourceSets { + getByName("test") { + java.srcDirs( + "src/mobileDeviceTest/kotlin" + ) + } + } } dependencies { From a95eef24834f79d9e790a67d56b1d20d0ac1e32d Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Fri, 19 Sep 2025 18:14:56 +0700 Subject: [PATCH 20/21] fix tests sourcesets --- javascript/build.gradle.kts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/javascript/build.gradle.kts b/javascript/build.gradle.kts index 905f128..45fe53b 100644 --- a/javascript/build.gradle.kts +++ b/javascript/build.gradle.kts @@ -20,14 +20,6 @@ android { testOptions { unitTests.isIncludeAndroidResources = true } - - sourceSets { - getByName("test") { - java.srcDirs( - "src/mobileDeviceTest/kotlin" - ) - } - } } dependencies { From c7023cb0d6e59e2c93569dc7bfaa8bec6f2806be Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Fri, 19 Sep 2025 18:15:11 +0700 Subject: [PATCH 21/21] enable zipline plugin for bind call --- build.gradle.kts | 1 + javascript/build.gradle.kts | 1 + 2 files changed, 2 insertions(+) diff --git a/build.gradle.kts b/build.gradle.kts index 54c4572..5c22092 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -17,6 +17,7 @@ buildscript { } dependencies { classpath(libs.mokoGradlePlugin) + classpath("app.cash.zipline:zipline-gradle-plugin:1.23.0") classpath(":javascript-build-logic") } } diff --git a/javascript/build.gradle.kts b/javascript/build.gradle.kts index 45fe53b..4df8a6c 100644 --- a/javascript/build.gradle.kts +++ b/javascript/build.gradle.kts @@ -8,6 +8,7 @@ import org.gradle.api.tasks.testing.logging.TestLogEvent plugins { id("multiplatform-library-convention") id("publication-convention") + id("app.cash.zipline") } android {