diff --git a/build.gradle.kts b/build.gradle.kts index a90a252..63f38c3 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,8 +4,11 @@ plugins { alias(libs.plugins.com.android.application) apply false alias(libs.plugins.com.android.library) apply false alias(libs.plugins.org.jetbrains.kotlin.android) apply false + alias(libs.plugins.org.jetbrains.kotlin.native.cocoapods) apply false alias(libs.plugins.kotlin.multiplatform) apply false alias(libs.plugins.kotlin.serialization) apply false + alias(libs.plugins.kmm.bridge) apply false + alias(libs.plugins.skie) apply false } buildscript { dependencies { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index a176ae3..984be28 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -21,6 +21,8 @@ ktor = "2.3.7" prferences = "1.1.1" build-konfig = "0.15.1" koin = "3.5.3" +kmm-bridge = "0.5.1" +skie = "0.6.1" [libraries] ## Core-Ktx @@ -77,8 +79,11 @@ com-android-application = { id = "com.android.application", version.ref = "agp" com-android-library = { id = "com.android.library", version.ref = "agp" } kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } org-jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } +org-jetbrains-kotlin-native-cocoapods = { id = "org.jetbrains.kotlin.native.cocoapods", version.ref = "kotlin" } kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } build-konfig = { id = "com.codingfeline.buildkonfig" } +kmm-bridge = { id = "co.touchlab.kmmbridge" , version.ref = "kmm-bridge" } +skie = { id = "co.touchlab.skie", version.ref = "skie" } [bundles] ktor-android = [ diff --git a/shared/build.gradle.kts b/shared/build.gradle.kts index 68b5d43..ebd2acd 100644 --- a/shared/build.gradle.kts +++ b/shared/build.gradle.kts @@ -1,9 +1,18 @@ +import co.touchlab.skie.configuration.FlowInterop +import co.touchlab.skie.configuration.EnumInterop + @Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed plugins { alias(libs.plugins.kotlin.multiplatform) + alias(libs.plugins.org.jetbrains.kotlin.native.cocoapods) alias(libs.plugins.com.android.library) + alias(libs.plugins.kmm.bridge) + alias(libs.plugins.skie) + `maven-publish` } +version = "0.1" + kotlin { androidTarget { compilations.all { @@ -12,17 +21,10 @@ kotlin { } } } - - listOf( - iosX64(), - iosArm64(), - iosSimulatorArm64() - ).forEach { - it.binaries.framework { - baseName = "shared" - isStatic = true - } - } + + iosX64() + iosArm64() + iosSimulatorArm64() sourceSets { commonMain.dependencies { @@ -30,18 +32,41 @@ kotlin { implementation(libs.koin) // Shared Core Network Module - implementation(project(":shared:core-network")) + api(project(":shared:core-network")) // Shared Core Preferences Module - implementation(project(":shared:core-preferences")) + api(project(":shared:core-preferences")) // Shared Core Logger Module - implementation(project(":shared:core-logger")) + api(project(":shared:core-logger")) } commonTest.dependencies { implementation(libs.kotlin.test) } } + + cocoapods { + summary = "Spotify Kmp Shared Binary" + homepage = "https://github.com/AshuTyagi16/Spotify-KMP" + ios.deploymentTarget = "13.5" + extraSpecAttributes["libraries"] = "'c++', 'sqlite3'" + license = "BSD" + extraSpecAttributes["swift_version"] = "\"5.9.2\"" + framework { + // Shared Core Network Module + export(project(":shared:core-network")) + + // Shared Core Preferences Module + export(project(":shared:core-preferences")) + + // Shared Core Logger Module + export(project(":shared:core-logger")) + + isStatic = true + + binaryOption("bundleId", "com.spotify.app.shared") + } + } } android { @@ -51,3 +76,19 @@ android { minSdk = libs.versions.minSdkVersion.get().toInt() } } + +kmmbridge { + mavenPublishArtifacts() + spm() + cocoapods("git@github.com:AshuTyagi16/SpotifyKmpPodspec.git") +} + +skie { + features { + group { + FlowInterop.Enabled(true) + coroutinesInterop.set(true) + EnumInterop.Enabled(true) + } + } +} \ No newline at end of file diff --git a/shared/core-network/src/commonMain/kotlin/com/spotify/app/core_network/shared/impl/data/base/BaseDataSource.kt b/shared/core-network/src/commonMain/kotlin/com/spotify/app/core_network/shared/impl/data/base/BaseDataSource.kt index be1cf59..930c379 100644 --- a/shared/core-network/src/commonMain/kotlin/com/spotify/app/core_network/shared/impl/data/base/BaseDataSource.kt +++ b/shared/core-network/src/commonMain/kotlin/com/spotify/app/core_network/shared/impl/data/base/BaseDataSource.kt @@ -42,7 +42,7 @@ abstract class BaseDataSource { } NetworkErrorCodes.REFRESH_TOKEN_EXPIRED -> { - NetworkEventBus.invokeEvent(NetworkApiEvent.REFRESH_TOKEN_EXPIRED) + NetworkEventBus.INSTANCE.invokeEvent(NetworkApiEvent.REFRESH_TOKEN_EXPIRED) RestClientResult.error( errorMessage = NetworkErrorMessages.PLEASE_LOGIN_AGAIN, errorCode = statusCode diff --git a/shared/core-network/src/commonMain/kotlin/com/spotify/app/core_network/shared/impl/util/NetworkEventBus.kt b/shared/core-network/src/commonMain/kotlin/com/spotify/app/core_network/shared/impl/util/NetworkEventBus.kt index 10a9302..86da35c 100644 --- a/shared/core-network/src/commonMain/kotlin/com/spotify/app/core_network/shared/impl/util/NetworkEventBus.kt +++ b/shared/core-network/src/commonMain/kotlin/com/spotify/app/core_network/shared/impl/util/NetworkEventBus.kt @@ -1,9 +1,18 @@ +@file:OptIn(InternalCoroutinesApi::class) + package com.spotify.app.core_network.shared.impl.util +import kotlinx.coroutines.InternalCoroutinesApi import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.SharedFlow -object NetworkEventBus { +class NetworkEventBus private constructor() { + + companion object { + val INSTANCE by lazy { + NetworkEventBus() + } + } private val _events = MutableSharedFlow() val events: SharedFlow = _events diff --git a/shared/shared.podspec b/shared/shared.podspec new file mode 100644 index 0000000..9fbedec --- /dev/null +++ b/shared/shared.podspec @@ -0,0 +1,51 @@ +Pod::Spec.new do |spec| + spec.name = 'shared' + spec.version = '0.1' + spec.homepage = 'https://github.com/AshuTyagi16/Spotify-KMP' + spec.source = { :http=> ''} + spec.authors = '' + spec.license = 'BSD' + spec.summary = 'Spotify Kmp Shared Binary' + spec.vendored_frameworks = 'build/cocoapods/framework/shared.framework' + + spec.ios.deployment_target = '13.5' + + + if !Dir.exist?('build/cocoapods/framework/shared.framework') || Dir.empty?('build/cocoapods/framework/shared.framework') + raise " + + Kotlin framework 'shared' doesn't exist yet, so a proper Xcode project can't be generated. + 'pod install' should be executed after running ':generateDummyFramework' Gradle task: + + ./gradlew :shared:generateDummyFramework + + Alternatively, proper pod installation is performed during Gradle sync in the IDE (if Podfile location is set)" + end + + spec.pod_target_xcconfig = { + 'KOTLIN_PROJECT_PATH' => ':shared', + 'PRODUCT_MODULE_NAME' => 'shared', + } + + spec.script_phases = [ + { + :name => 'Build shared', + :execution_position => :before_compile, + :shell_path => '/bin/sh', + :script => <<-SCRIPT + if [ "YES" = "$OVERRIDE_KOTLIN_BUILD_IDE_SUPPORTED" ]; then + echo "Skipping Gradle build task invocation due to OVERRIDE_KOTLIN_BUILD_IDE_SUPPORTED environment variable set to \"YES\"" + exit 0 + fi + set -ev + REPO_ROOT="$PODS_TARGET_SRCROOT" + "$REPO_ROOT/../gradlew" -p "$REPO_ROOT" $KOTLIN_PROJECT_PATH:syncFramework \ + -Pkotlin.native.cocoapods.platform=$PLATFORM_NAME \ + -Pkotlin.native.cocoapods.archs="$ARCHS" \ + -Pkotlin.native.cocoapods.configuration="$CONFIGURATION" + SCRIPT + } + ] + spec.libraries = 'c++', 'sqlite3' + spec.swift_version = "5.9.2" +end \ No newline at end of file