From 7c01853629814948cfd95177e0cb73bcb791505e Mon Sep 17 00:00:00 2001 From: michaelbel Date: Thu, 2 Nov 2023 06:30:13 +0300 Subject: [PATCH] Multiplatform --- {app => android-app}/.gitignore | 0 {app => android-app}/benchmark-rules.pro | 0 {app => android-app}/build.gradle.kts | 0 {app => android-app}/coroutines.pro | 0 {app => android-app}/google-services.json | 0 {app => android-app}/okhttp3.pro | 0 {app => android-app}/proguard-rules.pro | 0 {app => android-app}/retrofit2.pro | 0 .../src/debug/google-services.json | 0 .../src/main/AndroidManifest.xml | 0 .../main/kotlin/org/michaelbel/movies/App.kt | 0 .../org/michaelbel/movies/MainActivity.kt | 0 .../michaelbel/movies/MainActivityContent.kt | 0 .../org/michaelbel/movies/MainViewModel.kt | 0 .../src/main/res/values/strings.xml | 0 .../main/res/xml/data_extraction_rules.xml | 0 .../src/main/res/xml/locale_config.xml | 0 benchmark/build.gradle.kts | 2 +- instant/build.gradle.kts | 2 +- settings.gradle.kts | 5 +- shared/build.gradle.kts | 50 +++++++++++++++++++ .../movies/shared/Platform.android.kt | 9 ++++ .../org/michaelbel/movies/shared/Greeting.kt | 9 ++++ .../org/michaelbel/movies/shared/Platform.kt | 7 +++ .../michaelbel/movies/shared/Platform.ios.kt | 9 ++++ 25 files changed, 89 insertions(+), 4 deletions(-) rename {app => android-app}/.gitignore (100%) rename {app => android-app}/benchmark-rules.pro (100%) rename {app => android-app}/build.gradle.kts (100%) rename {app => android-app}/coroutines.pro (100%) rename {app => android-app}/google-services.json (100%) rename {app => android-app}/okhttp3.pro (100%) rename {app => android-app}/proguard-rules.pro (100%) rename {app => android-app}/retrofit2.pro (100%) rename {app => android-app}/src/debug/google-services.json (100%) rename {app => android-app}/src/main/AndroidManifest.xml (100%) rename {app => android-app}/src/main/kotlin/org/michaelbel/movies/App.kt (100%) rename {app => android-app}/src/main/kotlin/org/michaelbel/movies/MainActivity.kt (100%) rename {app => android-app}/src/main/kotlin/org/michaelbel/movies/MainActivityContent.kt (100%) rename {app => android-app}/src/main/kotlin/org/michaelbel/movies/MainViewModel.kt (100%) rename {app => android-app}/src/main/res/values/strings.xml (100%) rename {app => android-app}/src/main/res/xml/data_extraction_rules.xml (100%) rename {app => android-app}/src/main/res/xml/locale_config.xml (100%) create mode 100644 shared/build.gradle.kts create mode 100644 shared/src/androidMain/kotlin/org/michaelbel/movies/shared/Platform.android.kt create mode 100644 shared/src/commonMain/kotlin/org/michaelbel/movies/shared/Greeting.kt create mode 100644 shared/src/commonMain/kotlin/org/michaelbel/movies/shared/Platform.kt create mode 100644 shared/src/iosMain/kotlin/org/michaelbel/movies/shared/Platform.ios.kt diff --git a/app/.gitignore b/android-app/.gitignore similarity index 100% rename from app/.gitignore rename to android-app/.gitignore diff --git a/app/benchmark-rules.pro b/android-app/benchmark-rules.pro similarity index 100% rename from app/benchmark-rules.pro rename to android-app/benchmark-rules.pro diff --git a/app/build.gradle.kts b/android-app/build.gradle.kts similarity index 100% rename from app/build.gradle.kts rename to android-app/build.gradle.kts diff --git a/app/coroutines.pro b/android-app/coroutines.pro similarity index 100% rename from app/coroutines.pro rename to android-app/coroutines.pro diff --git a/app/google-services.json b/android-app/google-services.json similarity index 100% rename from app/google-services.json rename to android-app/google-services.json diff --git a/app/okhttp3.pro b/android-app/okhttp3.pro similarity index 100% rename from app/okhttp3.pro rename to android-app/okhttp3.pro diff --git a/app/proguard-rules.pro b/android-app/proguard-rules.pro similarity index 100% rename from app/proguard-rules.pro rename to android-app/proguard-rules.pro diff --git a/app/retrofit2.pro b/android-app/retrofit2.pro similarity index 100% rename from app/retrofit2.pro rename to android-app/retrofit2.pro diff --git a/app/src/debug/google-services.json b/android-app/src/debug/google-services.json similarity index 100% rename from app/src/debug/google-services.json rename to android-app/src/debug/google-services.json diff --git a/app/src/main/AndroidManifest.xml b/android-app/src/main/AndroidManifest.xml similarity index 100% rename from app/src/main/AndroidManifest.xml rename to android-app/src/main/AndroidManifest.xml diff --git a/app/src/main/kotlin/org/michaelbel/movies/App.kt b/android-app/src/main/kotlin/org/michaelbel/movies/App.kt similarity index 100% rename from app/src/main/kotlin/org/michaelbel/movies/App.kt rename to android-app/src/main/kotlin/org/michaelbel/movies/App.kt diff --git a/app/src/main/kotlin/org/michaelbel/movies/MainActivity.kt b/android-app/src/main/kotlin/org/michaelbel/movies/MainActivity.kt similarity index 100% rename from app/src/main/kotlin/org/michaelbel/movies/MainActivity.kt rename to android-app/src/main/kotlin/org/michaelbel/movies/MainActivity.kt diff --git a/app/src/main/kotlin/org/michaelbel/movies/MainActivityContent.kt b/android-app/src/main/kotlin/org/michaelbel/movies/MainActivityContent.kt similarity index 100% rename from app/src/main/kotlin/org/michaelbel/movies/MainActivityContent.kt rename to android-app/src/main/kotlin/org/michaelbel/movies/MainActivityContent.kt diff --git a/app/src/main/kotlin/org/michaelbel/movies/MainViewModel.kt b/android-app/src/main/kotlin/org/michaelbel/movies/MainViewModel.kt similarity index 100% rename from app/src/main/kotlin/org/michaelbel/movies/MainViewModel.kt rename to android-app/src/main/kotlin/org/michaelbel/movies/MainViewModel.kt diff --git a/app/src/main/res/values/strings.xml b/android-app/src/main/res/values/strings.xml similarity index 100% rename from app/src/main/res/values/strings.xml rename to android-app/src/main/res/values/strings.xml diff --git a/app/src/main/res/xml/data_extraction_rules.xml b/android-app/src/main/res/xml/data_extraction_rules.xml similarity index 100% rename from app/src/main/res/xml/data_extraction_rules.xml rename to android-app/src/main/res/xml/data_extraction_rules.xml diff --git a/app/src/main/res/xml/locale_config.xml b/android-app/src/main/res/xml/locale_config.xml similarity index 100% rename from app/src/main/res/xml/locale_config.xml rename to android-app/src/main/res/xml/locale_config.xml diff --git a/benchmark/build.gradle.kts b/benchmark/build.gradle.kts index 53e0a193e..148ea5707 100644 --- a/benchmark/build.gradle.kts +++ b/benchmark/build.gradle.kts @@ -33,7 +33,7 @@ android { targetCompatibility = JavaVersion.VERSION_17 } - targetProjectPath = ":app" + targetProjectPath = ":android-app" experimentalProperties["android.experimental.self-instrumenting"] = true } diff --git a/instant/build.gradle.kts b/instant/build.gradle.kts index 6ab87a971..b9d8b8b12 100644 --- a/instant/build.gradle.kts +++ b/instant/build.gradle.kts @@ -26,7 +26,7 @@ android { } dependencies { - implementation(project(":app")) + implementation(project(":android-app")) implementation(project(":core:common")) implementation(project(":core:ui")) implementation(libs.androidx.activity.compose) diff --git a/settings.gradle.kts b/settings.gradle.kts index 3336a6870..59966c40b 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -7,7 +7,7 @@ pluginManagement { } dependencyResolutionManagement { - repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + //repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { mavenCentral() google() @@ -17,9 +17,10 @@ dependencyResolutionManagement { rootProject.name = "movies" include( - ":app", + ":android-app", ":instant", ":benchmark", + ":shared", ":core:analytics", ":core:common", diff --git a/shared/build.gradle.kts b/shared/build.gradle.kts new file mode 100644 index 000000000..aaa3e5203 --- /dev/null +++ b/shared/build.gradle.kts @@ -0,0 +1,50 @@ +plugins { + kotlin("multiplatform") + alias(libs.plugins.library) +} + +@OptIn(org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi::class) +kotlin { + targetHierarchy.default() + + androidTarget { + compilations.all { + kotlinOptions { + jvmTarget = "1.8" + } + } + } + + listOf( + iosX64(), + iosArm64(), + iosSimulatorArm64() + ).forEach { + it.binaries.framework { + baseName = "shared" + } + } + + sourceSets { + val commonMain by getting { + dependencies { + //put your multiplatform dependencies here + } + } + val commonTest by getting { + dependencies { + //implementation(libs.kotlin.test) + } + } + } +} + +android { + namespace = "org.michaelbel.movies.shared" + + compileSdk = libs.versions.compile.sdk.get().toInt() + + defaultConfig { + minSdk = libs.versions.min.sdk.get().toInt() + } +} \ No newline at end of file diff --git a/shared/src/androidMain/kotlin/org/michaelbel/movies/shared/Platform.android.kt b/shared/src/androidMain/kotlin/org/michaelbel/movies/shared/Platform.android.kt new file mode 100644 index 000000000..c48b9e150 --- /dev/null +++ b/shared/src/androidMain/kotlin/org/michaelbel/movies/shared/Platform.android.kt @@ -0,0 +1,9 @@ +package org.michaelbel.movies.shared + +import android.os.Build + +class AndroidPlatform: Platform { + override val name: String = "Android ${Build.VERSION.SDK_INT}" +} + +actual fun getPlatform(): Platform = AndroidPlatform() \ No newline at end of file diff --git a/shared/src/commonMain/kotlin/org/michaelbel/movies/shared/Greeting.kt b/shared/src/commonMain/kotlin/org/michaelbel/movies/shared/Greeting.kt new file mode 100644 index 000000000..c0b5468e0 --- /dev/null +++ b/shared/src/commonMain/kotlin/org/michaelbel/movies/shared/Greeting.kt @@ -0,0 +1,9 @@ +package org.michaelbel.movies.shared + +class Greeting { + private val platform: Platform = getPlatform() + + fun greet(): String { + return "Hello, ${platform.name}!" + } +} \ No newline at end of file diff --git a/shared/src/commonMain/kotlin/org/michaelbel/movies/shared/Platform.kt b/shared/src/commonMain/kotlin/org/michaelbel/movies/shared/Platform.kt new file mode 100644 index 000000000..0b40f10c5 --- /dev/null +++ b/shared/src/commonMain/kotlin/org/michaelbel/movies/shared/Platform.kt @@ -0,0 +1,7 @@ +package org.michaelbel.movies.shared + +interface Platform { + val name: String +} + +expect fun getPlatform(): Platform \ No newline at end of file diff --git a/shared/src/iosMain/kotlin/org/michaelbel/movies/shared/Platform.ios.kt b/shared/src/iosMain/kotlin/org/michaelbel/movies/shared/Platform.ios.kt new file mode 100644 index 000000000..4955719c1 --- /dev/null +++ b/shared/src/iosMain/kotlin/org/michaelbel/movies/shared/Platform.ios.kt @@ -0,0 +1,9 @@ +package org.michaelbel.movies.shared + +import platform.UIKit.UIDevice + +class IOSPlatform: Platform { + override val name: String = UIDevice.currentDevice.systemName() + " " + UIDevice.currentDevice.systemVersion +} + +actual fun getPlatform(): Platform = IOSPlatform() \ No newline at end of file