Skip to content

Commit

Permalink
Added KMMbridge & SKIE
Browse files Browse the repository at this point in the history
  • Loading branch information
AshuTyagi16 committed Jan 6, 2024
1 parent 69cdbdf commit be25713
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 16 deletions.
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = [
Expand Down
69 changes: 55 additions & 14 deletions shared/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -12,36 +21,52 @@ kotlin {
}
}
}

listOf(
iosX64(),
iosArm64(),
iosSimulatorArm64()
).forEach {
it.binaries.framework {
baseName = "shared"
isStatic = true
}
}

iosX64()
iosArm64()
iosSimulatorArm64()

sourceSets {
commonMain.dependencies {
// Koin
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 {
Expand All @@ -51,3 +76,19 @@ android {
minSdk = libs.versions.minSdkVersion.get().toInt()
}
}

kmmbridge {
mavenPublishArtifacts()
spm()
cocoapods("[email protected]:AshuTyagi16/SpotifyKmpPodspec.git")
}

skie {
features {
group {
FlowInterop.Enabled(true)
coroutinesInterop.set(true)
EnumInterop.Enabled(true)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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<NetworkApiEvent>()
val events: SharedFlow<NetworkApiEvent> = _events
Expand Down
51 changes: 51 additions & 0 deletions shared/shared.podspec
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit be25713

Please sign in to comment.