From f2a4eb36fa1de16573bfc4397056a60f1a539431 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Mlynari=C4=8D?= Date: Tue, 21 Jan 2025 00:27:05 +0100 Subject: [PATCH] Update versions + fix build (#44) * Update versions * Remove deprecated properties * Fix ios build * Select xcode version * Update Fruitties.yaml * Remove pods + use xcodeproj * Revert daemon * Disable native toolchain --- .github/workflows/Fruitties.yaml | 12 +- Fruitties/build.gradle.kts | 1 + Fruitties/gradle.properties | 5 +- Fruitties/gradle/libs.versions.toml | 51 +++--- .../gradle/wrapper/gradle-wrapper.properties | 2 +- .../iosApp/iosApp.xcodeproj/project.pbxproj | 5 +- Fruitties/shared/.gitignore | 1 + Fruitties/shared/build.gradle.kts | 151 ++++++++++++------ .../src/androidMain/AndroidManifest.xml | 4 + .../example/fruitties/di/Factory.native.kt | 0 .../di/viewmodel/IOSViewModelOwner.kt | 0 11 files changed, 149 insertions(+), 83 deletions(-) create mode 100644 Fruitties/shared/.gitignore create mode 100644 Fruitties/shared/src/androidMain/AndroidManifest.xml rename Fruitties/shared/src/{nativeMain => iosMain}/kotlin/com/example/fruitties/di/Factory.native.kt (100%) rename Fruitties/shared/src/{nativeMain => iosMain}/kotlin/com/example/fruitties/di/viewmodel/IOSViewModelOwner.kt (100%) diff --git a/.github/workflows/Fruitties.yaml b/.github/workflows/Fruitties.yaml index 179c850..714ed3b 100644 --- a/.github/workflows/Fruitties.yaml +++ b/.github/workflows/Fruitties.yaml @@ -36,6 +36,10 @@ jobs: name: Build iOS app runs-on: macos-latest steps: + - uses: maxim-lobanov/setup-xcode@v1 + with: + xcode-version: latest-stable + - name: Checkout uses: actions/checkout@v3 @@ -48,12 +52,6 @@ jobs: distribution: 'zulu' java-version: 17 - - name: Initialize pods - working-directory: ./Fruitties - run: | - cd iosApp - pod install --verbose - - name: Build app working-directory: ./Fruitties - run: xcodebuild -workspace iosApp/iosApp.xcworkspace -configuration Debug -scheme iosApp -sdk iphonesimulator + run: xcodebuild -project iosApp/iosApp.xcodeproj -configuration Debug -scheme iosApp -sdk iphonesimulator diff --git a/Fruitties/build.gradle.kts b/Fruitties/build.gradle.kts index e3d0901..684098d 100644 --- a/Fruitties/build.gradle.kts +++ b/Fruitties/build.gradle.kts @@ -21,6 +21,7 @@ plugins { alias(libs.plugins.kotlinMultiplatform) apply false alias(libs.plugins.compose.compiler) apply false alias(libs.plugins.spotless) apply false + alias(libs.plugins.androidKmpLibrary) apply false } subprojects { diff --git a/Fruitties/gradle.properties b/Fruitties/gradle.properties index 2869189..2fc6fa2 100644 --- a/Fruitties/gradle.properties +++ b/Fruitties/gradle.properties @@ -11,6 +11,5 @@ android.useAndroidX=true android.nonTransitiveRClass=true #KMP -kotlin.mpp.androidGradlePluginCompatibility.nowarn=true -# Disabled due to https://youtrack.jetbrains.com/issue/KT-65761 -kotlin.native.disableCompilerDaemon = true +# Disabled due to https://youtrack.jetbrains.com/issue/KT-74278/ +kotlin.native.toolchain.enabled=false diff --git a/Fruitties/gradle/libs.versions.toml b/Fruitties/gradle/libs.versions.toml index d5b96e9..32f7cf9 100644 --- a/Fruitties/gradle/libs.versions.toml +++ b/Fruitties/gradle/libs.versions.toml @@ -13,29 +13,33 @@ # limitations under the License. [versions] -agp = "8.5.2" -androidx-activityCompose = "1.9.1" -androidx-paging = "3.3.2" -androidx-room = "2.7.0-alpha07" -androidx-lifecycle = "2.9.0-alpha01" -atomicfu = "0.23.1" -compose = "1.7.0-rc01" -compose-material3 = "1.2.1" -dataStoreVersion = "1.1.1" -kotlin = "2.0.10" -kotlinx-coroutines = "1.8.0" -kotlinxDatetime = "0.6.0-RC.2" -ksp = "2.0.10-1.0.24" -ktorVersion = "2.3.8" -pagingComposeAndroid = "3.3.2" -skie = "0.8.4" -sqlite = "2.5.0-alpha07" -spotless = "6.19.0" +agp = "8.8.0" +androidx-activityCompose = "1.10.0" +androidx-paging = "3.3.5" +androidx-room = "2.7.0-alpha12" +androidx-lifecycle = "2.9.0-alpha08" +atomicfu = "0.27.0" +compose = "1.7.6" +compose-material3 = "1.3.1" +dataStore = "1.1.2" +kotlin = "2.1.0" +kotlinx-coroutines = "1.10.1" +kotlinxDatetime = "0.6.1" +ksp = "2.1.0-1.0.29" +ktorVersion = "2.3.13" +pagingComposeAndroid = "3.3.5" +skie = "0.10.0" +sqlite = "2.5.0-alpha12" +spotless = "7.0.2" +okio = "3.10.2" +runner = "1.6.2" +core = "1.6.1" +junit = "1.2.1" [libraries] androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activityCompose" } -androidx-datastore-core-okio = { group = "androidx.datastore", name = "datastore-core-okio", version.ref = "dataStoreVersion" } -androidx-datastore-preferences-core = { group = "androidx.datastore", name = "datastore-preferences-core", version.ref = "dataStoreVersion" } +androidx-datastore-core-okio = { group = "androidx.datastore", name = "datastore-core-okio", version.ref = "dataStore" } +androidx-datastore-preferences-core = { group = "androidx.datastore", name = "datastore-preferences-core", version.ref = "dataStore" } androidx-paging-common = { module = "androidx.paging:paging-common", version.ref = "androidx-paging" } androidx-paging-compose-android = { group = "androidx.paging", name = "paging-compose-android", version.ref = "pagingComposeAndroid" } androidx-room-compiler = { group = "androidx.room", name = "room-compiler", version.ref = "androidx-room" } @@ -59,15 +63,20 @@ ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktorVer ktor-client-darwin = { module = "io.ktor:ktor-client-darwin", version.ref = "ktorVersion" } ktor-client-okhttp = { module = "io.ktor:ktor-client-okhttp", version.ref = "ktorVersion" } ktor-serialization-kotlinx-json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktorVersion" } -okio = "com.squareup.okio:okio:3.9.0" +okio = { module = "com.squareup.okio:okio", version.ref = "okio" } skie-annotations = { module = "co.touchlab.skie:configuration-annotations", version.ref = "skie" } sqlite-bundled = { module = "androidx.sqlite:sqlite-bundled", version.ref = "sqlite" } +kotlin-stdlib = { group = "org.jetbrains.kotlin", name = "kotlin-stdlib", version.ref = "kotlin" } +androidx-runner = { group = "androidx.test", name = "runner", version.ref = "runner" } +androidx-core = { group = "androidx.test", name = "core", version.ref = "core" } +androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junit" } [plugins] androidApplication = { id = "com.android.application", version.ref = "agp" } androidLibrary = { id = "com.android.library", version.ref = "agp" } kotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } +androidKmpLibrary = { id = "com.android.kotlin.multiplatform.library", version.ref = "agp" } kotlinCocoapods = { id = "org.jetbrains.kotlin.native.cocoapods", version.ref = "kotlin" } kotlinxSerialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" } diff --git a/Fruitties/gradle/wrapper/gradle-wrapper.properties b/Fruitties/gradle/wrapper/gradle-wrapper.properties index 9355b41..e2847c8 100644 --- a/Fruitties/gradle/wrapper/gradle-wrapper.properties +++ b/Fruitties/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/Fruitties/iosApp/iosApp.xcodeproj/project.pbxproj b/Fruitties/iosApp/iosApp.xcodeproj/project.pbxproj index d5149a9..18a39cc 100644 --- a/Fruitties/iosApp/iosApp.xcodeproj/project.pbxproj +++ b/Fruitties/iosApp/iosApp.xcodeproj/project.pbxproj @@ -100,7 +100,7 @@ isa = PBXNativeTarget; buildConfigurationList = 7555FFA5242A565B00829871 /* Build configuration list for PBXNativeTarget "iosApp" */; buildPhases = ( - 7555FFB5242A651A00829871 /* ShellScript */, + 7555FFB5242A651A00829871 /* Compile Kotlin Multiplatform */, 7555FF77242A565900829871 /* Sources */, 7555FF78242A565900829871 /* Frameworks */, 7555FF79242A565900829871 /* Resources */, @@ -161,7 +161,7 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ - 7555FFB5242A651A00829871 /* ShellScript */ = { + 7555FFB5242A651A00829871 /* Compile Kotlin Multiplatform */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( @@ -170,6 +170,7 @@ ); inputPaths = ( ); + name = "Compile Kotlin Multiplatform"; outputFileListPaths = ( ); outputPaths = ( diff --git a/Fruitties/shared/.gitignore b/Fruitties/shared/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/Fruitties/shared/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/Fruitties/shared/build.gradle.kts b/Fruitties/shared/build.gradle.kts index 5c578ff..0abf420 100644 --- a/Fruitties/shared/build.gradle.kts +++ b/Fruitties/shared/build.gradle.kts @@ -18,7 +18,7 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget plugins { alias(libs.plugins.kotlinMultiplatform) - alias(libs.plugins.androidLibrary) + alias(libs.plugins.androidKmpLibrary) alias(libs.plugins.kotlinxSerialization) alias(libs.plugins.skie) alias(libs.plugins.ksp) @@ -26,66 +26,119 @@ plugins { } kotlin { - @OptIn(ExperimentalKotlinGradlePluginApi::class) - compilerOptions { - androidTarget { - // compilerOptions DSL: https://kotl.in/u1r8ln - compilerOptions.jvmTarget.set(JvmTarget.JVM_1_8) + + // Target declarations - add or remove as needed below. These define + // which platforms this KMP module supports. + // See: https://kotlinlang.org/docs/multiplatform-discover-project.html#targets + androidLibrary { + namespace = "com.example.fruitties" + compileSdk = 35 + minSdk = 26 + + withHostTestBuilder { + } + + withDeviceTestBuilder { + sourceSetTreeName = "test" + }.configure { + instrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } } - listOf( - iosX64(), - iosArm64(), - iosSimulatorArm64(), - ).forEach { - it.binaries.framework { - baseName = "shared" - isStatic = true + + // For iOS targets, this is also where you should + // configure native binary output. For more information, see: + // https://kotlinlang.org/docs/multiplatform-build-native-binaries.html#build-xcframeworks + + // A step-by-step guide on how to include this library in an XCode + // project can be found here: + // https://developer.android.com/kotlin/multiplatform/migrate + val xcfName = "shared" + + iosX64 { + binaries.framework { + baseName = xcfName + } + } + + iosArm64 { + binaries.framework { + baseName = xcfName } } - sourceSets.all { - languageSettings.optIn("kotlin.experimental.ExperimentalObjCName") + + iosSimulatorArm64 { + binaries.framework { + baseName = xcfName + } } + + // Source set declarations. + // Declaring a target automatically creates a source set with the same name. By default, the + // Kotlin Gradle Plugin creates additional source sets that depend on each other, since it is + // common to share sources between related targets. + // See: https://kotlinlang.org/docs/multiplatform-hierarchy.html sourceSets { - commonMain.dependencies { - // put your multiplatform dependencies here - implementation(libs.kotlinx.datetime) - implementation(libs.kotlinx.coroutines.core) - implementation(libs.ktor.client.core) - implementation(libs.ktor.client.content.negotiation) - implementation(libs.ktor.serialization.kotlinx.json) - implementation(libs.skie.annotations) - implementation(libs.androidx.lifecycle.viewmodel) - implementation(libs.androidx.paging.common) - implementation(libs.androidx.room.runtime) - implementation(libs.sqlite.bundled) - implementation(libs.kotlinx.atomicfu) - api(libs.androidx.datastore.preferences.core) - api(libs.androidx.datastore.core.okio) - implementation(libs.okio) + all { + languageSettings.optIn("kotlin.experimental.ExperimentalObjCName") } - commonTest.dependencies { + + commonMain { + dependencies { + implementation(libs.kotlin.stdlib) + // Add KMP dependencies here + implementation(libs.kotlinx.datetime) + implementation(libs.kotlinx.coroutines.core) + implementation(libs.ktor.client.core) + implementation(libs.ktor.client.content.negotiation) + implementation(libs.ktor.serialization.kotlinx.json) + implementation(libs.skie.annotations) + implementation(libs.androidx.lifecycle.viewmodel) + implementation(libs.androidx.paging.common) + implementation(libs.androidx.room.runtime) + implementation(libs.sqlite.bundled) + implementation(libs.kotlinx.atomicfu) + api(libs.androidx.datastore.preferences.core) + api(libs.androidx.datastore.core.okio) + implementation(libs.okio) + } } - androidMain.dependencies { - implementation(libs.ktor.client.okhttp) - implementation(libs.androidx.room.paging) + + commonTest { + dependencies { + implementation(libs.kotlin.test) + } } - iosMain.dependencies { - implementation(libs.ktor.client.darwin) + + androidMain { + dependencies { + // Add Android-specific dependencies here. Note that this source set depends on + // commonMain by default and will correctly pull the Android artifacts of any KMP + // dependencies declared in commonMain. + implementation(libs.ktor.client.okhttp) + implementation(libs.androidx.room.paging) + } } - } -} -android { - namespace = "com.example.fruitties" - compileSdk = 34 - defaultConfig { - minSdk = 26 - } - compileOptions { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 + getByName("androidDeviceTest") { + dependencies { + implementation(libs.androidx.runner) + implementation(libs.androidx.core) + implementation(libs.androidx.junit) + } + } + + iosMain { + dependencies { + // Add iOS-specific dependencies here. This a source set created by Kotlin Gradle + // Plugin (KGP) that each specific iOS target (e.g., iosX64) depends on as + // part of KMP’s default source set hierarchy. Note that this source set depends + // on common by default and will correctly pull the iOS artifacts of any + // KMP dependencies declared in commonMain. + implementation(libs.ktor.client.darwin) + } + } } + } dependencies { diff --git a/Fruitties/shared/src/androidMain/AndroidManifest.xml b/Fruitties/shared/src/androidMain/AndroidManifest.xml new file mode 100644 index 0000000..a5918e6 --- /dev/null +++ b/Fruitties/shared/src/androidMain/AndroidManifest.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Fruitties/shared/src/nativeMain/kotlin/com/example/fruitties/di/Factory.native.kt b/Fruitties/shared/src/iosMain/kotlin/com/example/fruitties/di/Factory.native.kt similarity index 100% rename from Fruitties/shared/src/nativeMain/kotlin/com/example/fruitties/di/Factory.native.kt rename to Fruitties/shared/src/iosMain/kotlin/com/example/fruitties/di/Factory.native.kt diff --git a/Fruitties/shared/src/nativeMain/kotlin/com/example/fruitties/di/viewmodel/IOSViewModelOwner.kt b/Fruitties/shared/src/iosMain/kotlin/com/example/fruitties/di/viewmodel/IOSViewModelOwner.kt similarity index 100% rename from Fruitties/shared/src/nativeMain/kotlin/com/example/fruitties/di/viewmodel/IOSViewModelOwner.kt rename to Fruitties/shared/src/iosMain/kotlin/com/example/fruitties/di/viewmodel/IOSViewModelOwner.kt