Skip to content

Commit

Permalink
Added empty shared multiplatform module with gradle catalogue
Browse files Browse the repository at this point in the history
  • Loading branch information
AshuTyagi16 committed Dec 30, 2023
1 parent e6d18ea commit dd4d676
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
.externalNativeBuild
.cxx
local.properties
shared/build
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
@Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed
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.kotlin.multiplatform) apply false
}
true // Needed to make the Suppress annotation work for the plugins block
7 changes: 5 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jvmTargetVersion = "1.8"
kotlinCompilerExtensionVersion = "1.5.7"

agp = "8.1.4"
org-jetbrains-kotlin-android = "1.9.21"
kotlin = "1.9.21"
core-ktx = "1.12.0"
junit = "4.13.2"
androidx-test-ext-junit = "1.1.5"
Expand All @@ -18,6 +18,7 @@ compose-bom = "2023.10.01"

[libraries]
core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "core-ktx" }
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
junit = { group = "junit", name = "junit", version.ref = "junit" }
androidx-test-ext-junit = { group = "androidx.test.ext", name = "junit", version.ref = "androidx-test-ext-junit" }
espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espresso-core" }
Expand All @@ -34,7 +35,9 @@ material3 = { group = "androidx.compose.material3", name = "material3" }

[plugins]
com-android-application = { id = "com.android.application", version.ref = "agp" }
org-jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "org-jetbrains-kotlin-android" }
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" }

[bundles]

29 changes: 21 additions & 8 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
pluginManagement {
dependencyResolutionManagement {
repositories {
google()
google {
mavenContent {
includeGroupByRegex(".*google.*")
includeGroupByRegex(".*android.*")
}
}
mavenLocal()
mavenCentral()
gradlePluginPortal()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()

pluginManagement {
repositories {
google {
mavenContent {
includeGroupByRegex(".*google.*")
includeGroupByRegex(".*android.*")
}
}
mavenCentral()
gradlePluginPortal()
}
}
}

rootProject.name = "Spotify-KMP"
include(":app")
include(":shared")
43 changes: 43 additions & 0 deletions shared/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
@Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed
plugins {
alias(libs.plugins.kotlin.multiplatform)
alias(libs.plugins.com.android.library)
}

kotlin {
androidTarget {
compilations.all {
kotlinOptions {
jvmTarget = libs.versions.jvmTargetVersion.get()
}
}
}

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

sourceSets {
commonMain.dependencies {
//put your multiplatform dependencies here
}
commonTest.dependencies {
implementation(libs.kotlin.test)
}
}
}

android {
namespace = "com.spotify.app.shared"
compileSdk = libs.versions.compileSdkVersion.get().toInt()
defaultConfig {
minSdk = libs.versions.minSdkVersion.get().toInt()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.spotify.app.shared

class AndroidPlatform : Platform {
override val name: String = "Android ${android.os.Build.VERSION.SDK_INT}"
}

actual fun getPlatform(): Platform = AndroidPlatform()
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.spotify.app.shared

class Greeting {
private val platform: Platform = getPlatform()

fun greet(): String {
return "Hello, ${platform.name}!"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.spotify.app.shared

interface Platform {
val name: String
}

expect fun getPlatform(): Platform
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.spotify.app.shared

import platform.UIKit.UIDevice

class IOSPlatform: Platform {
override val name: String = UIDevice.currentDevice.systemName() + " " + UIDevice.currentDevice.systemVersion
}

actual fun getPlatform(): Platform = IOSPlatform()

0 comments on commit dd4d676

Please sign in to comment.