Skip to content

Commit 253e384

Browse files
Updated to Kotlin 1.4.10, Coroutines 1.3.9, Serialization 1.0.0 (#88)
* Updated to Kotlin 1.4.10, Coroutines 1.3.9, Serialization 1.0.0-RC * Only install carthage when not installed already * Fixing build warnings, and removed cocoapod plugin * Reverting androidTest change * Updating serialization to 1.0.0-RC2 * Making an attempt to test nullability * Updating serialization to 1.0.0 * update readme, closes #89 * make old @ImplicitReflectionSerializer functions inline fun <reified T> * make old @ImplicitReflectionSerializer functions inline fun <reified T> * get android instrumented tests running in common module * Update package.json * Update package.json * Update package.json * Update package.json * Update package.json Co-authored-by: Nicholas Bransby-Williams <[email protected]>
1 parent 2feef98 commit 253e384

File tree

32 files changed

+230
-320
lines changed

32 files changed

+230
-320
lines changed

.github/workflows/pull_request.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
- name: Grant execute permission for gradlew
2222
run: chmod +x gradlew
2323
- name: Install Carthage
24-
run: brew install carthage
24+
run: brew list carthage || brew install carthage
2525
- name: Assemble
2626
run: ./gradlew assemble
2727
- name: Run JS Tests

README.md

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ GlobalScope.launch {
4545

4646
<h3><a href="https://kotlinlang.org/docs/reference/coroutines/flow.html">Flows</a></h3>
4747

48-
Asynchronous streams of values are represented by Flows in the SDK instead of repeatedly invoked callbacks or listeners, for example:
48+
Asynchronous streams of values are represented by Flows in the SDK instead of repeatedly invoked callbacks or listeners, for example:
4949

5050
```kotlin
5151
val snapshots: Flow<DocumentSnapshot>
@@ -64,7 +64,7 @@ The Firebase Kotlin SDK uses Kotlin serialization to read and write custom class
6464
```groovy
6565
plugins {
6666
kotlin("multiplatform") // or kotlin("jvm") or any other kotlin plugin
67-
kotlin("plugin.serialization") version "1.3.72"
67+
kotlin("plugin.serialization") version "1.4.10"
6868
}
6969
```
7070

@@ -75,15 +75,15 @@ Then mark you custom classes `@Serializable`:
7575
data class City(val name: String)
7676
```
7777

78-
Instances of these classes can now be passed [along with their serializer](https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/runtime_usage.md#obtaining-serializers) to the SDK:
78+
Instances of these classes can now be passed [along with their serializer](https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/serializers.md#introduction-to-serializers) to the SDK:
7979

8080
```kotlin
8181
db.collection("cities").document("LA").set(City.serializer(), city, encodeDefaults = true)
8282
```
8383

8484
The `encodeDefaults` parameter is optional and defaults to `true`, set this to false to omit writing optional properties if they are equal to theirs default values.
8585

86-
You can also omit the serializer for classes that does not have generic type arguments, these functions are marked [`@ImplicitReflectionSerializer`](https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/runtime_usage.md#implicit-reflection-serializers) and their usage is discouraged in general because it is implicit and uses reflection (and therefore not working on Kotlin/Native), but may be useful shorthand in some cases.
86+
You can also omit the serializer but this is discouraged due to a [current limitation on Kotlin/JS and Kotlin/Native](https://github.com/Kotlin/kotlinx.serialization/issues/1116#issuecomment-704342452)
8787

8888
<h4><a href="https://firebase.google.com/docs/firestore/manage-data/add-data#server_timestamp">Server Timestamp</a></h3>
8989

@@ -94,14 +94,40 @@ You can also omit the serializer for classes that does not have generic type arg
9494
data class Post(val timestamp: Double = ServerValue.TIMESTAMP)
9595
```
9696

97+
<h3><a href="https://kotlinlang.org/docs/reference/functions.html#default-arguments">Default arguments</a></h3>
98+
99+
To reduce boilerplate, default arguments are used in the places where the Firebase Android SDK employs the builder pattern:
100+
```kotlin
101+
UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
102+
.setDisplayName("Jane Q. User")
103+
.setPhotoUri(Uri.parse("https://example.com/jane-q-user/profile.jpg"))
104+
.build();
105+
106+
user.updateProfile(profileUpdates)
107+
.addOnCompleteListener(new OnCompleteListener<Void>() {
108+
@Override
109+
public void onComplete(@NonNull Task<Void> task) {
110+
if (task.isSuccessful()) {
111+
Log.d(TAG, "User profile updated.");
112+
}
113+
}
114+
});
115+
116+
//...becomes...
117+
118+
user.updateProfile(displayName = "state", photoURL = "CA")
119+
```
120+
97121
<h3><a href="https://kotlinlang.org/docs/reference/functions.html#named-arguments">Named arguments</a></h3>
98122

99123
To improve readability functions such as the Cloud Firestore query operators use named arguments:
100124

101125
```kotlin
102126
citiesRef.whereEqualTo("state", "CA")
103127
citiesRef.whereArrayContains("regions", "west_coast")
128+
104129
//...becomes...
130+
105131
citiesRef.where("state", equalTo = "CA")
106132
citiesRef.where("regions", arrayContains = "west_coast")
107133
```

build.gradle.kts

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import org.gradle.api.tasks.testing.logging.TestExceptionFormat
44
import org.gradle.api.tasks.testing.logging.TestLogEvent
55

66
plugins {
7-
kotlin("multiplatform") version "1.3.71" apply false
7+
kotlin("multiplatform") version "1.4.10" apply false
88
id("de.undercouch.download").version("3.4.3")
99
id("base")
1010
}
@@ -175,14 +175,6 @@ subprojects {
175175
}
176176
}
177177

178-
// tasks.withType<KotlinCompile<*>> {
179-
// kotlinOptions.freeCompilerArgs += listOf(
180-
// "-Xuse-experimental=kotlin.Experimental",
181-
// "-Xuse-experimental=kotlinx.coroutines.ExperimentalCoroutinesApi",
182-
// "-Xuse-experimental=kotlinx.serialization.ImplicitReflectionSerializer"
183-
// )
184-
// }
185-
186178
afterEvaluate {
187179
// create the projects node_modules if they don't exist
188180
if(!File("$buildDir/node_module").exists()) {
@@ -195,27 +187,19 @@ subprojects {
195187

196188
dependencies {
197189
"commonMainImplementation"(kotlin("stdlib-common"))
198-
"commonMainImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core-common:1.3.8")
190+
"commonMainImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9")
199191
"jsMainImplementation"(kotlin("stdlib-js"))
200-
"jsMainImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core-js:1.3.8")
201-
"androidMainImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.8")
202-
"androidMainImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.3.6")
203-
"iosMainImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core-common:1.3.8")
204-
"iosMainImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core-native:1.3.8")
192+
"androidMainImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.3.9")
205193
"commonTestImplementation"(kotlin("test-common"))
206194
"commonTestImplementation"(kotlin("test-annotations-common"))
207-
"commonTestImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core-common:1.3.8")
208-
"commonTestImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.3.8")
195+
"commonTestImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9")
209196
"jsTestImplementation"(kotlin("test-js"))
210197
"androidAndroidTestImplementation"(kotlin("test-junit"))
211198
"androidAndroidTestImplementation"("junit:junit:4.13")
212199
"androidAndroidTestImplementation"("androidx.test:core:1.2.0")
213-
"androidAndroidTestImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.8")
214200
"androidAndroidTestImplementation"("androidx.test.ext:junit:1.1.1")
215201
"androidAndroidTestImplementation"("androidx.test:runner:1.2.0")
216202
}
217-
218-
219203
}
220204

221205
apply(plugin="maven-publish")

firebase-app/build.gradle.kts

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
*/
44
version = project.property("firebase-app.version") as String
55

6-
76
plugins {
87
id("com.android.library")
98
kotlin("multiplatform")
10-
kotlin("native.cocoapods")
119
}
1210

1311
repositories {
@@ -33,7 +31,7 @@ android {
3331
}
3432
}
3533
packagingOptions {
36-
pickFirst("META-INF/kotlinx-serialization-runtime.kotlin_module")
34+
pickFirst("META-INF/kotlinx-serialization-core.kotlin_module")
3735
pickFirst("META-INF/AL2.0")
3836
pickFirst("META-INF/LGPL2.1")
3937
}
@@ -44,21 +42,10 @@ android {
4442

4543
kotlin {
4644
js {
47-
val main by compilations.getting {
48-
kotlinOptions {
49-
moduleKind = "commonjs"
50-
}
51-
}
45+
useCommonJs()
5246
nodejs()
5347
browser()
5448
}
55-
// js("reactnative") {
56-
// val main by compilations.getting {
57-
// kotlinOptions {
58-
// moduleKind = "commonjs"
59-
// }
60-
// }
61-
// }
6249
android {
6350
publishLibraryVariants("release", "debug")
6451
}
@@ -79,12 +66,6 @@ kotlin {
7966
implementation(project(":firebase-common"))
8067
}
8168
}
82-
val commonTest by getting {
83-
dependencies {
84-
implementation(kotlin("test-common"))
85-
implementation(kotlin("test-annotations-common"))
86-
}
87-
}
8869
val androidMain by getting {
8970
dependencies {
9071
api("com.google.firebase:firebase-common:19.3.1")
@@ -101,12 +82,6 @@ kotlin {
10182
}
10283
}
10384
}
104-
105-
cocoapods {
106-
summary = ""
107-
homepage = ""
108-
//pod("FirebaseCore", "~> 6.3.1")
109-
}
11085
}
11186
}
11287

firebase-auth/build.gradle.kts

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
/*
2+
* Copyright (c) 2020 GitLive Ltd. Use of this source code is governed by the Apache 2.0 license.
3+
*/
14
version = project.property("firebase-auth.version") as String
25

36
plugins {
47
id("com.android.library")
58
kotlin("multiplatform")
6-
kotlin("native.cocoapods")
79
//id("com.quittle.android-emulator") version "0.2.0"
810
}
911

@@ -37,7 +39,7 @@ android {
3739
}
3840
}
3941
packagingOptions {
40-
pickFirst("META-INF/kotlinx-serialization-runtime.kotlin_module")
42+
pickFirst("META-INF/kotlinx-serialization-core.kotlin_module")
4143
pickFirst("META-INF/AL2.0")
4244
pickFirst("META-INF/LGPL2.1")
4345
}
@@ -61,11 +63,7 @@ android {
6163

6264
kotlin {
6365
js {
64-
val main by compilations.getting {
65-
kotlinOptions {
66-
moduleKind = "commonjs"
67-
}
68-
}
66+
useCommonJs()
6967
nodejs()
7068
browser()
7169
}
@@ -87,8 +85,7 @@ kotlin {
8785
tasks.withType<org.jetbrains.kotlin.gradle.dsl.KotlinCompile<*>> {
8886
kotlinOptions.freeCompilerArgs += listOf(
8987
"-Xuse-experimental=kotlin.Experimental",
90-
"-Xuse-experimental=kotlinx.coroutines.ExperimentalCoroutinesApi",
91-
"-Xuse-experimental=kotlinx.serialization.ImplicitReflectionSerializer"
88+
"-Xuse-experimental=kotlinx.coroutines.ExperimentalCoroutinesApi"
9289
)
9390
}
9491

@@ -118,12 +115,6 @@ kotlin {
118115
}
119116
}
120117
}
121-
122-
cocoapods {
123-
summary = ""
124-
homepage = ""
125-
}
126-
127118
}
128119
}
129120

firebase-common/build.gradle.kts

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,29 @@ version = project.property("firebase-common.version") as String
77
plugins {
88
id("com.android.library")
99
kotlin("multiplatform")
10-
kotlin("native.cocoapods")
11-
kotlin("plugin.serialization") version "1.3.71"
10+
kotlin("plugin.serialization") version "1.4.10"
1211
}
1312

1413
android {
1514
compileSdkVersion(property("targetSdkVersion") as Int)
1615
defaultConfig {
1716
minSdkVersion(property("minSdkVersion") as Int)
1817
targetSdkVersion(property("targetSdkVersion") as Int)
18+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
1919
}
2020
sourceSets {
2121
getByName("main") {
2222
manifest.srcFile("src/androidMain/AndroidManifest.xml")
2323
}
24+
getByName("androidTest").java.srcDir(file("src/androidAndroidTest/kotlin"))
2425
}
2526
testOptions {
2627
unitTests.apply {
2728
isIncludeAndroidResources = true
2829
}
2930
}
3031
packagingOptions {
31-
pickFirst("META-INF/kotlinx-serialization-runtime.kotlin_module")
32+
pickFirst("META-INF/kotlinx-serialization-core.kotlin_module")
3233
pickFirst("META-INF/AL2.0")
3334
pickFirst("META-INF/LGPL2.1")
3435
}
@@ -39,12 +40,9 @@ android {
3940

4041
kotlin {
4142
js {
42-
val main by compilations.getting {
43-
kotlinOptions {
44-
moduleKind = "commonjs"
45-
}
46-
}
43+
useCommonJs()
4744
nodejs()
45+
browser()
4846
}
4947
android {
5048
publishLibraryVariants("release", "debug")
@@ -57,44 +55,36 @@ kotlin {
5755
kotlinOptions.freeCompilerArgs += listOf(
5856
"-Xuse-experimental=kotlin.Experimental",
5957
"-Xuse-experimental=kotlinx.coroutines.ExperimentalCoroutinesApi",
60-
"-Xuse-experimental=kotlinx.serialization.ImplicitReflectionSerializer"
58+
"-Xuse-experimental=kotlinx.serialization.ExperimentalSerializationApi",
59+
"-Xuse-experimental=kotlinx.serialization.InternalSerializationApi"
6160
)
6261
}
6362

6463
sourceSets {
6564
val commonMain by getting {
6665
dependencies {
67-
api("org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:0.20.0")
66+
api("org.jetbrains.kotlinx:kotlinx-serialization-core:1.0.0")
6867
}
6968
}
7069
val androidMain by getting {
7170
dependencies {
7271
api("com.google.firebase:firebase-common:19.3.0")
73-
api("org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.20.0")
7472
}
7573
}
7674
val jsMain by getting {
7775
dependencies {
7876
api(npm("firebase", "7.14.0"))
79-
api("org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:0.20.0")
8077
}
8178
}
8279
val iosMain by getting {
8380
dependencies {
84-
api("org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:0.20.0")
8581
}
8682
}
8783
configure(listOf(iosArm64, iosX64)) {
8884
compilations.getByName("main") {
8985
source(sourceSets.get("iosMain"))
9086
}
9187
}
92-
93-
cocoapods {
94-
summary = "Firebase Core for iOS (plus community support for macOS and tvOS)"
95-
homepage = "https://github.com/GitLiveApp/firebase-kotlin-multiplatform-sdk"
96-
//pod("FirebaseCore", "~> 6.3.1")
97-
}
9888
}
9989
}
10090

firebase-common/src/androidAndroidTest/kotlin/dev/gitlive/firebase/EncodersTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ package dev.gitlive.firebase
66

77
actual fun nativeMapOf(vararg pairs: Pair<String, Any>): Any = mapOf(*pairs)
88
actual fun nativeListOf(vararg elements: Any): Any = listOf(*elements)
9-
actual fun nativeAssertEquals(expected: Any?, actual: Any?) = kotlin.test.assertEquals(expected, actual)
9+
actual fun nativeAssertEquals(expected: Any?, actual: Any?) = kotlin.test.assertEquals(expected, actual)

firebase-common/src/androidMain/kotlin/dev/gitlive/firebase/_decoders.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
package dev.gitlive.firebase
66

7-
import kotlinx.serialization.CompositeDecoder
7+
import kotlinx.serialization.encoding.CompositeDecoder
88
import kotlinx.serialization.KSerializer
9-
import kotlinx.serialization.SerialDescriptor
10-
import kotlinx.serialization.StructureKind
9+
import kotlinx.serialization.descriptors.SerialDescriptor
10+
import kotlinx.serialization.descriptors.StructureKind
1111

12-
actual fun FirebaseDecoder.structureDecoder(descriptor: SerialDescriptor, vararg typeParams: KSerializer<*>): CompositeDecoder = when(descriptor.kind as StructureKind) {
12+
actual fun FirebaseDecoder.structureDecoder(descriptor: SerialDescriptor): CompositeDecoder = when(descriptor.kind as StructureKind) {
1313
StructureKind.CLASS, StructureKind.OBJECT -> (value as Map<*, *>).let { map ->
1414
FirebaseClassDecoder(map.size, { map.containsKey(it) }) { desc, index -> map[desc.getElementName(index)] }
1515
}

0 commit comments

Comments
 (0)