Skip to content

Commit 097f548

Browse files
authored
Merge pull request #257 from suntrix/installations
Added firebase-installations
2 parents 36ce852 + 18ba80e commit 097f548

File tree

18 files changed

+368
-20
lines changed

18 files changed

+368
-20
lines changed

build.gradle.kts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ tasks {
3131
"firebase-app:updateVersion", "firebase-app:updateDependencyVersion",
3232
"firebase-auth:updateVersion", "firebase-auth:updateDependencyVersion",
3333
"firebase-common:updateVersion", "firebase-common:updateDependencyVersion",
34+
"firebase-config:updateVersion", "firebase-config:updateDependencyVersion",
3435
"firebase-database:updateVersion", "firebase-database:updateDependencyVersion",
3536
"firebase-firestore:updateVersion", "firebase-firestore:updateDependencyVersion",
3637
"firebase-functions:updateVersion", "firebase-functions:updateDependencyVersion",
37-
"firebase-config:updateVersion", "firebase-config:updateDependencyVersion"
38+
"firebase-installations:updateVersion", "firebase-installations:updateDependencyVersion"
3839
)
3940
}
4041
}
@@ -154,8 +155,8 @@ subprojects {
154155
}
155156
}
156157

157-
if (projectDir.resolve("src/nativeInterop/cinterop/Cartfile").exists()) { // skipping firebase-common module
158-
listOf("bootstrap", "update").forEach {
158+
val carthageTasks = if (projectDir.resolve("src/nativeInterop/cinterop/Cartfile").exists()) { // skipping firebase-common module
159+
listOf("bootstrap", "update").map {
159160
task<Exec>("carthage${it.capitalize()}") {
160161
group = "carthage"
161162
executable = "carthage"
@@ -166,11 +167,13 @@ subprojects {
166167
)
167168
}
168169
}
169-
}
170+
} else emptyList()
170171

171172
if (Os.isFamily(Os.FAMILY_MAC)) {
172173
withType(org.jetbrains.kotlin.gradle.tasks.CInteropProcess::class) {
173-
dependsOn("carthageBootstrap")
174+
if (carthageTasks.isNotEmpty()) {
175+
dependsOn("carthageBootstrap")
176+
}
174177
}
175178
}
176179

firebase-app/src/iosMain/c_interop/Cartfile.resolved

Lines changed: 0 additions & 1 deletion
This file was deleted.

firebase-auth/src/iosMain/c_interop/Cartfile.resolved

Lines changed: 0 additions & 1 deletion
This file was deleted.

firebase-common/src/jsMain/kotlin/dev/gitlive/firebase/externals.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,4 +498,14 @@ external object firebase {
498498
fun getSource(): String
499499
}
500500
}
501+
502+
fun installations(app: App? = definedExternally): installations.Installations
503+
504+
object installations {
505+
interface Installations {
506+
fun delete(): Promise<Unit>
507+
fun getId(): Promise<String>
508+
fun getToken(forceRefresh: Boolean): Promise<String>
509+
}
510+
}
501511
}

firebase-common/src/jsMain/kotlin/dev/gitlive/firebase/externals2.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ package dev.gitlive.firebase
66

77
import kotlin.js.Promise
88

9-
@JsModule("firebase/compat/functions")
10-
@JsName("default")
11-
external object functions
12-
139
@JsModule("firebase/compat/auth")
1410
@JsName("default")
1511
external object auth
@@ -22,6 +18,12 @@ external object database
2218
@JsName("default")
2319
external object firestore
2420

21+
@JsModule("firebase/compat/functions")
22+
@JsName("default")
23+
external object functions
24+
25+
external object installations
26+
2527
@JsModule("firebase/compat/remote-config")
2628
@JsName("default")
2729
external object remoteConfig

firebase-database/src/iosMain/c_interop/Cartfile.resolved

Lines changed: 0 additions & 1 deletion
This file was deleted.

firebase-firestore/src/iosMain/c_interop/Cartfile.resolved

Lines changed: 0 additions & 1 deletion
This file was deleted.

