Skip to content

Commit

Permalink
Issue #7 - Move http and serialization to common
Browse files Browse the repository at this point in the history
Create a fake `app-ios-lib` module as a workaround for JetBrains/kotlin-native#2423.
Update `app-ios` project due to changed framework name.
Still not using Kotlin classes for REST + JSON though (for now).
  • Loading branch information
4ntoine committed Dec 29, 2019
1 parent d544180 commit cebb22a
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 41 deletions.
17 changes: 1 addition & 16 deletions app-infra-rest-ktor/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ plugins {
id 'idea'
id 'kotlin-multiplatform'
id 'kotlinx-serialization'
id 'org.jetbrains.kotlin.native.cocoapods'
}

kotlin {
Expand Down Expand Up @@ -65,18 +64,4 @@ kotlin {
}
}

version = "$rootProject.module_version"

kotlin {
cocoapods {
summary = "Infra REST (HTTP + JSON) of NotesClientApp"
homepage = "https://github.com/4ntoine/NotesClientApp"
}

targets.iosX64.binaries
.findAll { it instanceof org.jetbrains.kotlin.gradle.plugin.mpp.Framework }
.every {
it.export "name.antonsmirnov.notes:app-api-iosx64:$rootProject.server_module_version"
it.transitiveExport = true
}
}
version = "$rootProject.module_version"
76 changes: 76 additions & 0 deletions app-ios-lib/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
plugins {
id 'kotlin-multiplatform'
id('org.jetbrains.kotlin.native.cocoapods')
}

kotlin {
targets {
jvm()
iosX64() // iOS simulator
}

sourceSets {
commonMain {
kotlin.srcDirs = [
"${project.rootDir}/app-mvp/src/commonMain/kotlin",
"${project.rootDir}/app-infra-rest-ktor/src/commonMain/kotlin"
]
dependencies {
// # using of `implementation project(':...)` does not work and leads to compilation error:
// java.lang.IllegalStateException: IrClassSymbolImpl for deserialized class AddResponseJson is already bound
// (I believe it's because of `app-api` imported twice (1 for both project))
// implementation project(':app-infra-rest-ktor')
// implementation project(':app-mvp')

// # -ktor deps
api "io.ktor:ktor-client-core:$rootProject.ktor_version"
api "io.ktor:ktor-client-serialization:$rootProject.ktor_version"
api "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$rootProject.coroutines_version"
// # both -ktor and -mvp deps
implementation 'org.jetbrains.kotlin:kotlin-stdlib'
api "name.antonsmirnov.notes:app-api-metadata:$rootProject.server_module_version"
}
}
iosX64Main {
kotlin.srcDirs = [
"${project.rootDir}/app-infra-rest-ktor/src/iosX64Main"
]
dependencies {
// # -ktor deps
implementation "io.ktor:ktor-client-ios:$rootProject.ktor_version"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:$rootProject.serialization_version"
implementation "io.ktor:ktor-client-serialization-native:$rootProject.ktor_version"
// # both -ktor and -mvp deps
api "name.antonsmirnov.notes:app-api-iosx64:$rootProject.server_module_version"
}
}
}

// All exceptions in Kotlin are not checked, but in Swift they are checked.
// So we need @Throws annotation for iOS compatibility to generate swift signatures with `.. throws -> ..`
// This requires @ExperimentalMultiplatform annotation in all methods with @Throws.
// In order to prevent adding @ExperimentalMultiplatform every here and there we can use compiler option:
targets.all {
compilations.all {
kotlinOptions {
freeCompilerArgs += '-Xuse-experimental=kotlin.ExperimentalMultiplatform'
}
}
}
}

version = "$rootProject.module_version"

kotlin {
cocoapods {
summary = "iOS Kotlin library of NotesClientApp"
homepage = "https://github.com/4ntoine/NotesClientApp"
}

targets.iosX64.binaries
.findAll { it instanceof org.jetbrains.kotlin.gradle.plugin.mpp.Framework }
.every {
it.export "name.antonsmirnov.notes:app-api-iosx64:$rootProject.server_module_version"
it.transitiveExport = true
}
}
5 changes: 3 additions & 2 deletions app-ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use_frameworks!
platform :ios, '9.0'

target 'app-ios' do
pod 'app_mvp', :path => '../app-mvp'
pod 'app_infra_rest_ktor', :path => '../app-infra-rest-ktor'
pod 'app_ios_lib', :path => '../app-ios-lib'
# pod 'app_mvp', :path => '../app-mvp'
# pod 'app_infra_rest_ktor', :path => '../app-infra-rest-ktor'
end
2 changes: 1 addition & 1 deletion app-ios/app-ios/Rest/Deserializer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

import Foundation
import app_mvp
import app_ios_lib

protocol Deserializer {
func deserializeListNotes(data: Data) throws -> ListNotesResponse
Expand Down
2 changes: 1 addition & 1 deletion app-ios/app-ios/Rest/RestApi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

import Foundation
import app_mvp
import app_ios_lib

protocol RestApi : ListNotes, AddNote {

Expand Down
2 changes: 1 addition & 1 deletion app-ios/app-ios/ThreadManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

import Foundation
import app_mvp
import app_ios_lib

// Executes in current thread
class BlockingThreadManager : ThreadManager {
Expand Down
2 changes: 1 addition & 1 deletion app-ios/app-ios/UI/AddNoteViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

import UIKit
import app_mvp
import app_ios_lib

class AddNoteViewController: UIViewController, AddNoteView {

Expand Down
2 changes: 1 addition & 1 deletion app-ios/app-ios/UI/ListNotesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

import UIKit
import app_mvp
import app_ios_lib

// TODO: add loading indicator
class ListNotesViewController: UITableViewController, ListNotesView {
Expand Down
2 changes: 1 addition & 1 deletion app-ios/app-ios/UI/ServerUrlViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

import UIKit
import app_mvp
import app_ios_lib

class RestServerUrlModel : ServerUrlModel {
override func update(host: String, port: UInt32) {
Expand Down
17 changes: 1 addition & 16 deletions app-mvp/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
plugins {
id 'idea'
id 'kotlin-multiplatform'
id('org.jetbrains.kotlin.native.cocoapods')
}

kotlin {
Expand Down Expand Up @@ -51,18 +50,4 @@ kotlin {
}
}

version = "$rootProject.module_version"

kotlin {
cocoapods {
summary = "App MVP of NotesClientApp"
homepage = "https://github.com/4ntoine/NotesClientApp"
}

targets.iosX64.binaries
.findAll { it instanceof org.jetbrains.kotlin.gradle.plugin.mpp.Framework }
.every {
it.export "name.antonsmirnov.notes:app-api-iosx64:$rootProject.server_module_version"
it.transitiveExport = true
}
}
version = "$rootProject.module_version"
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ext {
module_version = '0.8.1'
module_version = '0.9.0'
server_module_version = '1.3'
mockito_kotlin_version = '2.1.0'
androidx_version = '1.0.2'
Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ rootProject.name = 'NotesClientApp'
include 'app-mvp'
include 'app-infra-rest-retrofit'
include 'app-infra-rest-ktor'
include 'app-ios-lib'
include 'app-android'
include 'app-javafx'

Expand Down

0 comments on commit cebb22a

Please sign in to comment.