Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Kotlin 1.5.10, bump other dependencies, clear compiler warnings #198

Merged
merged 1 commit into from
May 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ android {
}
}
compileOptions {
coreLibraryDesugaringEnabled = true
isCoreLibraryDesugaringEnabled = true
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
Expand All @@ -40,6 +40,7 @@ android {

kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
}
}

Expand All @@ -64,6 +65,5 @@ dependencies {
implementation(Deps.AndroidX.lifecycle_viewmodel)
implementation(Deps.AndroidX.lifecycle_viewmodel_extensions)
implementation(Deps.AndroidX.lifecycle_livedata)
implementation(Deps.AndroidX.lifecycle_extension)
testImplementation(Deps.junit)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class MainViewHolder(binding: ItemBreedBinding, breedClickListener: (Int) -> Uni
private val favoriteButton = binding.favoriteButton

init {
favoriteButton.setOnClickListener { breedClickListener(adapterPosition) }
favoriteButton.setOnClickListener { breedClickListener(bindingAdapterPosition) }
}

fun bindTo(breed: Breed) {
Expand Down
33 changes: 16 additions & 17 deletions buildSrc/src/main/java/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,32 @@ object Versions {
val target_sdk = 30
val compile_sdk = 30

val kotlin = "1.4.32"
val android_gradle_plugin = "4.0.2"
val kotlin = "1.5.10"
val android_gradle_plugin = "4.1.1"

val buildToolsVersion = "30.0.3"
val coroutines = "1.4.3-native-mt"
val kermit = "0.1.8"
val koin = "3.0.1"
val ktlint_gradle_plugin = "9.4.1"
val ktor = "1.5.3"
val coroutines = "1.5.0-native-mt"
val kermit = "0.1.9"
val koin = "3.0.2"
val ktlint_gradle_plugin = "10.0.0"
val ktor = "1.6.0"
val junit = "4.13.2"
val material = "1.3.0"
val desugarJdkLibs = "1.1.5"
val multiplatformSettings = "0.7.5"
val multiplatformSettings = "0.7.7"
val robolectric = "4.5.1"
val sqlDelight = "1.5.0"
val stately = "1.1.6"
val serialization = "1.1.0"
val kotlinxDateTime = "0.1.1"
val turbine = "0.4.1"
val stately = "1.1.7"
val serialization = "1.2.1"
val kotlinxDateTime = "0.2.1"
val turbine = "0.5.1"

object AndroidX {
val appcompat = "1.2.0"
val appcompat = "1.3.0"
val constraintlayout = "2.0.4"
val core = "1.3.2"
val lifecycle = "2.2.0"
val recyclerview = "1.1.0"
val core = "1.5.0"
val lifecycle = "2.3.1"
val recyclerview = "1.2.0"
val swipeRefresh = "1.1.0"
val test = "1.3.0"
val test_ext = "1.1.2"
Expand Down Expand Up @@ -62,7 +62,6 @@ object Deps {
val lifecycle_viewmodel = "androidx.lifecycle:lifecycle-viewmodel:${Versions.AndroidX.lifecycle}"
val lifecycle_viewmodel_extensions = "androidx.lifecycle:lifecycle-viewmodel-ktx:${Versions.AndroidX.lifecycle}"
val lifecycle_livedata = "androidx.lifecycle:lifecycle-livedata:${Versions.AndroidX.lifecycle}"
val lifecycle_extension = "androidx.lifecycle:lifecycle-extensions:${Versions.AndroidX.lifecycle}"
}

object AndroidXTest {
Expand Down
12 changes: 7 additions & 5 deletions shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,7 @@ kotlin {
implementation(Deps.Ktor.commonCore)
implementation(Deps.Ktor.commonJson)
implementation(Deps.Ktor.commonLogging)
implementation(Deps.Coroutines.common) {
version {
strictly(Versions.coroutines)
}
}
implementation(Deps.Coroutines.common)
implementation(Deps.stately)
implementation(Deps.multiplatformSettings)
implementation(Deps.koinCore)
Expand Down Expand Up @@ -101,6 +97,12 @@ kotlin {
sourceSets["iosMain"].dependencies {
implementation(Deps.SqlDelight.driverIos)
implementation(Deps.Ktor.ios)

implementation(Deps.Coroutines.common) {
version {
strictly(Versions.coroutines)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we even need this anymore? I think ktor was the one causing issues

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apparently, yes. Without it we get tests hanging due missing run loop, which indicates it's not picking up the native-mt version

Copy link

@ndipatri ndipatri Jul 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@russhwolf @kpgalligan hello there.. Firstly, thank you both so much for all your hard work. KMM is amazing and I'm telling everyone that will listen that it's the future of mobile :-)

Ok, now the bad news :-( I have a fork of this repo that I've been using to convert an app I have in development. After I pulled down this merged PR, my iOS build started getting runtime errors.

It seems to be when I'm creating a cold flow for a KTOR network call. I tried rolling back just coroutines/kotlin version bumps but that wasn't enough. I can provide more information as I dig more, but I wanted to just let you know what I discovered thus far.. Thank you again!

2021-07-04 11:01:17.729169-0400 tRacket[39241:897272] Verbose: (Network) RESPONSE https://io.adafruit.com/api/v2/ndipatri/feeds/occupancy/data?start_time=2021-05-135T11:01-0400&x-aio-key=aio_XmSy92vYjddoZhQ4f19ztFc8Qm6r failed with exception: kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen kotlin.collections.HashMap@393d508
2021-07-04 11:01:17.730368-0400 tRacket[39241:897272] Error: (OccupancyModel) Error downloading data
2021-07-04 11:01:17.743070-0400 tRacket[39241:897272] kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen kotlin.collections.HashMap@393d508
at 0 tRacket 0x000000010d7f721f kfun:kotlin.Throwable#(kotlin.String?){} + 95
at 1 tRacket 0x000000010d7ef97d kfun:kotlin.Exception#(kotlin.String?){} + 93
at 2 tRacket 0x000000010d7efbed kfun:kotlin.RuntimeException#(kotlin.String?){} + 93
at 3 tRacket 0x000000010d8278fd kfun:kotlin.native.concurrent.InvalidMutabilityException#(kotlin.String){} + 93
at 4 tRacket 0x000000010d8290ff ThrowInvalidMutabilityException + 431
at 5 tRacket 0x000000010d994590 MutationCheck + 128
at 6 tRacket 0x000000010d80a102 kfun:kotlin.collections.HashMap.#internal + 82

}
}
}

cocoapods {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@ package co.touchlab.kampkit

import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExecutorCoroutineDispatcher
import kotlinx.coroutines.newSingleThreadContext
import kotlinx.coroutines.asCoroutineDispatcher
import kotlinx.coroutines.test.resetMain
import kotlinx.coroutines.test.setMain
import org.junit.rules.TestWatcher
import org.junit.runner.Description
import java.util.concurrent.Executors

/**
* Use this rule to update the Main dispatcher ahead of tests. By delegating the main dispatcher to a new thread.
* we can block the current thread and still dispatch main coroutines
*/
class CoroutineTestRule(
private val testDispatcher: ExecutorCoroutineDispatcher = newSingleThreadContext("UI thread")
private val testDispatcher: ExecutorCoroutineDispatcher = Executors.newSingleThreadExecutor()
.asCoroutineDispatcher()
) : TestWatcher() {
override fun starting(description: Description?) {
super.starting(description)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertTrue
import kotlin.time.hours
import kotlin.time.seconds
import kotlin.time.Duration

class BreedModelTest : BaseTest() {

Expand Down Expand Up @@ -129,7 +128,7 @@ class BreedModelTest : BaseTest() {
val successResult = ktorApi.successResult()
ktorApi.prepareResult(successResult)
flowOf(model.refreshBreedsIfStale(), model.getBreedsFromCache()).flattenMerge()
.test(timeout = 30.seconds) {
.test(timeout = Duration.seconds(30)) {
assertEquals(DataState.Loading, expectItem())
val oldBreeds = expectItem()
assertTrue(oldBreeds is DataState.Success)
Expand All @@ -140,12 +139,12 @@ class BreedModelTest : BaseTest() {
}

// Advance time by more than an hour to make cached data stale
clock.currentInstant += 2.hours
clock.currentInstant += Duration.hours(2)
val resultWithExtraBreed = successResult.copy(message = successResult.message + ("extra" to emptyList()))

ktorApi.prepareResult(resultWithExtraBreed)
flowOf(model.refreshBreedsIfStale(), model.getBreedsFromCache()).flattenMerge()
.test(timeout = 30.seconds) {
.test(timeout = Duration.seconds(30)) {
assertEquals(DataState.Loading, expectItem())
val updated = expectItem()
assertTrue(updated is DataState.Success)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package co.touchlab.kampkit

import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
Expand All @@ -14,6 +15,7 @@ class ConcurrencyTest : BaseTest() {
* This doesn't test any KampKit code, but is a sanity check that our tests can handle main thread
* coroutines without hanging
*/
@OptIn(DelicateCoroutinesApi::class)
@Test
fun testMain() {
runTest {
Expand Down
2 changes: 2 additions & 0 deletions shared/src/iosTest/kotlin/co/touchlab/kampkit/BaseTest.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package co.touchlab.kampkit

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
Expand All @@ -9,6 +10,7 @@ import platform.CoreFoundation.CFRunLoopRun
import platform.CoreFoundation.CFRunLoopStop

actual abstract class BaseTest {
@OptIn(DelicateCoroutinesApi::class)
actual fun <T> runTest(block: suspend CoroutineScope.() -> T) {
var error: Throwable? = null
GlobalScope.launch(Dispatchers.Main) {
Expand Down