Skip to content

Commit

Permalink
Fix - iOS app not building (#285)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandregpereira authored Jul 7, 2024
1 parent aae0977 commit b858a85
Show file tree
Hide file tree
Showing 23 changed files with 38 additions and 59 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ multiplatform {
}

jvmMain()
iosMain(iosFramework = { linkerOpts("-l", "sqlite3") })
iosMain()

jvmTest {
implementation(libs.bundles.unittest)
Expand Down
4 changes: 2 additions & 2 deletions buildSrc/src/main/kotlin/TargetConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ fun KotlinMultiplatformExtension.jvmTest(block: KotlinDependencyHandler.() -> Un
}

fun KotlinMultiplatformExtension.iosMain(
iosFramework: Framework.() -> Unit = {},
block: KotlinDependencyHandler.() -> Unit = {}
) {
if (Os.isArch("aarch64")) {
Expand All @@ -90,7 +89,8 @@ fun KotlinMultiplatformExtension.iosMain(
)
}.onEach {
it.binaries.framework {
iosFramework()
baseName = "KotlinApp"
isStatic = true
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ internal actual fun getAdditionalModule(): List<Module> {
return listOf(
module {
factory { get<Context>().getSharedPreferences("preferences", Context.MODE_PRIVATE) }
factory { DriverFactory(get()) }
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import android.content.Context
import br.alexandregpereira.hunter.data.Database
import com.squareup.sqldelight.android.AndroidSqliteDriver
import com.squareup.sqldelight.db.SqlDriver
import org.koin.core.scope.Scope

actual class DriverFactory(private val context: Context) {
actual fun createDriver(): SqlDriver {
return AndroidSqliteDriver(Database.Schema, context, "hunter-database")
}
internal actual fun Scope.createSqlDriver(): SqlDriver {
val context = get<Context>()
return AndroidSqliteDriver(Database.Schema, context, "hunter-database")
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import org.koin.dsl.module

val databaseModule = module {
single {
createDatabase(get())
Database(createSqlDriver())
}
factory<AlternativeSourceDao> {
AlternativeSourceDaoImpl(
Expand Down Expand Up @@ -82,8 +82,3 @@ val databaseModule = module {
}

expect fun getDispatcherIO(): CoroutineDispatcher

private fun createDatabase(driverFactory: DriverFactory): Database {
val driver = driverFactory.createDriver()
return Database(driver)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package br.alexandregpereira.hunter.data.di

import com.squareup.sqldelight.db.SqlDriver
import org.koin.core.scope.Scope

expect class DriverFactory {
fun createDriver(): SqlDriver
}
internal expect fun Scope.createSqlDriver(): SqlDriver
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,7 @@ package br.alexandregpereira.hunter.data.di
import br.alexandregpereira.hunter.data.IosDispatchers
import kotlinx.coroutines.CoroutineDispatcher
import org.koin.core.module.Module
import org.koin.dsl.module

internal actual fun getAdditionalModule(): List<Module> {
return listOf(
module {
factory { DriverFactory() }
}
)
}
internal actual fun getAdditionalModule(): List<Module> = emptyList()

actual fun getDispatcherIO(): CoroutineDispatcher = IosDispatchers.IO
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ package br.alexandregpereira.hunter.data.di
import br.alexandregpereira.hunter.data.Database
import com.squareup.sqldelight.db.SqlDriver
import com.squareup.sqldelight.drivers.native.NativeSqliteDriver
import org.koin.core.scope.Scope

actual class DriverFactory{
actual fun createDriver(): SqlDriver {
return NativeSqliteDriver(Database.Schema, "hunter-database")
}
internal actual fun Scope.createSqlDriver(): SqlDriver {
return NativeSqliteDriver(Database.Schema, "hunter-database")
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,7 @@ package br.alexandregpereira.hunter.data.di
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
import org.koin.core.module.Module
import org.koin.dsl.module

internal actual fun getAdditionalModule(): List<Module> {
return listOf(
module {
factory { DriverFactory() }
}
)
}
internal actual fun getAdditionalModule(): List<Module> = emptyList()

actual fun getDispatcherIO(): CoroutineDispatcher = Dispatchers.IO
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ package br.alexandregpereira.hunter.data.di
import br.alexandregpereira.hunter.data.Database
import com.squareup.sqldelight.db.SqlDriver
import com.squareup.sqldelight.sqlite.driver.JdbcSqliteDriver
import org.koin.core.scope.Scope

actual class DriverFactory{
actual fun createDriver(): SqlDriver {
val driver: SqlDriver = JdbcSqliteDriver(JdbcSqliteDriver.IN_MEMORY)
Database.Schema.create(driver)
return driver
}
internal actual fun Scope.createSqlDriver(): SqlDriver {
val driver: SqlDriver = JdbcSqliteDriver(JdbcSqliteDriver.IN_MEMORY)
Database.Schema.create(driver)
return driver
}
10 changes: 6 additions & 4 deletions iosApp/MonsterCompendium.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"MonsterCompendium/Preview Content\"";
ENABLE_PREVIEWS = YES;
FRAMEWORK_SEARCH_PATHS = "$(SRCROOT)/../shared/build/xcode-frameworks/$(CONFIGURATION)/$(SDK_NAME)";
FRAMEWORK_SEARCH_PATHS = "$(SRCROOT)/../app/build/xcode-frameworks/$(CONFIGURATION)/$(SDK_NAME)";
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
Expand All @@ -584,8 +584,9 @@
MARKETING_VERSION = 1.0;
OTHER_LDFLAGS = (
"$(inherited)",
"-lsqlite3",
"-framework",
shared,
KotlinApp,
);
PRODUCT_BUNDLE_IDENTIFIER = br.alexandregpereira.MonsterCompendium;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -604,7 +605,7 @@
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"MonsterCompendium/Preview Content\"";
ENABLE_PREVIEWS = YES;
FRAMEWORK_SEARCH_PATHS = "$(SRCROOT)/../shared/build/xcode-frameworks/$(CONFIGURATION)/$(SDK_NAME)";
FRAMEWORK_SEARCH_PATHS = "$(SRCROOT)/../app/build/xcode-frameworks/$(CONFIGURATION)/$(SDK_NAME)";
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
Expand All @@ -618,8 +619,9 @@
MARKETING_VERSION = 1.0;
OTHER_LDFLAGS = (
"$(inherited)",
"-lsqlite3",
"-framework",
shared,
KotlinApp,
);
PRODUCT_BUNDLE_IDENTIFIER = br.alexandregpereira.MonsterCompendium;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//

import Foundation
import shared
import KotlinApp

@MainActor class MonsterCompendiumViewModel : ObservableObject {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//

import Foundation
import shared
import KotlinApp

extension MonsterCompendiumItemState {
static let sampleData: [MonsterCompendiumItemState] = (0...100).map {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by Alexandre G Pereira on 29/01/23.
//

import shared
import KotlinApp
import SwiftUI

struct MonsterCompendiumView: View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by Alexandre G Pereira on 08/03/23.
//

import shared
import KotlinApp
import SwiftUI

struct TableContentPopup: View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by Alexandre G Pereira on 08/03/23.
//

import shared
import KotlinApp
import SwiftUI

struct TableContent: View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//

import Foundation
import shared
import KotlinApp

class MonsterDetailStringsWrapper: ObservableObject {
@Published var value: MonsterDetailStrings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//

import Foundation
import shared
import KotlinApp

@MainActor class MonsterDetailViewModel : ObservableObject {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by Alexandre G Pereira on 26/03/23.
//

import shared
import KotlinApp
import SwiftUI

// Not working properly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by Alexandre G Pereira on 02/03/23.
//

import shared
import KotlinApp
import SwiftUI

struct MonsterDetailView : View {
Expand Down
2 changes: 1 addition & 1 deletion iosApp/MonsterCompendium/MonsterCompendiumApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//

import SwiftUI
import shared
import KotlinApp

@main
struct MonsterCompendiumApp: App {
Expand Down
2 changes: 1 addition & 1 deletion iosApp/MonsterCompendium/UI/MonsterCardView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//

import SDWebImageSwiftUI
import shared
import KotlinApp
import SwiftUI

struct MonsterCardView: View {
Expand Down
2 changes: 1 addition & 1 deletion iosApp/MonsterCompendium/UI/MonsterUiState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//

import Foundation
import shared
import KotlinApp

struct MonsterUiState {
let index: String
Expand Down

0 comments on commit b858a85

Please sign in to comment.