firebase-functions/src/iosMain/c_interop/Cartfile.resolved

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
/*
2+
* Copyright (c) 2020 GitLive Ltd. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
6+
import org.jetbrains.kotlin.konan.target.KonanTarget
7+
8+
version = project.property("firebase-installations.version") as String
9+
10+
plugins {
11+
id("com.android.library")
12+
kotlin("multiplatform")
13+
}
14+
15+
android {
16+
compileSdk = property("targetSdkVersion") as Int
17+
defaultConfig {
18+
minSdk = property("minSdkVersion") as Int
19+
targetSdk = property("targetSdkVersion") as Int
20+
}
21+
sourceSets {
22+
getByName("main") {
23+
manifest.srcFile("src/androidMain/AndroidManifest.xml")
24+
}
25+
}
26+
testOptions {
27+
unitTests.apply {
28+
isIncludeAndroidResources = true
29+
}
30+
}
31+
packagingOptions {
32+
resources.pickFirsts.add("META-INF/kotlinx-serialization-core.kotlin_module")
33+
resources.pickFirsts.add("META-INF/AL2.0")
34+
resources.pickFirsts.add("META-INF/LGPL2.1")
35+
}
36+
lint {
37+
isAbortOnError = false
38+
}
39+
}
40+
41+
val KonanTarget.archVariant: String
42+
get() = if (this is KonanTarget.IOS_X64 || this is KonanTarget.IOS_SIMULATOR_ARM64) {
43+
"ios-arm64_i386_x86_64-simulator"
44+
} else {
45+
"ios-arm64_armv7"
46+
}
47+
48+
kotlin {
49+
50+
android {
51+
publishAllLibraryVariants()
52+
}
53+
54+
val supportIosTarget = project.property("skipIosTarget") != "true"
55+
if (supportIosTarget) {
56+
fun nativeTargetConfig(): KotlinNativeTarget.() -> Unit = {
57+
val nativeFrameworkPaths = listOf(
58+
rootProject.project("firebase-app").projectDir.resolve("src/nativeInterop/cinterop/Carthage/Build/iOS")
59+
).plus(
60+
listOf(
61+
"FirebaseAnalytics",
62+
"FirebaseCore",
63+
"FirebaseCoreDiagnostics",
64+
"FirebaseInstallations",
65+
"GoogleAppMeasurement",
66+
"GoogleAppMeasurementIdentitySupport",
67+
"GoogleDataTransport",
68+
"GoogleUtilities",
69+
"nanopb",
70+
"PromisesObjC"
71+
).map {
72+
rootProject.project("firebase-app").projectDir.resolve("src/nativeInterop/cinterop/Carthage/Build/$it.xcframework/${konanTarget.archVariant}")
73+
}
74+
)
75+
76+
binaries {
77+
getTest("DEBUG").apply {
78+
linkerOpts(nativeFrameworkPaths.map { "-F$it" })
79+
linkerOpts("-ObjC")
80+
}
81+
}
82+
83+
compilations.getByName("main") {
84+
cinterops.create("FirebaseInstallations") {
85+
compilerOpts(nativeFrameworkPaths.map { "-F$it" })
86+
extraOpts = listOf("-compiler-option", "-DNS_FORMAT_ARGUMENT(A)=", "-verbose")
87+
}
88+
}
89+
}
90+
91+
ios(configure = nativeTargetConfig())
92+
iosSimulatorArm64(configure = nativeTargetConfig())
93+
}
94+
95+
js {
96+
useCommonJs()
97+
nodejs {
98+
testTask {
99+
useMocha {
100+
timeout = "5s"
101+
}
102+
}
103+
}
104+
browser {
105+
testTask {
106+
useMocha {
107+
timeout = "5s"
108+
}
109+
}
110+
}
111+
}
112+
113+
sourceSets {
114+
all {
115+
languageSettings.apply {
116+
apiVersion = "1.5"
117+
languageVersion = "1.5"
118+
progressiveMode = true
119+
// optIn("kotlinx.coroutines.ExperimentalCoroutinesApi")
120+
// optIn("kotlinx.serialization.InternalSerializationApi")
121+
}
122+
}
123+
124+
val commonMain by getting {
125+
dependencies {
126+
api(project(":firebase-app"))
127+
implementation(project(":firebase-common"))
128+
}
129+
}
130+
131+
val androidMain by getting {
132+
dependencies {
133+
api("com.google.firebase:firebase-installations")
134+
}
135+
}
136+
137+
if (supportIosTarget) {
138+
val iosMain by getting
139+
val iosSimulatorArm64Main by getting
140+
iosSimulatorArm64Main.dependsOn(iosMain)
141+
142+
val iosTest by sourceSets.getting
143+
val iosSimulatorArm64Test by sourceSets.getting
144+
iosSimulatorArm64Test.dependsOn(iosTest)
145+
}
146+
147+
val jsMain by getting
148+
}
149+
}
150+
151+
if (project.property("firebase-installations.skipIosTests") == "true") {
152+
tasks.forEach {
153+
if (it.name.contains("ios", true) && it.name.contains("test", true)) { it.enabled = false }
154+
}
155+
}
156+
157+
signing {
158+
val signingKey: String? by project
159+
val signingPassword: String? by project
160+
useInMemoryPgpKeys(signingKey, signingPassword)
161+
sign(publishing.publications)
162+
}

firebase-installations/package.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "@gitlive/firebase-installations",
3+
"version": "1.0.0",
4+
"description": "Wrapper around firebase for usage in Kotlin Multiplatform projects",
5+
"main": "firebase-installations.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/GitLiveApp/firebase-kotlin-sdk.git"
12+
},
13+
"keywords": [
14+
"kotlin",
15+
"multiplatform",
16+
"kotlin-js",
17+
"firebase"
18+
],
19+
"author": "dev.gitlive",
20+
"license": "Apache-2.0",
21+
"bugs": {
22+
"url": "https://github.com/GitLiveApp/firebase-kotlin-sdk/issues"
23+
},
24+
"homepage": "https://github.com/GitLiveApp/firebase-kotlin-sdk",
25+
"dependencies": {
26+
"@gitlive/firebase-app": "1.4.3",
27+
"firebase": "9.4.1",
28+
"kotlin": "1.5.31",
29+
"kotlinx-coroutines-core": "1.5.2"
30+
}
31+
}

0 commit comments

Comments
 (0)